-
Notifications
You must be signed in to change notification settings - Fork 0
/
mf_auto_lncrnadisease.py
214 lines (192 loc) · 8.19 KB
/
mf_auto_lncrnadisease.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#hybride model of SDAE and MF. One hidden layer is used in the SDAE.
import h5py
import numpy as np
import random
import auto_fun as auto
import testing_lncrnadisease as testing
timecounts = [0]
def deeplearing_start(lncdis_tr,lncdis_val,i):
lncrnadisease_tr=lncdis_tr
lncrnadisease_val=lncdis_val
with h5py.File('need_lncrna_disease_tr.h5', 'w') as hf:
hf.create_dataset("rating", data=lncrnadisease_tr)
main1(denoise = True)
main2(denoise = True)
score_matrix=testing.protect_lncrnadiseas(lncrnadisease_tr,lncrnadisease_val,i)
print("count time is:")
print(timecounts[0])
return score_matrix
def main1(denoise = True):
INPUT_LAYER = 6066 #lncrna feature sizes
HIDDEN_UNIT1 = 130
HIDDEN_UNIT2 = 100
LEARNING_RATE = 0.001/100
EPOCH_NUM = 100
#randomSeed = np.random.RandomState(42)
mu, sigma = 0, 0.1
l=100
#alpha=100
#l2_u=200
#l2_v=200
alpha=100
l2_u=200 #lambda
l2_v=200
batch=60
# batch = 60
ratio_l=500
ratio_u=1.0
#allMatrix, xtrain, xval, xtest,lenList,accList = getData()
diction = [('ind_empleado', 5), ('pais_residencia', 6066), ('sexo', 3), ('ind_nuevo', 2), ('indrel', 2), ('indrel_1mes', 4), ('tiprel_1mes', 4), ('indresi', 2), ('indext', 2), ('conyuemp', 3), ('canal_entrada', 158), ('indfall', 2), ('cod_prov', 53), ('ind_actividad_cliente', 2), ('segmento', 4), ('antiguedad_binned', 10), ('age_binned', 6066), ('renta_binned', 10)]
lenList = []
for tuppl in diction:
val = tuppl[1]
lenList.append(val)
accList = []
for i in range(len(lenList)):
if i ==0:
accList.append(lenList[i])
else:
accList.append(accList[i-1]+lenList[i])
#read lncrna infor
with h5py.File('need_lncrna_gene_micrna_go.h5', 'r') as hf:
xtrain = hf['infor'][:]
#read rating matrix
with h5py.File('need_lncrna_disease_tr.h5', 'r') as hf:
rating_mat = hf['rating'][:]
W1,W2,b1,b2,c1,c2 = auto.initialization(INPUT_LAYER,HIDDEN_UNIT1,HIDDEN_UNIT2,mu,sigma)
#define lncrna and disease matrices
u=np.random.rand(rating_mat.shape[0],l)
v=np.random.rand(rating_mat.shape[1],l)
#define preference and confidence matrices
p=np.zeros(rating_mat.shape)
p[rating_mat>0]=1
c=np.zeros(rating_mat.shape)
c=1+alpha*rating_mat #confidence matrices
iteration=30
print('start')
for iterate in range(iteration):
#update lncrna
for i in range(rating_mat.shape[0]):
c_diag=np.diag(c[i,:])
temp_u=np.dot(np.dot(p[i,:],c_diag),v)
u[i,:]=np.dot(temp_u,np.linalg.pinv(l2_u*np.identity(l)+np.dot(np.dot(v.T,c_diag),v)))
print('u complete')
#update disease
for j in range(rating_mat.shape[1]):
#print(j)
c_diag=np.diag(c[:,j])
temp_v=np.dot(np.dot(p[:,j],c_diag),u)
v[j,:]=np.dot(temp_v,np.linalg.pinv(l2_v*np.identity(l)+np.dot(np.dot(u.T,c_diag),u)))
print('v complete')
print(np.linalg.norm(p-np.dot(u,v.T)))
timecounts[0] += 1
# W1,b1,c1 = auto.autoEncoder_mono(ratio_l,ratio_u,batch,W1,xtrain,u,b1,c1,accList,EPOCH_NUM,LEARNING_RATE,denoise = True)
#autoEncoder(ratio_l,ratio_u,batch,W1,W2,xtrain,u,b1,b2,c1,c2,accList,EPOCH_NUM,LEARNING_RATE,denoise = True):
hiddenlayer3 = True
W1, W2, b1, b2, c1, c2 = auto.autoEncoder(ratio_l, ratio_u, batch, W1, W2, xtrain, u, b1, b2, c1, c2, accList,
EPOCH_NUM,
LEARNING_RATE, denoise=True)
# getoutPut(W1,W2,b1,b2,x,accList):
hidden = auto.getoutPut(W1, W2, b1, b2, xtrain, accList)
u=hidden
print(np.linalg.norm(p-np.dot(u,v.T)))
with h5py.File('u_40_lncdis_40+100_auto.h5', 'w') as hf:
hf.create_dataset("u", data=u)
with h5py.File('v_40_lncdis_40+100_auto.h5', 'w') as hf:
hf.create_dataset("v", data=v)
with h5py.File('W1_40_lncdis_40+100.h5', 'w') as hf:
hf.create_dataset("W1", data=W1)
with h5py.File('b1_40_lncdis_40+100.h5', 'w') as hf:
hf.create_dataset("b1", data=b1)
with h5py.File('c1_40_lncdis_40+100.h5', 'w') as hf:
hf.create_dataset("c1", data=c1)
if hiddenlayer3:
with h5py.File('W2_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("W2", data=W2)
with h5py.File('b2_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("b2", data=b2)
return hidden
def main2(denoise = True):
INPUT_LAYER = 10621 # disease feature sizes
HIDDEN_UNIT1 = 130
HIDDEN_UNIT2 = 100
LEARNING_RATE = 0.001/100
EPOCH_NUM = 100
#randomSeed = np.random.RandomState(42)
mu, sigma = 0, 0.1
l=100
alpha=100
l2_u=200
l2_v=200
# batch=60
batch = 60
ratio_l=500
ratio_u=1.0
#allMatrix, xtrain, xval, xtest,lenList,accList = getData()
diction = [('ind_empleado', 5), ('pais_residencia', 10621), ('sexo', 3), ('ind_nuevo', 2), ('indrel', 2), ('indrel_1mes', 4), ('tiprel_1mes', 4), ('indresi', 2), ('indext', 2), ('conyuemp', 3), ('canal_entrada', 158), ('indfall', 2), ('cod_prov', 53), ('ind_actividad_cliente', 2), ('segmento', 4), ('antiguedad_binned', 10), ('age_binned', 10621), ('renta_binned', 10)]
lenList = []
for tuppl in diction:
val = tuppl[1]
lenList.append(val)
accList = []
for i in range(len(lenList)):
if i ==0:
accList.append(lenList[i])
else:
accList.append(accList[i-1]+lenList[i])
with h5py.File('need_disease_micrna_gene.h5', 'r') as hf:
xtrain = hf['infor'][:]
xtrain = xtrain
#read rating matrix
with h5py.File('need_lncrna_disease_tr.h5', 'r') as hf:
rating_mat = hf['rating'][:]
rating_mat = rating_mat.transpose()
W1,W2,b1,b2,c1,c2 = auto.initialization(INPUT_LAYER,HIDDEN_UNIT1,HIDDEN_UNIT2,mu,sigma)
u=np.random.rand(rating_mat.shape[0],l)
v=np.random.rand(rating_mat.shape[1],l)
#define preference and confidence matrices
p=np.zeros(rating_mat.shape)
p[rating_mat>0]=1
c=np.zeros(rating_mat.shape)
c=1+alpha*rating_mat #confidence matrices
iteration=30
print('start')
for iterate in range(iteration):
#update
for i in range(rating_mat.shape[0]):
c_diag=np.diag(c[i,:])
temp_u=np.dot(np.dot(p[i,:],c_diag),v)
u[i,:]=np.dot(temp_u,np.linalg.pinv(l2_u*np.identity(l)+np.dot(np.dot(v.T,c_diag),v)))
print('u complete')
#update
for j in range(rating_mat.shape[1]):
#print(j)
c_diag=np.diag(c[:,j])
temp_v=np.dot(np.dot(p[:,j],c_diag),u)
v[j,:]=np.dot(temp_v,np.linalg.pinv(l2_v*np.identity(l)+np.dot(np.dot(u.T,c_diag),u)))
print('v complete')
print(np.linalg.norm(p-np.dot(u,v.T)))
timecounts[0] += 1
hiddenlayer3 = True
W1, W2, b1, b2, c1, c2 = auto.autoEncoder(ratio_l, ratio_u, batch, W1, W2, xtrain, u, b1, b2, c1, c2, accList, EPOCH_NUM,
LEARNING_RATE, denoise=True)
#getoutPut(W1,W2,b1,b2,x,accList):
hidden = auto.getoutPut(W1, W2, b1, b2, xtrain, accList)
u=hidden
print(np.linalg.norm(p-np.dot(u,v.T)))
with h5py.File('v_40_disease_40+100_auto.h5', 'w') as hf:
hf.create_dataset("v", data=u)
with h5py.File('u_40_disease_40+100_auto.h5', 'w') as hf:
hf.create_dataset("u", data=v)
with h5py.File('W1_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("W1", data=W1)
with h5py.File('b1_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("b1", data=b1)
with h5py.File('c1_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("c1", data=c1)
if hiddenlayer3:
with h5py.File('W2_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("W2", data=W2)
with h5py.File('b2_40_disease_40+100.h5', 'w') as hf:
hf.create_dataset("b2", data=b2)
return hidden