-
Notifications
You must be signed in to change notification settings - Fork 1
/
simpleSynth.py
230 lines (173 loc) · 6.95 KB
/
simpleSynth.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import sys
import numpy
import numpy as np
import colorsys
from socket import gethostname
import time
import argparse
import os
import colorsys
# sys.path.append(os.path.abspath("../diffEqModel/"))
parser = argparse.ArgumentParser(description='Launches voxel-wise/point-wise DPM on ADNI'
'using cortical thickness maps derived from MRI')
parser.add_argument('--agg', dest='agg', type=int, default=0,
help='agg=1 => plot figures without using Xwindows, for use on cluster where the plots cannot be displayed '
' agg=0 => plot with Xwindows (for use on personal machine)')
parser.add_argument('--runIndex', dest='runIndex', type=int,
default=1, help='index of run instance/process .. for cross-validation')
parser.add_argument('--nrProc', dest='nrProc', type=int,
default=1, help='# of processes')
parser.add_argument('--modelToRun', dest='modelToRun', type=int,
help='index of model to run')
parser.add_argument('--cluster', action="store_true",
help='need to include this flag if runnin on cluster')
parser.add_argument('--nrRows', dest='nrRows', type=int,
help='nr of subfigure rows to plot at every iteration')
parser.add_argument('--nrCols', dest='nrCols', type=int,
help='nr of subfigure columns to plot at every iteration')
parser.add_argument('--penalty', dest='penalty', type=float,
help='penalty value for non-monotonic trajectories. between 0 (no effect) and 10 (strong effect). ')
args = parser.parse_args()
if args.agg:
# print(matplotlib.__version__)
import matplotlib
matplotlib.use('Agg')
# print(asds)
import genSynthData
import GPModel
import ParHierModel
import Plotter
from auxFunc import *
import evaluationFramework
hostName = gethostname()
if hostName == 'razvan-Inspiron-5547':
freesurfPath = '/usr/local/freesurfer-5.3.0'
homeDir = '/home/razvan'
blenderPath = 'blender'
elif hostName == 'razvan-Precision-T1700':
freesurfPath = '/usr/local/freesurfer-5.3.0'
homeDir = '/home/razvan'
blenderPath = 'blender'
elif args.cluster:
freesurfPath = '/share/apps/freesurfer-5.3.0'
homeDir = '/home/rmarines'
blenderPath = '/share/apps/blender-2.75/blender'
else:
raise ValueError('Wrong hostname. If running on new machine, add '
'application paths in python code above')
plotTrajParams = {}
plotTrajParams['SubfigTrajWinSize'] = (1600,900)
plotTrajParams['nrRows'] = args.nrRows
plotTrajParams['nrCols'] = args.nrCols
plotTrajParams['diagColors'] = {CTL:'b', AD:'r'}
plotTrajParams['legendCols'] = 2
plotTrajParams['diagLabels'] = {CTL:'CTL', AD:'AD'}
plotTrajParams['freesurfPath'] = freesurfPath
# plotTrajParams['ylimitsRandPoints'] = (-3,2)
plotTrajParams['blenderPath'] = blenderPath
plotTrajParams['isSynth'] = True
if args.agg:
plotTrajParams['agg'] = True
else:
plotTrajParams['agg'] = False
hostName = gethostname()
if hostName == 'razvan-Inspiron-5547':
height = 350
else: #if hostName == 'razvan-Precision-T1700':
height = 450
def main():
nrSubjLong = 100
nrBiomk = 4
nrTimepts = 4
lowerAgeLim = 60
upperAgeLim = 80
shiftsLowerLim = -13
shiftsUpperLim = 10
etaB = 1 * np.ones(nrBiomk)
lB = 10 * np.ones(nrBiomk)
epsB = 1 * np.ones(nrBiomk)
sigmaSB = 2 * np.ones((nrSubjLong, nrBiomk))
sigmaGfunc = GPModel.genSigmaG
sigmaEpsfunc = None
sigmaSfunc = None
outFolder = 'resfiles/synth/'
expName = 'synth1'
fileName = '%s.npz' % expName
forceRegenerate = False
params = {}
nrFuncUnits = 2
nrBiomkInFuncUnits = 3
nrBiomk = nrBiomkInFuncUnits * nrFuncUnits
mapBiomkToFuncUnits = np.array(list(range(nrFuncUnits)) * nrBiomkInFuncUnits)
# should give smth like [0,1,2,3,0,1,2,3,0,1,2,3]
print('mapBiomkToFuncUnits', mapBiomkToFuncUnits)
# params of the dysfunctional trajectories (in the disease specific model)
dysfuncParams = np.zeros((nrFuncUnits, 4), float)
dysfuncParams[:, 0] = 1 # ak
dysfuncParams[:, 1] = 0.3 # bk
dysfuncParams[:, 2] = [-3, 7] # ck
dysfuncParams[:, 3] = 0 # dk
# params of individual biomarkers
thetas = np.zeros((nrBiomk, 4), float)
thetas[:, 0] = 1
thetas[:, 1] = 10
thetas[:, 3] = 0
for f in range(nrFuncUnits):
thetas[mapBiomkToFuncUnits == f, 2] = np.linspace(0.2, 0.9, num = nrBiomkInFuncUnits, endpoint = True)
sigmaB = 0.1 * np.ones(nrBiomk)
synthModel = ParHierModel.ParHierModel(dysfuncParams, thetas, mapBiomkToFuncUnits, sigmoidFunc, sigmaB)
params = genSynthData.generateDataJMD(nrSubjLong, nrBiomk, nrTimepts, lowerAgeLim,
upperAgeLim, shiftsLowerLim, shiftsUpperLim, synthModel, outFolder, fileName, forceRegenerate, params)
plotTrajParams['diagNrs'] = np.unique(params['diag'])
plotTrajParams['mapBiomkToFuncUnits'] = mapBiomkToFuncUnits
plotTrajParams['trueParams'] = params['trueParams']
plotTrajParams['labels'] = ['b%d' % n for n in range(nrBiomk)]
plotTrajParams['nrRowsFuncUnit'] = 2
plotTrajParams['nrColsFuncUnit'] = 2
plotTrajParams['colorsTraj'] = [colorsys.hsv_to_rgb(hue, 1, 1) for hue in np.linspace(0, 1, num=nrBiomk, endpoint=False)]
# if False, plot estimated traj. in separate plot from true traj.
plotTrajParams['allTrajOverlap'] = False
params['runIndex'] = args.runIndex
params['nrProc'] = args.nrProc
params['cluster'] = args.cluster
params['plotTrajParams'] = plotTrajParams
params['penalty'] = args.penalty
params['nrFuncUnits'] = nrFuncUnits
params['mapBiomkToFuncUnits'] = mapBiomkToFuncUnits
# params['data'] = dataCross
# params['diag'] = diagCross
# params['scanTimepts'] = scanTimeptsCross
# params['partCode'] = partCodeCross
# params['ageAtScan'] = ageAtScanCrossZ
# params['trueParams'] = trueParams
biomkCols = np.array([colorsys.hsv_to_rgb(hue,1,1) for hue in np.linspace(0,1,num=nrBiomk,endpoint=False)])
if forceRegenerate:
synthPlotter = Plotter.PlotterJDM(plotTrajParams)
fig = synthPlotter.plotTrajData(params['longData'], params['longDiag'], params['trueParams']['dpsLong'],
synthModel, replaceFigMode=True)
fig.savefig('%s/synth1GeneratedData.png' % outFolder)
if np.abs(args.penalty - int(args.penalty) < 0.00001):
expName = '%sPen%d' % (expName, args.penalty)
else:
expName = '%sPen%.1f' % (expName, args.penalty)
params['runPartStd'] = ['L', 'R']
# [mainPart, plot, stage]
params['runPartMain'] = ['R', 'R', 'I']
params['masterProcess'] = args.runIndex == 0
modelNames, res = evaluationFramework.runModels(params, expName, args.modelToRun, runAllExpSynth)
def runAllExpSynth(params, expName, dpmBuilder, compareTrueParamsFunc = None):
""" runs all experiments"""
res = {}
params['patientID'] = AD
params['excludeID'] = -1
params['excludeXvalidID'] = -1
params['excludeStaging'] = [-1]
params['outFolder'] = 'resfiles/synth/%s' % expName
dpmObjStd, res['std'] = evaluationFramework.runStdDPM(params, expName, dpmBuilder,
params['runPartMain'])
if 'compareTrueParamsFunc' in params.keys():
res['resComp'] = params['compareTrueParamsFunc'](dpmObjStd, res['std'])
# print(res)
return res
if __name__ == '__main__':
main()