/
generate_Z_est.py
66 lines (60 loc) · 2.21 KB
/
generate_Z_est.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
import numpy as np,os,sys
def sigmoid(num):
y=1/(1+np.exp(-num))
return y
def generate_Z(phenotypes,thetaname,theta,alpha):
if not os.path.exists('Z_est_fMRI'):
os.makedirs('Z_est_fMRI')
theta=np.resize(theta,theta.size)
z=np.dot(alpha.T,theta)
if phenotypes!=1:
for i in range(0,z.size):
z[i]=sigmoid(z[i])
for i in range(0,z.size):
z[i]=(z[i]-np.mean(z))/np.std(z)
return z
def getThetaAlpha(phenotypes,num_scans):
#get the number of files
thetanames=np.load('Theta_est_fMRI/ThetaFiles.npy')
z=[]
scans=range(0,num_scans)
for thetaname in thetanames:
for scan in scans:
theta=np.load('Theta_est_fMRI/'+thetaname+'.npy')
(x,y)=theta.shape
#maintaining sparsity
alpha=theta
alpha[alpha.nonzero()]=np.random.randn(len(alpha[alpha.nonzero()]))
for i in range(0,phenotypes):
temp=theta
temp[temp.nonzero()]=np.random.rand(len(temp[temp.nonzero()]))
alpha=np.dstack((alpha,temp))
alpha=np.resize(alpha,(theta.size,phenotypes))
z.extend(generate_Z(phenotypes,thetaname,theta,alpha))
z=np.reshape(z,(phenotypes,len(thetanames)*num_scans))
print z
np.save('Z_est_fmri',z)
z=[]
thetanames=np.load('Theta_est_dti/ThetaFiles.npy')
for thetaname in thetanames:
for scan in scans:
theta=np.load('Theta_est_dti/'+thetaname+'.npy')
(x,y)=theta.shape
#maintaining sparsity
alpha=theta
alpha[alpha.nonzero()]=np.random.randn(len(alpha[alpha.nonzero()]))
for i in range(0,phenotypes):
temp=theta
temp[temp.nonzero()]=np.random.rand(len(temp[temp.nonzero()]))
alpha=np.dstack((alpha,temp))
alpha=np.resize(alpha,(theta.size,phenotypes))
z.extend(generate_Z(phenotypes,thetaname,theta,alpha))
z=np.reshape(z,(phenotypes,len(thetanames)*num_scans))
print z
np.save('Z_est_dti',z)
def main():
phenotypes=int(sys.argv[1])
num_scans=int(sys.argv[2])
getThetaAlpha(phenotypes,num_scans)
if __name__ == '__main__':
main()