dmri-commit 2.3.0__cp38-cp38-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- commit/__init__.py +10 -0
- commit/core.cp38-win_amd64.pyd +0 -0
- commit/models.py +110 -0
- commit/operator/__init__.py +0 -0
- commit/operator/operator.cp38-win_amd64.pyd +0 -0
- commit/operator/operator.pyx +246 -0
- commit/operator/operator_c.c +8589 -0
- commit/proximals.cp38-win_amd64.pyd +0 -0
- commit/solvers.py +395 -0
- commit/trk2dictionary.cp38-win_amd64.pyd +0 -0
- dmri_commit-2.3.0.dist-info/LICENSE +79 -0
- dmri_commit-2.3.0.dist-info/METADATA +159 -0
- dmri_commit-2.3.0.dist-info/RECORD +15 -0
- dmri_commit-2.3.0.dist-info/WHEEL +5 -0
- dmri_commit-2.3.0.dist-info/top_level.txt +1 -0
|
Binary file
|
commit/solvers.py
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
from math import sqrt
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from dicelib.ui import setup_logger
|
|
8
|
+
|
|
9
|
+
logger = setup_logger('solvers')
|
|
10
|
+
eps = np.finfo(float).eps
|
|
11
|
+
list_regularizers = [None, 'lasso', 'group_lasso', 'sparse_group_lasso']
|
|
12
|
+
from commit.proximals import non_negativity, omega_group_lasso, prox_group_lasso, soft_thresholding, w_soft_thresholding, omega_sparse_group_lasso, omega_w_sparse_group_lasso
|
|
13
|
+
# removed, for now, projection_onto_l2_ball
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def init_regularisation(regularisation_params):
|
|
17
|
+
"""
|
|
18
|
+
Initialize the regularisation parameters.
|
|
19
|
+
|
|
20
|
+
References:
|
|
21
|
+
[1] Jenatton et al. - 'Proximal Methods for Hierarchical Sparse Coding'
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# check if regularisations are in the list
|
|
25
|
+
if regularisation_params['regIC'] not in list_regularizers or regularisation_params['regEC'] not in list_regularizers or regularisation_params['regISO'] not in list_regularizers:
|
|
26
|
+
logger.error('Regularisation not in the list')
|
|
27
|
+
|
|
28
|
+
startIC = regularisation_params.get('startIC')
|
|
29
|
+
sizeIC = regularisation_params.get('sizeIC')
|
|
30
|
+
startEC = regularisation_params.get('startEC')
|
|
31
|
+
sizeEC = regularisation_params.get('sizeEC')
|
|
32
|
+
startISO = regularisation_params.get('startISO')
|
|
33
|
+
sizeISO = regularisation_params.get('sizeISO')
|
|
34
|
+
|
|
35
|
+
# create array with al coeff_weights for weighted version of 'lasso'
|
|
36
|
+
all_coeff_weights = np.ones(sizeIC+sizeEC+sizeISO, dtype=np.float64)
|
|
37
|
+
if regularisation_params.get('dictIC_params') is not None and "coeff_weights_kept" in regularisation_params['dictIC_params'].keys():
|
|
38
|
+
all_coeff_weights[startIC:(startIC+sizeIC)] = regularisation_params['dictIC_params']["coeff_weights_kept"]
|
|
39
|
+
# if regularisation_params.get('dictEC_params') is not None and "coeff_weights" in regularisation_params['dictEC_params'].keys():
|
|
40
|
+
# all_coeff_weights[startEC:(startEC+sizeEC)] = regularisation_params['dictEC_params']["coeff_weights"]
|
|
41
|
+
# if regularisation_params.get('dictISO_params') is not None and "coeff_weights" in regularisation_params['dictISO_params'].keys():
|
|
42
|
+
# all_coeff_weights[startISO:(startISO+sizeISO)] = regularisation_params['dictISO_params']["coeff_weights"]
|
|
43
|
+
|
|
44
|
+
############################
|
|
45
|
+
# INTRACELLULAR COMPARTMENT#
|
|
46
|
+
############################
|
|
47
|
+
|
|
48
|
+
dictIC_params = regularisation_params.get('dictIC_params')
|
|
49
|
+
|
|
50
|
+
if regularisation_params['regIC'] is None:
|
|
51
|
+
omegaIC = lambda x: 0.0
|
|
52
|
+
if regularisation_params.get('nnIC')==True:
|
|
53
|
+
proxIC = lambda x, _: non_negativity(x,startIC,sizeIC)
|
|
54
|
+
else:
|
|
55
|
+
proxIC = lambda x, _: x
|
|
56
|
+
|
|
57
|
+
elif regularisation_params['regIC'] == 'lasso':
|
|
58
|
+
lambdaIC = regularisation_params['lambdaIC']
|
|
59
|
+
# check if weights are provided
|
|
60
|
+
if dictIC_params is not None and "coeff_weights_kept" in dictIC_params.keys():
|
|
61
|
+
# w = dictIC_params["coeff_weights"]
|
|
62
|
+
omegaIC = lambda x: lambdaIC * np.linalg.norm(all_coeff_weights[startIC:sizeIC]*x[startIC:sizeIC],1)
|
|
63
|
+
if regularisation_params.get('nnIC'):
|
|
64
|
+
proxIC = lambda x, scaling: non_negativity(w_soft_thresholding(x,all_coeff_weights,scaling*lambdaIC,startIC,sizeIC),startIC,sizeIC)
|
|
65
|
+
else:
|
|
66
|
+
proxIC = lambda x, scaling: w_soft_thresholding(x,all_coeff_weights,scaling*lambdaIC,startIC,sizeIC)
|
|
67
|
+
else:
|
|
68
|
+
omegaIC = lambda x: lambdaIC * np.linalg.norm(x[startIC:sizeIC],1)
|
|
69
|
+
if regularisation_params.get('nnIC'):
|
|
70
|
+
proxIC = lambda x, scaling: non_negativity(soft_thresholding(x,scaling*lambdaIC,startIC,sizeIC),startIC,sizeIC)
|
|
71
|
+
else:
|
|
72
|
+
proxIC = lambda x, scaling: soft_thresholding(x,scaling*lambdaIC,startIC,sizeIC)
|
|
73
|
+
|
|
74
|
+
# elif regularisation_params['regIC'] == 'smoothness':
|
|
75
|
+
# lambdaIC = regularisation_params.get('lambdaIC')
|
|
76
|
+
# omegaIC = lambda x: lambdaIC * np.linalg.norm(x[startIC:sizeIC])
|
|
77
|
+
# proxIC = lambda x: projection_onto_l2_ball(x, lambdaIC, startIC, sizeIC)
|
|
78
|
+
|
|
79
|
+
elif regularisation_params['regIC'] == 'group_lasso':
|
|
80
|
+
if not len(dictIC_params['group_idx_kept']) == len(dictIC_params['group_weights']):
|
|
81
|
+
logger.error('Number of groups and weights do not match')
|
|
82
|
+
|
|
83
|
+
lambda_group_IC = regularisation_params['lambdaIC']
|
|
84
|
+
|
|
85
|
+
# convert to new data structure (needed for faster access)
|
|
86
|
+
N = np.sum([g.size for g in dictIC_params['group_idx_kept']])
|
|
87
|
+
groupIdxIC = np.zeros( (N,), dtype=np.int32 )
|
|
88
|
+
groupSizeIC = np.zeros( (dictIC_params['group_idx_kept'].size,), dtype=np.int32 )
|
|
89
|
+
pos = 0
|
|
90
|
+
for i, g in enumerate(dictIC_params['group_idx_kept']) :
|
|
91
|
+
groupSizeIC[i] = g.size
|
|
92
|
+
groupIdxIC[pos:(pos+g.size)] = g[:]
|
|
93
|
+
pos += g.size
|
|
94
|
+
|
|
95
|
+
omegaIC = lambda x: omega_group_lasso( x, groupIdxIC, groupSizeIC, dictIC_params['group_weights'], lambda_group_IC )
|
|
96
|
+
if regularisation_params.get('nnIC'):
|
|
97
|
+
proxIC = lambda x, scaling: non_negativity(prox_group_lasso(x,groupIdxIC,groupSizeIC,dictIC_params['group_weights'],scaling*lambda_group_IC),startIC,sizeIC)
|
|
98
|
+
else:
|
|
99
|
+
proxIC = lambda x, scaling: prox_group_lasso(x,groupIdxIC,groupSizeIC,dictIC_params['group_weights'],scaling*lambda_group_IC)
|
|
100
|
+
|
|
101
|
+
elif regularisation_params['regIC'] == 'sparse_group_lasso':
|
|
102
|
+
if not len(dictIC_params['group_idx_kept']) == len(dictIC_params['group_weights']):
|
|
103
|
+
logger.error('Number of groups and weights do not match')
|
|
104
|
+
|
|
105
|
+
lambdaIC = regularisation_params['lambdaIC'][0]
|
|
106
|
+
lambda_group_IC = regularisation_params['lambdaIC'][1]
|
|
107
|
+
|
|
108
|
+
# convert to new data structure (needed for faster access)
|
|
109
|
+
N = np.sum([g.size for g in dictIC_params['group_idx_kept']])
|
|
110
|
+
groupIdxIC = np.zeros( (N,), dtype=np.int32 )
|
|
111
|
+
groupSizeIC = np.zeros( (dictIC_params['group_idx_kept'].size,), dtype=np.int32 )
|
|
112
|
+
pos = 0
|
|
113
|
+
for i, g in enumerate(dictIC_params['group_idx_kept']) :
|
|
114
|
+
groupSizeIC[i] = g.size
|
|
115
|
+
groupIdxIC[pos:(pos+g.size)] = g[:]
|
|
116
|
+
pos += g.size
|
|
117
|
+
|
|
118
|
+
if "coeff_weights_kept" in dictIC_params.keys():
|
|
119
|
+
# w = dictIC_params["coeff_weights"]
|
|
120
|
+
omegaIC = lambda x: omega_w_sparse_group_lasso( x, all_coeff_weights, groupIdxIC, groupSizeIC, dictIC_params['group_weights'], lambdaIC, lambda_group_IC)
|
|
121
|
+
|
|
122
|
+
if regularisation_params.get('nnIC'):
|
|
123
|
+
proxIC = lambda x, scaling: non_negativity(prox_group_lasso(w_soft_thresholding(x,all_coeff_weights,scaling*lambdaIC,startIC,sizeIC),groupIdxIC,groupSizeIC,dictIC_params['group_weights'],scaling*lambda_group_IC), startIC,sizeIC)
|
|
124
|
+
else:
|
|
125
|
+
proxIC = lambda x, scaling: prox_group_lasso(w_soft_thresholding(x,all_coeff_weights,scaling*lambdaIC,startIC,sizeIC),groupIdxIC,groupSizeIC,dictIC_params['group_weights'],scaling*lambda_group_IC)
|
|
126
|
+
else:
|
|
127
|
+
omegaIC = lambda x: omega_sparse_group_lasso( x, groupIdxIC, groupSizeIC, dictIC_params['group_weights'], lambdaIC, lambda_group_IC)
|
|
128
|
+
|
|
129
|
+
if regularisation_params.get('nnIC'):
|
|
130
|
+
proxIC = lambda x, scaling: non_negativity(prox_group_lasso(soft_thresholding(x,scaling*lambdaIC,startIC,sizeIC),groupIdxIC,groupSizeIC,dictIC_params['group_weights'],scaling*lambda_group_IC), startIC,sizeIC)
|
|
131
|
+
else:
|
|
132
|
+
proxIC = lambda x, scaling: prox_group_lasso(soft_thresholding(x,scaling*lambdaIC,startIC,sizeIC),groupIdxIC,groupSizeIC,dictIC_params['group_weights'],scaling*lambda_group_IC)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
###########################
|
|
136
|
+
# EXTRCELLULAR COMPARTMENT#
|
|
137
|
+
###########################
|
|
138
|
+
|
|
139
|
+
dictEC_params = regularisation_params.get('dictEC_params')
|
|
140
|
+
|
|
141
|
+
if regularisation_params['regEC'] is None:
|
|
142
|
+
omegaEC = lambda x: 0.0
|
|
143
|
+
if regularisation_params.get('nnEC')==True:
|
|
144
|
+
proxEC = lambda x, _: non_negativity(x,startEC,sizeEC)
|
|
145
|
+
else:
|
|
146
|
+
proxEC = lambda x, _: x
|
|
147
|
+
|
|
148
|
+
elif regularisation_params['regEC'] == 'lasso':
|
|
149
|
+
lambdaEC = regularisation_params.get('lambdaEC')
|
|
150
|
+
# check if weights are provided
|
|
151
|
+
# if dictEC_params is not None and "coeff_weights" in dictEC_params.keys():
|
|
152
|
+
# omegaEC = lambda x: lambdaEC * np.linalg.norm(all_coeff_weights[startEC:sizeEC]*x[startEC:sizeEC],1)
|
|
153
|
+
# if regularisation_params.get('nnEC'):
|
|
154
|
+
# proxEC = lambda x, scaling: non_negativity(w_soft_thresholding(x,all_coeff_weights,scaling*lambdaEC,startEC,sizeEC),startEC,sizeEC)
|
|
155
|
+
# else:
|
|
156
|
+
# proxEC = lambda x, scaling: w_soft_thresholding(x,all_coeff_weights,scaling*lambdaEC,startEC,sizeEC)
|
|
157
|
+
# else:
|
|
158
|
+
omegaEC = lambda x: lambdaEC * np.linalg.norm(x[startEC:(startEC+sizeEC)],1)
|
|
159
|
+
if regularisation_params.get('nnEC'):
|
|
160
|
+
proxEC = lambda x, scaling: non_negativity(soft_thresholding(x,scaling*lambdaEC,startEC,sizeEC),startEC,sizeEC)
|
|
161
|
+
else:
|
|
162
|
+
proxEC = lambda x, scaling: soft_thresholding(x,scaling*lambdaEC,startEC,sizeEC)
|
|
163
|
+
|
|
164
|
+
# elif regularisation_params['regIC'] == 'smoothness':
|
|
165
|
+
# lambdaEC = regularisation_params.get('lambdaEC')
|
|
166
|
+
# omegaEC = lambda x: lambdaEC * np.linalg.norm(x[startEC:(startEC+sizeEC)])
|
|
167
|
+
# proxEC = lambda x: projection_onto_l2_ball(x, lambdaEC, startEC, sizeEC)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
########################
|
|
171
|
+
# ISOTROPIC COMPARTMENT#
|
|
172
|
+
########################
|
|
173
|
+
|
|
174
|
+
dictISO_params = regularisation_params.get('dictISO_params')
|
|
175
|
+
|
|
176
|
+
if regularisation_params['regISO'] is None:
|
|
177
|
+
omegaISO = lambda x: 0.0
|
|
178
|
+
if regularisation_params.get('nnISO')==True:
|
|
179
|
+
proxISO = lambda x, _: non_negativity(x,startISO,sizeISO)
|
|
180
|
+
else:
|
|
181
|
+
proxISO = lambda x, _: x
|
|
182
|
+
|
|
183
|
+
elif regularisation_params['regISO'] == 'lasso':
|
|
184
|
+
lambdaISO = regularisation_params.get('lambdaISO')
|
|
185
|
+
# check if weights are provided
|
|
186
|
+
# if dictISO_params is not None and "coeff_weights" in dictISO_params.keys():
|
|
187
|
+
# omegaISO = lambda x: lambdaISO * np.linalg.norm(all_coeff_weights[startISO:sizeISO]*x[startISO:sizeISO],1)
|
|
188
|
+
# if regularisation_params.get('nnISO'):
|
|
189
|
+
# proxISO = lambda x, scaling: non_negativity(w_soft_thresholding(x,all_coeff_weights,scaling*lambdaISO,startISO,sizeISO),startISO,sizeISO)
|
|
190
|
+
# else:
|
|
191
|
+
# proxISO = lambda x, scaling: w_soft_thresholding(x,all_coeff_weights,scaling*lambdaISO,startISO,sizeISO)
|
|
192
|
+
# else:
|
|
193
|
+
omegaISO = lambda x: lambdaISO * np.linalg.norm(x[startISO:(startISO+sizeISO)],1)
|
|
194
|
+
if regularisation_params.get('nnISO'):
|
|
195
|
+
proxISO = lambda x, scaling: non_negativity(soft_thresholding(x,scaling*lambdaISO,startISO,sizeISO),startISO,sizeISO)
|
|
196
|
+
else:
|
|
197
|
+
proxISO = lambda x, scaling: soft_thresholding(x,scaling*lambdaISO,startISO,sizeISO)
|
|
198
|
+
|
|
199
|
+
# elif regularisation_params['regISO'] == 'group_lasso':
|
|
200
|
+
# lambdaISO = regularisation_params.get('lambdaISO')
|
|
201
|
+
# omegaISO = lambda x: lambdaISO * np.linalg.norm(x[startISO:(startISO+sizeISO)])
|
|
202
|
+
# proxISO = lambda x: projection_onto_l2_ball(x, lambdaISO, startISO, sizeISO)
|
|
203
|
+
|
|
204
|
+
omega = lambda x: omegaIC(x) + omegaEC(x) + omegaISO(x)
|
|
205
|
+
prox = lambda x, scaling: proxIC(proxEC(proxISO(x, scaling), scaling), scaling)
|
|
206
|
+
|
|
207
|
+
regularisation_params["omega"] = omega
|
|
208
|
+
regularisation_params["prox"] = prox
|
|
209
|
+
|
|
210
|
+
return regularisation_params
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def evaluate_model(y, A, x, regularisation=None):
|
|
214
|
+
if regularisation is None:
|
|
215
|
+
omega = lambda x: 0.0
|
|
216
|
+
else:
|
|
217
|
+
omega, _ = init_regularisation(regularisation)
|
|
218
|
+
|
|
219
|
+
return 0.5*np.linalg.norm(A.dot(x)-y)**2 + omega(x)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def solve(y, A, At, tol_fun=1e-4, tol_x=1e-6, max_iter=1000, verbose=True, x0 =None, regularisation=None, confidence_array=None):
|
|
223
|
+
"""
|
|
224
|
+
Solve the regularised least squares problem
|
|
225
|
+
|
|
226
|
+
argmin_x 0.5*|| sqrt(W) ( Ax-y ) ||_2^2 + Omega(x)
|
|
227
|
+
|
|
228
|
+
with the Omega described by 'regularisation' and W is the confidence_array
|
|
229
|
+
|
|
230
|
+
Check the documentation of commit.solvers.init_regularisation to see how to
|
|
231
|
+
solve a specific problem.
|
|
232
|
+
"""
|
|
233
|
+
if regularisation is None:
|
|
234
|
+
omega = lambda x: 0.0
|
|
235
|
+
prox = lambda x, _: x
|
|
236
|
+
else:
|
|
237
|
+
omega, prox = regularisation['omega'], regularisation['prox']
|
|
238
|
+
|
|
239
|
+
if x0 is None:
|
|
240
|
+
x0 = np.zeros(A.shape[1])
|
|
241
|
+
|
|
242
|
+
if confidence_array is not None:
|
|
243
|
+
confidence_array = np.sqrt(confidence_array)
|
|
244
|
+
|
|
245
|
+
return fista(y, A, At, omega, prox, confidence_array, tol_fun, tol_x, max_iter, verbose, x0)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def fista(y, A, At, omega, prox, sqrt_W=None, tol_fun=1e-4, tol_x=1e-6, max_iter=1000, verbose=False, x0=None):
|
|
249
|
+
"""
|
|
250
|
+
Solve the regularised least squares problem
|
|
251
|
+
|
|
252
|
+
argmin_x 0.5*|| sqrt(W) ( Ax-y ) ||_2^2 + Omega(x)
|
|
253
|
+
|
|
254
|
+
with the FISTA algorithm described in [1].
|
|
255
|
+
|
|
256
|
+
The penalty term and its proximal operator must be defined in such a way
|
|
257
|
+
that they already contain the regularisation parameter.
|
|
258
|
+
|
|
259
|
+
References:
|
|
260
|
+
[1] Beck & Teboulle - `A Fast Iterative Shrinkage Thresholding
|
|
261
|
+
Algorithm for Linear Inverse Problems`
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
# Initialization
|
|
265
|
+
if x0 is None:
|
|
266
|
+
x0 = np.zeros(A.shape[1])
|
|
267
|
+
xhat = x0.copy()
|
|
268
|
+
x = np.zeros_like(xhat)
|
|
269
|
+
if sqrt_W is not None:
|
|
270
|
+
res = sqrt_W * (A.dot(xhat) - y)
|
|
271
|
+
grad = np.asarray(At.dot(sqrt_W * res))
|
|
272
|
+
else:
|
|
273
|
+
res = A.dot(xhat) - y
|
|
274
|
+
grad = np.asarray(At.dot(res))
|
|
275
|
+
|
|
276
|
+
prox( xhat, 1.0 )
|
|
277
|
+
reg_term = omega( xhat )
|
|
278
|
+
prev_obj = 0.5 * np.linalg.norm(res)**2 + reg_term
|
|
279
|
+
|
|
280
|
+
told = 1
|
|
281
|
+
beta = 0.9
|
|
282
|
+
prev_x = xhat.copy()
|
|
283
|
+
qfval = prev_obj
|
|
284
|
+
|
|
285
|
+
# Step size computation
|
|
286
|
+
if sqrt_W is not None:
|
|
287
|
+
L = ( np.linalg.norm( sqrt_W * A.dot(grad) ) / np.linalg.norm(grad) )**2
|
|
288
|
+
else:
|
|
289
|
+
L = ( np.linalg.norm( A.dot(grad) ) / np.linalg.norm(grad) )**2
|
|
290
|
+
step_size = 1.9 / L
|
|
291
|
+
# Main loop
|
|
292
|
+
if verbose==4 :
|
|
293
|
+
print()
|
|
294
|
+
print( " | 1/2||Ax-y||^2 Omega | Cost function Abs error Rel error | Abs x Rel x " )
|
|
295
|
+
print( "------|--------------------------------|-----------------------------------------------|------------------------------" )
|
|
296
|
+
iter = 1
|
|
297
|
+
while True :
|
|
298
|
+
if verbose==4 :
|
|
299
|
+
print( "%4d |" % iter, end="" )
|
|
300
|
+
sys.stdout.flush()
|
|
301
|
+
|
|
302
|
+
# Smooth step
|
|
303
|
+
x = xhat - step_size*grad
|
|
304
|
+
|
|
305
|
+
# Non-smooth step
|
|
306
|
+
prox( x, step_size )
|
|
307
|
+
reg_term_x = omega( x )
|
|
308
|
+
# Check stepsize
|
|
309
|
+
tmp = x-xhat
|
|
310
|
+
q = qfval + np.real( np.dot(tmp,grad) ) + 0.5/step_size * np.linalg.norm(tmp)**2 + reg_term_x
|
|
311
|
+
if sqrt_W is not None:
|
|
312
|
+
res = sqrt_W * ( A.dot(x) - y )
|
|
313
|
+
else:
|
|
314
|
+
res = A.dot(x) - y
|
|
315
|
+
res_norm = np.linalg.norm(res)
|
|
316
|
+
curr_obj = 0.5 * res_norm**2 + reg_term_x
|
|
317
|
+
|
|
318
|
+
# Backtracking
|
|
319
|
+
while curr_obj > q :
|
|
320
|
+
# Smooth step
|
|
321
|
+
step_size = beta*step_size
|
|
322
|
+
x = xhat - step_size*grad
|
|
323
|
+
|
|
324
|
+
# Non-smooth step
|
|
325
|
+
prox( x, step_size )
|
|
326
|
+
reg_term_x = omega( x )
|
|
327
|
+
|
|
328
|
+
# Check stepsize
|
|
329
|
+
tmp = x-xhat
|
|
330
|
+
q = qfval + np.real( np.dot(tmp,grad) ) + 0.5/step_size * np.linalg.norm(tmp)**2 + reg_term_x
|
|
331
|
+
if sqrt_W is not None:
|
|
332
|
+
res = sqrt_W * ( A.dot(x) - y )
|
|
333
|
+
else:
|
|
334
|
+
res = A.dot(x) - y
|
|
335
|
+
res_norm = np.linalg.norm(res)
|
|
336
|
+
curr_obj = 0.5 * res_norm**2 + reg_term_x
|
|
337
|
+
|
|
338
|
+
# Global stopping criterion
|
|
339
|
+
abs_obj = abs(curr_obj - prev_obj)
|
|
340
|
+
rel_obj = abs_obj / curr_obj
|
|
341
|
+
abs_x = np.linalg.norm(x - prev_x)
|
|
342
|
+
rel_x = abs_x / ( np.linalg.norm(x) + eps )
|
|
343
|
+
if verbose==4 :
|
|
344
|
+
print( " %13.7e %13.7e | %13.7e %13.7e %13.7e | %13.7e %13.7e" % ( 0.5 * res_norm**2, reg_term_x, curr_obj, abs_obj, rel_obj, abs_x, rel_x ), flush=True )
|
|
345
|
+
|
|
346
|
+
if abs_obj < eps :
|
|
347
|
+
criterion = "Absolute tolerance on the objective"
|
|
348
|
+
break
|
|
349
|
+
elif rel_obj < tol_fun :
|
|
350
|
+
criterion = "Relative tolerance on the objective"
|
|
351
|
+
break
|
|
352
|
+
elif abs_x < eps :
|
|
353
|
+
criterion = "Absolute tolerance on the unknown"
|
|
354
|
+
break
|
|
355
|
+
elif rel_x < tol_x :
|
|
356
|
+
criterion = "Relative tolerance on the unknown"
|
|
357
|
+
break
|
|
358
|
+
elif iter >= max_iter :
|
|
359
|
+
criterion = "Maximum number of iterations"
|
|
360
|
+
break
|
|
361
|
+
|
|
362
|
+
# FISTA update
|
|
363
|
+
t = 0.5 * ( 1 + sqrt(1+4*told**2) )
|
|
364
|
+
xhat = x + (told-1)/t * (x - prev_x)
|
|
365
|
+
|
|
366
|
+
# Gradient computation
|
|
367
|
+
if sqrt_W is not None:
|
|
368
|
+
res = sqrt_W * ( A.dot(xhat) - y )
|
|
369
|
+
grad = np.asarray(At.dot(sqrt_W * res))
|
|
370
|
+
else:
|
|
371
|
+
res = A.dot(xhat) - y
|
|
372
|
+
grad = np.asarray(At.dot(res))
|
|
373
|
+
|
|
374
|
+
# Update variables
|
|
375
|
+
iter += 1
|
|
376
|
+
prev_obj = curr_obj
|
|
377
|
+
prev_x = x.copy()
|
|
378
|
+
told = t
|
|
379
|
+
qfval = 0.5 * np.linalg.norm(res)**2
|
|
380
|
+
|
|
381
|
+
if verbose==4 :
|
|
382
|
+
print( "< Stopping criterion: %s >" % criterion, flush=True )
|
|
383
|
+
|
|
384
|
+
opt_details = {}
|
|
385
|
+
opt_details['residual'] = 0.5*res_norm**2
|
|
386
|
+
opt_details['regterm'] = reg_term_x
|
|
387
|
+
opt_details['cost_function'] = curr_obj
|
|
388
|
+
opt_details['abs_cost'] = abs_obj
|
|
389
|
+
opt_details['rel_cost'] = rel_obj
|
|
390
|
+
opt_details['abs_x'] = abs_x
|
|
391
|
+
opt_details['rel_x'] = rel_x
|
|
392
|
+
opt_details['iterations'] = iter
|
|
393
|
+
opt_details['stopping_criterion'] = criterion
|
|
394
|
+
|
|
395
|
+
return x, opt_details
|
|
Binary file
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
COMMIT software license agreement
|
|
3
|
+
Version 2, 24 July 2023
|
|
4
|
+
################################################################################
|
|
5
|
+
|
|
6
|
+
------------------------------------PREAMBLE------------------------------------
|
|
7
|
+
This license agreement (“Agreement”) is a legal agreement between you and the
|
|
8
|
+
Diffusion Imaging and Connectivity Estimation laboratory (“DICE lab”) for the
|
|
9
|
+
use of the COMMIT software (“Software”). By downloading and/or using the
|
|
10
|
+
Software, you hereby accept and agree to all the terms and conditions of this
|
|
11
|
+
Agreement. As used in this Agreement, “you” refers to any individual or
|
|
12
|
+
organization that uses the Software.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
------------------------------TERMS AND CONDITIONS------------------------------
|
|
16
|
+
[1] License Grant
|
|
17
|
+
Subject to all the terms and conditions of this Agreement, the DICE lab hereby
|
|
18
|
+
grants you a worldwide, non-exclusive, non-transferable, limited license to
|
|
19
|
+
copy, use, modify, and redistribute the Software solely for research and
|
|
20
|
+
educational purposes, free of charge.
|
|
21
|
+
|
|
22
|
+
[2] Commercial use
|
|
23
|
+
You may not use the Software and/or any work based on or using the Software for
|
|
24
|
+
any commercial purpose, including but not limited to selling, licensing,
|
|
25
|
+
distributing, renting, or leasing the Software for profit. If you want to use
|
|
26
|
+
the Software for commercial purposes, you may contact the DICE lab to obtain a
|
|
27
|
+
commercial license agreement. The DICE lab may consider offering a commercial
|
|
28
|
+
license, subject to negotiation of appropriate terms and conditions, including
|
|
29
|
+
but not limited to the payment of a license fee and compliance with any
|
|
30
|
+
additional restriction on the use of the Software.
|
|
31
|
+
|
|
32
|
+
[3] Attributions and Acknowledgments
|
|
33
|
+
You agree to provide an acknowledgement identifying the Software and referencing
|
|
34
|
+
its use in any publication, presentation, research result, and product related
|
|
35
|
+
to or arising from the use of the Software. You also agree to give proper
|
|
36
|
+
attribution to the original Software and reproduce this Agreement in any
|
|
37
|
+
modified and/or redistributed work based on the Software.
|
|
38
|
+
|
|
39
|
+
[4] Patents
|
|
40
|
+
If you plan to file a patent application based on or using the Software, you
|
|
41
|
+
must contact the DICE lab. The DICE lab may have certain rights or restrictions
|
|
42
|
+
related to such patents that need to be addressed before filing the application.
|
|
43
|
+
|
|
44
|
+
[5] Compliance with Law
|
|
45
|
+
In exercising your rights under this Agreement, you agree to comply with all
|
|
46
|
+
applicable governmental laws and regulations, including but not limited to the
|
|
47
|
+
use, export, and transmission of the Software. You are solely responsible for
|
|
48
|
+
ensuring that your use of the Software complies with such laws and regulations.
|
|
49
|
+
The DICE lab is not responsible for any violations of such laws or regulations
|
|
50
|
+
by you.
|
|
51
|
+
|
|
52
|
+
[6] Warranty
|
|
53
|
+
The Software is provided "AS IS" without warranty of any kind, express or
|
|
54
|
+
implied, including but not limited to the warranties of merchantability, fitness
|
|
55
|
+
for a particular purpose and non-infringement of third-party rights. The
|
|
56
|
+
Software may also contain errors and is subject to further development and
|
|
57
|
+
revision. The DICE lab does not guarantee the accuracy of the Software or any
|
|
58
|
+
result or data arising from the use of the Software.
|
|
59
|
+
|
|
60
|
+
[7] Disclaimers
|
|
61
|
+
The Software has been designed for research purposes only and has not been
|
|
62
|
+
reviewed or approved by the Food and Drug Administration or by any other agency.
|
|
63
|
+
You acknowledge and agree that clinical applications are neither recommended nor
|
|
64
|
+
advised.
|
|
65
|
+
|
|
66
|
+
[8] Limitation of Liability
|
|
67
|
+
In no event shall the DICE lab be liable to any party for any direct, indirect,
|
|
68
|
+
special, incidental, exemplary, or consequential damages, however caused and
|
|
69
|
+
under any theory of liability, arising in any way related to the Software, even
|
|
70
|
+
if the DICE lab has been advised of the possibility of such damages. Except to
|
|
71
|
+
the extent prohibited by law or regulation, you assume all risk and liability
|
|
72
|
+
for your use of the Software. You also agree to indemnify and hold harmless the
|
|
73
|
+
DICE lab from and against all claims, suits, actions, demands, and judgments
|
|
74
|
+
arising from your use or misuse of the Software.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
------------------------------------CONTACT-------------------------------------
|
|
78
|
+
If you have any question about the terms of this Agreement, you may contact the
|
|
79
|
+
head of the DICE lab Alessandro Daducci at alessandro.daducci@univr.it
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dmri-commit
|
|
3
|
+
Version: 2.3.0
|
|
4
|
+
Summary: Convex Optimization Modeling for Microstructure Informed Tractography (COMMIT)
|
|
5
|
+
Author-email: Alessandro Daducci <alessandro.daducci@univr.it>
|
|
6
|
+
Maintainer-email: DICE lab <DICE_lab@strutture.univr.it>
|
|
7
|
+
License: ################################################################################
|
|
8
|
+
COMMIT software license agreement
|
|
9
|
+
Version 2, 24 July 2023
|
|
10
|
+
################################################################################
|
|
11
|
+
|
|
12
|
+
------------------------------------PREAMBLE------------------------------------
|
|
13
|
+
This license agreement (“Agreement”) is a legal agreement between you and the
|
|
14
|
+
Diffusion Imaging and Connectivity Estimation laboratory (“DICE lab”) for the
|
|
15
|
+
use of the COMMIT software (“Software”). By downloading and/or using the
|
|
16
|
+
Software, you hereby accept and agree to all the terms and conditions of this
|
|
17
|
+
Agreement. As used in this Agreement, “you” refers to any individual or
|
|
18
|
+
organization that uses the Software.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
------------------------------TERMS AND CONDITIONS------------------------------
|
|
22
|
+
[1] License Grant
|
|
23
|
+
Subject to all the terms and conditions of this Agreement, the DICE lab hereby
|
|
24
|
+
grants you a worldwide, non-exclusive, non-transferable, limited license to
|
|
25
|
+
copy, use, modify, and redistribute the Software solely for research and
|
|
26
|
+
educational purposes, free of charge.
|
|
27
|
+
|
|
28
|
+
[2] Commercial use
|
|
29
|
+
You may not use the Software and/or any work based on or using the Software for
|
|
30
|
+
any commercial purpose, including but not limited to selling, licensing,
|
|
31
|
+
distributing, renting, or leasing the Software for profit. If you want to use
|
|
32
|
+
the Software for commercial purposes, you may contact the DICE lab to obtain a
|
|
33
|
+
commercial license agreement. The DICE lab may consider offering a commercial
|
|
34
|
+
license, subject to negotiation of appropriate terms and conditions, including
|
|
35
|
+
but not limited to the payment of a license fee and compliance with any
|
|
36
|
+
additional restriction on the use of the Software.
|
|
37
|
+
|
|
38
|
+
[3] Attributions and Acknowledgments
|
|
39
|
+
You agree to provide an acknowledgement identifying the Software and referencing
|
|
40
|
+
its use in any publication, presentation, research result, and product related
|
|
41
|
+
to or arising from the use of the Software. You also agree to give proper
|
|
42
|
+
attribution to the original Software and reproduce this Agreement in any
|
|
43
|
+
modified and/or redistributed work based on the Software.
|
|
44
|
+
|
|
45
|
+
[4] Patents
|
|
46
|
+
If you plan to file a patent application based on or using the Software, you
|
|
47
|
+
must contact the DICE lab. The DICE lab may have certain rights or restrictions
|
|
48
|
+
related to such patents that need to be addressed before filing the application.
|
|
49
|
+
|
|
50
|
+
[5] Compliance with Law
|
|
51
|
+
In exercising your rights under this Agreement, you agree to comply with all
|
|
52
|
+
applicable governmental laws and regulations, including but not limited to the
|
|
53
|
+
use, export, and transmission of the Software. You are solely responsible for
|
|
54
|
+
ensuring that your use of the Software complies with such laws and regulations.
|
|
55
|
+
The DICE lab is not responsible for any violations of such laws or regulations
|
|
56
|
+
by you.
|
|
57
|
+
|
|
58
|
+
[6] Warranty
|
|
59
|
+
The Software is provided "AS IS" without warranty of any kind, express or
|
|
60
|
+
implied, including but not limited to the warranties of merchantability, fitness
|
|
61
|
+
for a particular purpose and non-infringement of third-party rights. The
|
|
62
|
+
Software may also contain errors and is subject to further development and
|
|
63
|
+
revision. The DICE lab does not guarantee the accuracy of the Software or any
|
|
64
|
+
result or data arising from the use of the Software.
|
|
65
|
+
|
|
66
|
+
[7] Disclaimers
|
|
67
|
+
The Software has been designed for research purposes only and has not been
|
|
68
|
+
reviewed or approved by the Food and Drug Administration or by any other agency.
|
|
69
|
+
You acknowledge and agree that clinical applications are neither recommended nor
|
|
70
|
+
advised.
|
|
71
|
+
|
|
72
|
+
[8] Limitation of Liability
|
|
73
|
+
In no event shall the DICE lab be liable to any party for any direct, indirect,
|
|
74
|
+
special, incidental, exemplary, or consequential damages, however caused and
|
|
75
|
+
under any theory of liability, arising in any way related to the Software, even
|
|
76
|
+
if the DICE lab has been advised of the possibility of such damages. Except to
|
|
77
|
+
the extent prohibited by law or regulation, you assume all risk and liability
|
|
78
|
+
for your use of the Software. You also agree to indemnify and hold harmless the
|
|
79
|
+
DICE lab from and against all claims, suits, actions, demands, and judgments
|
|
80
|
+
arising from your use or misuse of the Software.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
------------------------------------CONTACT-------------------------------------
|
|
84
|
+
If you have any question about the terms of this Agreement, you may contact the
|
|
85
|
+
head of the DICE lab Alessandro Daducci at alessandro.daducci@univr.it
|
|
86
|
+
|
|
87
|
+
Project-URL: Homepage, https://github.com/daducci/COMMIT.git
|
|
88
|
+
Project-URL: Documentation, https://github.com/daducci/COMMIT/wiki
|
|
89
|
+
Project-URL: Repository, https://github.com/daducci/COMMIT.git
|
|
90
|
+
Project-URL: Issues, https://github.com/daducci/COMMIT/issues
|
|
91
|
+
Project-URL: Changelog, https://github.com/daducci/COMMIT/blob/master/CHANGELOG.md
|
|
92
|
+
Keywords: Neuroimaging
|
|
93
|
+
Classifier: Intended Audience :: Science/Research
|
|
94
|
+
Classifier: License :: Other/Proprietary License
|
|
95
|
+
Classifier: Programming Language :: C++
|
|
96
|
+
Classifier: Programming Language :: Cython
|
|
97
|
+
Classifier: Programming Language :: Python :: 3
|
|
98
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
99
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
100
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
101
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
102
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
103
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
104
|
+
Requires-Python: >=3.8
|
|
105
|
+
Description-Content-Type: text/markdown
|
|
106
|
+
License-File: LICENSE
|
|
107
|
+
Requires-Dist: dmri-amico >=2.0.1
|
|
108
|
+
Requires-Dist: dmri-dicelib >=1.1.0
|
|
109
|
+
Requires-Dist: numpy <2.0.0,>=1.24.4
|
|
110
|
+
Requires-Dist: scipy >=1.10.1
|
|
111
|
+
|
|
112
|
+
[](https://pypi.org/project/dmri-commit/)
|
|
113
|
+
[](#)
|
|
114
|
+
[](https://github.com/daducci/COMMIT/blob/master/LICENSE)
|
|
115
|
+
[](#)
|
|
116
|
+
[](https://ieeexplore.ieee.org/document/6884830)
|
|
117
|
+
|
|
118
|
+
[](#)
|
|
119
|
+
[](#)
|
|
120
|
+
[](#)
|
|
121
|
+
[](#)
|
|
122
|
+
[](#)
|
|
123
|
+
[](https://twitter.com/intent/follow?screen_name=ADaducci)
|
|
124
|
+
|
|
125
|
+
# COMMIT
|
|
126
|
+
|
|
127
|
+
The reconstructions recovered with existing tractography algorithms are not really quantitative even though diffusion MRI is a quantitative modality. COMMIT stands for *Convex Optimization for Microstructure Informed Tractography* and is a **powerful framework for enhancing the anatomical accuracy of the reconstructions** by combining tractography with microstructural features of the neuronal tissue.
|
|
128
|
+
|
|
129
|
+
<img align="right" src="https://github.com/daducci/COMMIT/wiki/images/filtering_methods.png" height="225">
|
|
130
|
+
|
|
131
|
+
**How?** Starting from an input set of candidate fiber-tracts estimated using standard fiber-tracking techniques, COMMIT models the diffusion MRI signal in each voxel of the image as a *linear combination* of the restricted and hindered contributions generated in every location of the brain by these candidate tracts. Then, COMMIT seeks for the effective contribution of each of them such that they globally fit the measured signal at best.
|
|
132
|
+
These weights can be *efficiently estimated by solving a convenient linear system*.
|
|
133
|
+
|
|
134
|
+
Results clearly demonstrated the benefits of the proposed formulation, opening new perspectives for a more quantitative and biologically-plausible assessment of the structural connectivity of the brain. See the [references](https://github.com/daducci/COMMIT/wiki/References) for more information.
|
|
135
|
+
|
|
136
|
+
<p align="center">
|
|
137
|
+
<img src="https://github.com/daducci/COMMIT/wiki/images/COMMIT_example.png" height="450">
|
|
138
|
+
</p>
|
|
139
|
+
|
|
140
|
+
## Main features
|
|
141
|
+
|
|
142
|
+
- Very efficient: COMMIT is implemented in Python but the core of the algorithm is implemented in C++ and using **multi-thread programming** for efficient parallel computation.
|
|
143
|
+
- Accepts and works with **any input tractogram** (i.e. set of fiber tracts).
|
|
144
|
+
- Can easily implement and consider **any multi-compartment model** available in the literature: possibility to account for restricted, hindered as well as isotropic contributions into the signal forward model.
|
|
145
|
+
- **Low memory** consumption using optimized sparse data structures, e.g. it can easily run on a standard laptop with 8GB RAM a full-brain tractogram from the HCP data (1M fibers, 3 shells, 1.25 mm^3 resolution).
|
|
146
|
+
- **Soon**: **GPU implementation** for even faster model fitting.
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
## Documentation
|
|
150
|
+
|
|
151
|
+
More information/documentation, as well as a series of tutorials, can be found in the [wiki pages](https://github.com/daducci/COMMIT/wiki/Home).
|
|
152
|
+
|
|
153
|
+
### Installation
|
|
154
|
+
To install COMMIT, refer to the [installation guide](https://github.com/daducci/COMMIT/wiki/Installation).
|
|
155
|
+
|
|
156
|
+
### Getting started
|
|
157
|
+
|
|
158
|
+
To get started with the COMMIT framework, have a look at [this tutorial](https://github.com/daducci/COMMIT/wiki/Getting-started), which will guide you through the main steps of the processing.
|
|
159
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
commit/__init__.py,sha256=AaTCXr1oNiLf8XiGaznm0_saRdjGNwjALuMhhbk9xa8,262
|
|
2
|
+
commit/core.cp38-win_amd64.pyd,sha256=rYRUL93-N2b8cINJk7ZROeVpCf7NHNpxu1qjkoqUA4g,710144
|
|
3
|
+
commit/models.py,sha256=Z04Ux2aZQ3pvHSLem7l1VUm5JUjC7FpkBlxxl1rLHBI,3603
|
|
4
|
+
commit/proximals.cp38-win_amd64.pyd,sha256=ggmAd2i0gVh2uw_6jrOJyh-ynHKf089SaP7KAchNonw,184320
|
|
5
|
+
commit/solvers.py,sha256=C_fLjuKT_pjH3_1EmUJdiSz6M574k51-yoGJ5eqvHsc,17717
|
|
6
|
+
commit/trk2dictionary.cp38-win_amd64.pyd,sha256=qttHV3Kff8usFgjevf90RDvX2B7RQNz-0Mye7cjUsTY,427520
|
|
7
|
+
commit/operator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
commit/operator/operator.cp38-win_amd64.pyd,sha256=wH_qw68HqnKs3Dsiac2HUaBV6793btZu58WQ21M8BXU,369152
|
|
9
|
+
commit/operator/operator.pyx,sha256=Qc95vijYxoMjmDrqc6wiDK8RVcclFj1tdx9X7MIeJTk,9400
|
|
10
|
+
commit/operator/operator_c.c,sha256=qXvKE5EQopnBM35i_E2plDunNSj8xOlDVCzhK6yXgqI,360704
|
|
11
|
+
dmri_commit-2.3.0.dist-info/LICENSE,sha256=KGYJ1FLUEuu_4DZKE7mvtewiMv_29EzY-3BVrhBQMdQ,4493
|
|
12
|
+
dmri_commit-2.3.0.dist-info/METADATA,sha256=Tc5EyCZzgF-RrP4utqOy2LtiE5yARiKu-X7_7bhVP5c,10428
|
|
13
|
+
dmri_commit-2.3.0.dist-info/WHEEL,sha256=BIzqQvR0Lkhnc-FBonYpFhy3UzxcO5dqXwgpZ-I7rOw,99
|
|
14
|
+
dmri_commit-2.3.0.dist-info/top_level.txt,sha256=UINu7ldOz_ed6jtP1AZz19AA96Xxd9imowALWceDg7g,7
|
|
15
|
+
dmri_commit-2.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
commit
|