dmri-commit 2.4.1__tar.gz → 2.4.3__tar.gz
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.
- {dmri_commit-2.4.1/dmri_commit.egg-info → dmri_commit-2.4.3}/PKG-INFO +3 -3
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/core.pyx +97 -113
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/operator/operator.pyx +6 -6
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/operator/operator_c.c +855 -855
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/trk2dictionary/trk2dictionary.pyx +2 -1
- {dmri_commit-2.4.1 → dmri_commit-2.4.3/dmri_commit.egg-info}/PKG-INFO +3 -3
- dmri_commit-2.4.3/dmri_commit.egg-info/requires.txt +4 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/pyproject.toml +4 -4
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/setup_operator.py +23 -23
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/tests/test_demo.py +22 -20
- dmri_commit-2.4.1/dmri_commit.egg-info/requires.txt +0 -4
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/LICENSE +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/MANIFEST.in +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/README.md +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/__init__.py +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/models.pyx +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/operator/__init__.py +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/proximals.pyx +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/solvers.py +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/trk2dictionary/ProgressBar.h +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/trk2dictionary/Vector.h +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/commit/trk2dictionary/trk2dictionary_c.cpp +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/dmri_commit.egg-info/SOURCES.txt +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/dmri_commit.egg-info/dependency_links.txt +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/dmri_commit.egg-info/top_level.txt +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/setup.cfg +0 -0
- {dmri_commit-2.4.1 → dmri_commit-2.4.3}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dmri-commit
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.3
|
|
4
4
|
Summary: Convex Optimization Modeling for Microstructure Informed Tractography (COMMIT)
|
|
5
5
|
Author-email: Alessandro Daducci <alessandro.daducci@univr.it>
|
|
6
6
|
Maintainer-email: DICE lab <DICE_lab@strutture.univr.it>
|
|
@@ -105,8 +105,8 @@ Requires-Python: >=3.8
|
|
|
105
105
|
Description-Content-Type: text/markdown
|
|
106
106
|
License-File: LICENSE
|
|
107
107
|
Requires-Dist: dmri-amico>=2.0.1
|
|
108
|
-
Requires-Dist: dmri-dicelib
|
|
109
|
-
Requires-Dist: numpy
|
|
108
|
+
Requires-Dist: dmri-dicelib<1.4.0,>=1.3.0
|
|
109
|
+
Requires-Dist: numpy>=1.24.4
|
|
110
110
|
Requires-Dist: scipy>=1.10.1
|
|
111
111
|
Dynamic: license-file
|
|
112
112
|
|
|
@@ -76,7 +76,6 @@ cdef class Evaluation :
|
|
|
76
76
|
cdef public CONFIG
|
|
77
77
|
cdef public temp_data
|
|
78
78
|
cdef public confidence_map_img
|
|
79
|
-
cdef public debias_mask
|
|
80
79
|
cdef public verbose
|
|
81
80
|
|
|
82
81
|
def __init__( self, study_path='.', subject='.', dictionary_path='COMMIT'):
|
|
@@ -102,7 +101,6 @@ cdef class Evaluation :
|
|
|
102
101
|
self.regularisation_params = None # set by "set_regularisation" method
|
|
103
102
|
self.x = None # set by "fit" method
|
|
104
103
|
self.confidence_map_img = None # set by "fit" method
|
|
105
|
-
self.debias_mask = None # set by "fit" method
|
|
106
104
|
self.x_nnls = None # set by "fit" method (coefficients of IC compartment estimated without regularization)
|
|
107
105
|
self.verbose = 3
|
|
108
106
|
|
|
@@ -651,7 +649,7 @@ cdef class Evaluation :
|
|
|
651
649
|
self.THREADS['EC'][i] = np.searchsorted( self.DICTIONARY['EC']['vox'], self.DICTIONARY['IC']['vox'][ self.THREADS['IC'][i] ] )
|
|
652
650
|
self.THREADS['EC'][n] = self.DICTIONARY['EC']['n']
|
|
653
651
|
|
|
654
|
-
# check if some threads are not assigned any segment
|
|
652
|
+
# check if some threads are not assigned any segment # TODO: check if this is really needed (EC is treated like ISO, but in that case this check is not needed)
|
|
655
653
|
if np.count_nonzero( np.diff( self.THREADS['EC'].astype(np.int32) ) <= 0 ) :
|
|
656
654
|
self.THREADS = None
|
|
657
655
|
logger.error( 'Too many threads for the EC compartments to evaluate; try decreasing the number' )
|
|
@@ -708,25 +706,29 @@ cdef class Evaluation :
|
|
|
708
706
|
|
|
709
707
|
if self.DICTIONARY['ISO']['n'] > 0 :
|
|
710
708
|
self.THREADS['ISOt'] = np.zeros( n+1, dtype=np.uint32 )
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
self.THREADS['ISOt'][
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
self.THREADS =
|
|
720
|
-
logger.error( 'Too many threads for the ISO compartments to evaluate; try decreasing the number' )
|
|
709
|
+
if self.DICTIONARY['ISO']['n'] < n:
|
|
710
|
+
n_iso = self.DICTIONARY['ISO']['n']
|
|
711
|
+
self.THREADS['ISOt'][:n_iso+1] = np.arange( n_iso+1 )
|
|
712
|
+
self.THREADS['ISOt'][n_iso+1:] = n_iso
|
|
713
|
+
else:
|
|
714
|
+
N = np.floor( self.DICTIONARY['ISO']['n']/n )
|
|
715
|
+
for i in xrange(1,n) :
|
|
716
|
+
self.THREADS['ISOt'][i] = self.THREADS['ISOt'][i-1] + N
|
|
717
|
+
self.THREADS['ISOt'][n] = self.DICTIONARY['ISO']['n']
|
|
721
718
|
else :
|
|
722
719
|
self.THREADS['ISOt'] = None
|
|
723
720
|
|
|
724
721
|
logger.info( f'[ {format_time(time.time() - tic)} ]' )
|
|
725
722
|
|
|
726
723
|
|
|
727
|
-
def build_operator( self ) :
|
|
724
|
+
def build_operator( self, ic_debias_mask=None ) :
|
|
728
725
|
"""Build the operator for computing the matrix-vector multiplications by A and A'
|
|
729
726
|
using the informations from self.DICTIONARY, self.KERNELS and self.THREADS.
|
|
727
|
+
|
|
728
|
+
Parameters
|
|
729
|
+
----------
|
|
730
|
+
ic_debias_mask : np.array
|
|
731
|
+
Binary mask to restrict the evaluation on a subset of columns of the IC compartment.
|
|
730
732
|
"""
|
|
731
733
|
if self.DICTIONARY is None :
|
|
732
734
|
logger.error( 'Dictionary not loaded; call "load_dictionary()" first' )
|
|
@@ -743,7 +745,10 @@ cdef class Evaluation :
|
|
|
743
745
|
tic = time.time()
|
|
744
746
|
logger.subinfo('')
|
|
745
747
|
logger.info( 'Building linear operator A' )
|
|
746
|
-
|
|
748
|
+
if ic_debias_mask is not None:
|
|
749
|
+
self.DICTIONARY['IC']['debias_mask'] = ic_debias_mask
|
|
750
|
+
else:
|
|
751
|
+
self.DICTIONARY['IC']['debias_mask'] = np.ones( int(self.DICTIONARY['IC']['nSTR'] * self.KERNELS['wmr'].shape[0]), dtype=np.uint32)
|
|
747
752
|
self.A = operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS, True if hasattr(self.model, 'nolut') else False )
|
|
748
753
|
logger.info( f'[ {format_time(time.time() - tic)} ]' )
|
|
749
754
|
|
|
@@ -760,9 +765,6 @@ cdef class Evaluation :
|
|
|
760
765
|
|
|
761
766
|
y = self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float64)
|
|
762
767
|
|
|
763
|
-
if self.debias_mask is not None :
|
|
764
|
-
y *= self.debias_mask
|
|
765
|
-
|
|
766
768
|
return y
|
|
767
769
|
|
|
768
770
|
def set_wLasso_ISO(self, img_weights_filename, lambda_perc_iso):
|
|
@@ -796,10 +798,10 @@ cdef class Evaluation :
|
|
|
796
798
|
if self.A is None :
|
|
797
799
|
logger.error( 'Operator not built; call "build_operator()" first' )
|
|
798
800
|
|
|
799
|
-
if self.DICTIONARY['IC']['
|
|
801
|
+
if self.DICTIONARY['IC']['nSTR'] <= 0 :
|
|
800
802
|
logger.error( 'No streamline found in the dictionary; check your data' )
|
|
801
803
|
|
|
802
|
-
if int( self.DICTIONARY['
|
|
804
|
+
if int( self.DICTIONARY['ISO']['n'] * self.KERNELS['iso'].shape[0] ) == 0 :
|
|
803
805
|
logger.error( 'Unable to set regularisation because no isotropic compartment found in the dictionary.' )
|
|
804
806
|
|
|
805
807
|
# load image and check it
|
|
@@ -827,7 +829,8 @@ cdef class Evaluation :
|
|
|
827
829
|
|
|
828
830
|
# compute array of weights from image
|
|
829
831
|
array_weights = weights_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ].flatten().astype(np.float32)
|
|
830
|
-
|
|
832
|
+
array_weights = array_weights[self.DICTIONARY['ISO']['vox']]
|
|
833
|
+
if array_weights.size != self.DICTIONARY['ISO']['n']:
|
|
831
834
|
logger.error( 'Number of voxels in the weights image does not match the number of voxels in the dictionary' )
|
|
832
835
|
if np.any(array_weights < 1):
|
|
833
836
|
logger.error('All weights must be greater or equal to 1')
|
|
@@ -910,15 +913,16 @@ cdef class Evaluation :
|
|
|
910
913
|
Available options:
|
|
911
914
|
'group_idx' - np.array(np.int32) :
|
|
912
915
|
group indices for the IC compartment (not implemented for EC and ISO).
|
|
913
|
-
|
|
916
|
+
NB: Each element of the array corresponds to a group and contains the indices of the streamlines
|
|
917
|
+
belonging to that group. All streamlines must belong to at least one group.
|
|
918
|
+
NB: This field is necessary only if regularisers[0] is 'group_lasso' or 'sparse_group_lasso'.
|
|
914
919
|
Example:
|
|
915
|
-
|
|
920
|
+
group_idx = np.array([[0,2,5],[1,3,4],[0,1,2,3,4,5],[6]], dtype=np.object_)
|
|
916
921
|
that is equivalent to
|
|
917
922
|
[0,1,2,3,4,5] [6]
|
|
918
923
|
/ \
|
|
919
924
|
[0,2,5] [1,3,4]
|
|
920
|
-
which has two non-overlapping groups, one of which is the union
|
|
921
|
-
of two other non-overlapping groups.
|
|
925
|
+
which has two non-overlapping groups, one of which is the union of two other non-overlapping groups.
|
|
922
926
|
Group weights computation (if regularisers[0] is 'group_lasso' or 'sparse_group_lasso'):
|
|
923
927
|
w[k] = ( 1 * sqrt(|g[k]|) * group_weights_extra[k] ) / ( ||x_nnls[g[k]]||_2 )
|
|
924
928
|
where:
|
|
@@ -942,7 +946,7 @@ cdef class Evaluation :
|
|
|
942
946
|
This field can be specified only if regularisers[0] is 'group_lasso' or 'sparse_group_lasso'.
|
|
943
947
|
NB: this array must have the same size as the number of groups in the IC compartment and contain only non-negative values.
|
|
944
948
|
'coeff_weights' - np.array(np.float64) :
|
|
945
|
-
weights associated to each individual element of the compartment (for the moment implemented only for IC
|
|
949
|
+
weights associated to each individual element of the compartment (for the moment implemented only for IC and ISO compartments).
|
|
946
950
|
This field can be specified only if the chosen regulariser is 'lasso' or 'sparse_group_lasso'.
|
|
947
951
|
NB: this array must have the same size as the number of elements in the compartment and contain only non-negative values.
|
|
948
952
|
|
|
@@ -1114,10 +1118,25 @@ cdef class Evaluation :
|
|
|
1114
1118
|
# check if group_idx contains all the indices of the input streamlines
|
|
1115
1119
|
if regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso':
|
|
1116
1120
|
all_idx_in = np.sort(np.unique(np.concatenate(dictIC_params['group_idx'])))
|
|
1117
|
-
all_idx = np.arange(self.DICTIONARY['
|
|
1121
|
+
all_idx = np.arange(self.DICTIONARY['TRK']['kept'].size, dtype=np.int32)
|
|
1122
|
+
if all_idx_in.size != all_idx.size:
|
|
1123
|
+
logger.error(f'Group indices must contain all the indices of the input streamlines. Got {all_idx_in.size} unique streamline indices from the groups, but {all_idx.size} expected.')
|
|
1118
1124
|
if np.any(all_idx_in != all_idx):
|
|
1119
1125
|
logger.error('Group indices must contain all the indices of the input streamlines')
|
|
1120
1126
|
|
|
1127
|
+
# check if in the provided group indices there is at least one empty group and remove it
|
|
1128
|
+
if regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso':
|
|
1129
|
+
count_empty_groups = 0
|
|
1130
|
+
list_non_empty_groups = []
|
|
1131
|
+
for g in dictIC_params['group_idx']:
|
|
1132
|
+
if g.size == 0:
|
|
1133
|
+
count_empty_groups += 1
|
|
1134
|
+
else:
|
|
1135
|
+
list_non_empty_groups.append(g)
|
|
1136
|
+
if count_empty_groups > 0:
|
|
1137
|
+
logger.warning('At least one of the provided groups is empty; removing it from the group structure')
|
|
1138
|
+
dictIC_params['group_idx'] = np.array(list_non_empty_groups, dtype=np.object_)
|
|
1139
|
+
|
|
1121
1140
|
# check if group_weights_extra is consistent with the number of groups
|
|
1122
1141
|
if (regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso') and 'group_weights_extra' in dictIC_params:
|
|
1123
1142
|
if type(dictIC_params['group_weights_extra']) not in [list, np.ndarray]:
|
|
@@ -1335,7 +1354,7 @@ cdef class Evaluation :
|
|
|
1335
1354
|
logger.info( f'[ {format_time(time.time() - tr)} ]' )
|
|
1336
1355
|
|
|
1337
1356
|
|
|
1338
|
-
def fit( self, tol_fun=1e-3, tol_x=1e-6, max_iter=100, x0=None, confidence_map_filename=None, confidence_map_rescale=False, debias=False )
|
|
1357
|
+
def fit( self, tol_fun=1e-3, tol_x=1e-6, max_iter=100, x0=None, confidence_map_filename=None, confidence_map_rescale=False, debias=False, debias_thr=0.0 ):
|
|
1339
1358
|
"""Fit the model to the data.
|
|
1340
1359
|
|
|
1341
1360
|
Parameters
|
|
@@ -1356,6 +1375,15 @@ cdef class Evaluation :
|
|
|
1356
1375
|
If true, the values of the confidence map will be rescaled to the
|
|
1357
1376
|
range [0.0,1.0]. Only the voxels considered in the mask will be affected.
|
|
1358
1377
|
(default : False)
|
|
1378
|
+
debias : boolean
|
|
1379
|
+
If true, a debiasing step will be performed after the main fitting
|
|
1380
|
+
procedure. Highly suggested when using a regularisation. (default : False)
|
|
1381
|
+
debias_thr : float
|
|
1382
|
+
Threshold used to select the coefficients to be debiased.
|
|
1383
|
+
A second fit (without regularisation) will be performed on the reduced
|
|
1384
|
+
problem defined by as a subset of the original linear operator. This is obtained
|
|
1385
|
+
by selecting only the columns corresponding to estimated coefficients greater
|
|
1386
|
+
than debias_thr in the main fitting procedure. (default : 0.0)
|
|
1359
1387
|
"""
|
|
1360
1388
|
if self.niiDWI is None :
|
|
1361
1389
|
logger.error( 'Data not loaded; call "load_data()" first' )
|
|
@@ -1365,9 +1393,11 @@ cdef class Evaluation :
|
|
|
1365
1393
|
logger.error( 'Response functions not generated; call "generate_kernels()" and "load_kernels()" first' )
|
|
1366
1394
|
if self.THREADS is None :
|
|
1367
1395
|
logger.error( 'Threads not set; call "set_threads()" first' )
|
|
1368
|
-
if self.A is None :
|
|
1369
|
-
logger.error( 'Operator not built; call "build_operator()" first' )
|
|
1370
1396
|
|
|
1397
|
+
# Build operator
|
|
1398
|
+
self.build_operator()
|
|
1399
|
+
|
|
1400
|
+
# Set default regularisation parameters if not set by the user
|
|
1371
1401
|
if self.regularisation_params is None:
|
|
1372
1402
|
self.set_regularisation()
|
|
1373
1403
|
|
|
@@ -1458,39 +1488,31 @@ cdef class Evaluation :
|
|
|
1458
1488
|
logger.subinfo(f'Stopped after {opt_details["iterations"]} iterations', indent_lvl=1, indent_char='*', with_progress=True)
|
|
1459
1489
|
logger.subinfo(f'Stopping condition: \"{opt_details["stopping_criterion"]}\"', indent_lvl=1, indent_char='*')
|
|
1460
1490
|
|
|
1491
|
+
# DEBIAS
|
|
1461
1492
|
if (self.regularisation_params['regIC']!=None or self.regularisation_params['regEC']!= None or self.regularisation_params['regISO']!= None) and debias:
|
|
1462
|
-
from commit.operator import operator
|
|
1463
1493
|
temp_verb = self.verbose
|
|
1464
|
-
logger.
|
|
1494
|
+
logger.subinfo('')
|
|
1495
|
+
logger.info( f'Running debias' )
|
|
1496
|
+
logger.subinfo( f'Keeping columns in the IC compartment whose corresponding coefficient is greater than {debias_thr}', indent_lvl=1, indent_char='*' )
|
|
1465
1497
|
self.set_verbose(0)
|
|
1466
1498
|
|
|
1467
1499
|
offset = self.DICTIONARY['IC']['nSTR'] * self.KERNELS['wmr'].shape[0]
|
|
1468
1500
|
xic = self.x[:offset]
|
|
1469
1501
|
mask = np.ones(offset, dtype=np.uint32)
|
|
1470
|
-
mask[xic
|
|
1471
|
-
|
|
1472
|
-
self.DICTIONARY["IC"]["eval"] = mask
|
|
1473
|
-
|
|
1474
|
-
self.A = operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS, nolut=True if hasattr(self.model, 'nolut') else False )
|
|
1502
|
+
mask[xic<=debias_thr] = 0
|
|
1475
1503
|
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
y_mask[y_mask>0] = 1
|
|
1489
|
-
|
|
1490
|
-
self.debias_mask = y_mask
|
|
1491
|
-
|
|
1492
|
-
with ProgressBar(disable=self.verbose!=3, hide_on_exit=True, subinfo=True) as pbar:
|
|
1493
|
-
self.x, opt_details = commit.solvers.solve(self.get_y(), self.A, self.A.T, tol_fun=tol_fun, tol_x=tol_x, max_iter=max_iter, verbose=self.verbose, x0=x0, regularisation=self.regularisation_params, confidence_array=confidence_array)
|
|
1504
|
+
if np.sum(mask)==0:
|
|
1505
|
+
self.set_verbose(temp_verb)
|
|
1506
|
+
logger.warning('All coefficients of the IC compartment are below the debias threshold. The debias step will not be performed. Note: consider softening the regularisation by decreasing the lambda value(s).')
|
|
1507
|
+
else:
|
|
1508
|
+
# update the operator with the new mask for the IC compartment
|
|
1509
|
+
self.build_operator(ic_debias_mask=mask)
|
|
1510
|
+
# run fit on the debiased problem
|
|
1511
|
+
self.set_regularisation()
|
|
1512
|
+
self.set_verbose(temp_verb)
|
|
1513
|
+
logger.subinfo('Recomputing coefficients', indent_lvl=1, indent_char='*', with_progress=True)
|
|
1514
|
+
with ProgressBar(disable=self.verbose!=3, hide_on_exit=True, subinfo=True) as pbar:
|
|
1515
|
+
self.x, opt_details = commit.solvers.solve(self.get_y(), self.A, self.A.T, tol_fun=tol_fun, tol_x=tol_x, max_iter=max_iter, verbose=self.verbose, x0=x0, regularisation=self.regularisation_params, confidence_array=confidence_array)
|
|
1494
1516
|
|
|
1495
1517
|
elif (self.regularisation_params['regIC']!=None or self.regularisation_params['regEC']!= None or self.regularisation_params['regISO']!= None) and not debias:
|
|
1496
1518
|
logger.warning('Fitting with regularisation but without debiasing. The coefficients will be biased, use "debias=True" to debias the coefficients')
|
|
@@ -1606,64 +1628,26 @@ cdef class Evaluation :
|
|
|
1606
1628
|
niiMAP_hdr['descrip'] = f'Created with COMMIT {self.get_config("version")}'
|
|
1607
1629
|
niiMAP_hdr['db_name'] = ''
|
|
1608
1630
|
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
niiMAP_img[self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz']] = tmp
|
|
1631
|
-
niiMAP_hdr['cal_min'] = 0
|
|
1632
|
-
niiMAP_hdr['cal_max'] = tmp.max()
|
|
1633
|
-
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_RMSE.nii.gz') )
|
|
1634
|
-
|
|
1635
|
-
tmp = np.sum(y_mea**2,axis=1)
|
|
1636
|
-
idx = np.where( tmp < 1E-12 )
|
|
1637
|
-
tmp[ idx ] = 1
|
|
1638
|
-
tmp = np.sqrt( np.sum((y_mea-y_est)**2,axis=1) / tmp )
|
|
1639
|
-
tmp[ idx ] = 0
|
|
1640
|
-
|
|
1641
|
-
niiMAP_img[self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz']] = tmp
|
|
1642
|
-
niiMAP_hdr['cal_min'] = 0
|
|
1643
|
-
niiMAP_hdr['cal_max'] = 1
|
|
1644
|
-
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_NRMSE.nii.gz') )
|
|
1645
|
-
|
|
1646
|
-
else:
|
|
1647
|
-
nVOX = self.DICTIONARY['IC']['nVOX']
|
|
1648
|
-
y_mea = np.reshape( self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float32), (nVOX,-1) )
|
|
1649
|
-
y_est = np.reshape( self.A.dot(self.x), (nVOX,-1) ).astype(np.float32)
|
|
1650
|
-
tmp = np.sqrt( np.mean((y_mea-y_est)**2,axis=1) )
|
|
1651
|
-
logger.subinfo(f'RMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
1652
|
-
niiMAP_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = tmp
|
|
1653
|
-
niiMAP_hdr['cal_min'] = 0
|
|
1654
|
-
niiMAP_hdr['cal_max'] = tmp.max()
|
|
1655
|
-
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_RMSE.nii.gz') )
|
|
1656
|
-
|
|
1657
|
-
tmp = np.sum(y_mea**2,axis=1)
|
|
1658
|
-
idx = np.where( tmp < 1E-12 )
|
|
1659
|
-
tmp[ idx ] = 1
|
|
1660
|
-
tmp = np.sqrt( np.sum((y_mea-y_est)**2,axis=1) / tmp )
|
|
1661
|
-
tmp[ idx ] = 0
|
|
1662
|
-
logger.subinfo(f'NRMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
1663
|
-
niiMAP_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = tmp
|
|
1664
|
-
niiMAP_hdr['cal_min'] = 0
|
|
1665
|
-
niiMAP_hdr['cal_max'] = 1
|
|
1666
|
-
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_NRMSE.nii.gz') )
|
|
1631
|
+
nVOX = self.DICTIONARY['IC']['nVOX']
|
|
1632
|
+
y_mea = np.reshape( self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float32), (nVOX,-1) )
|
|
1633
|
+
y_est = np.reshape( self.A.dot(self.x), (nVOX,-1) ).astype(np.float32)
|
|
1634
|
+
tmp = np.sqrt( np.mean((y_mea-y_est)**2,axis=1) )
|
|
1635
|
+
logger.subinfo(f'RMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
1636
|
+
niiMAP_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = tmp
|
|
1637
|
+
niiMAP_hdr['cal_min'] = 0
|
|
1638
|
+
niiMAP_hdr['cal_max'] = tmp.max()
|
|
1639
|
+
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_RMSE.nii.gz') )
|
|
1640
|
+
|
|
1641
|
+
tmp = np.sum(y_mea**2,axis=1)
|
|
1642
|
+
idx = np.where( tmp < 1E-12 )
|
|
1643
|
+
tmp[ idx ] = 1
|
|
1644
|
+
tmp = np.sqrt( np.sum((y_mea-y_est)**2,axis=1) / tmp )
|
|
1645
|
+
tmp[ idx ] = 0
|
|
1646
|
+
logger.subinfo(f'NRMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
1647
|
+
niiMAP_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = tmp
|
|
1648
|
+
niiMAP_hdr['cal_min'] = 0
|
|
1649
|
+
niiMAP_hdr['cal_max'] = 1
|
|
1650
|
+
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_NRMSE.nii.gz') )
|
|
1667
1651
|
|
|
1668
1652
|
if self.confidence_map_img is not None:
|
|
1669
1653
|
confidence_array = np.reshape( self.confidence_map_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float32), (nVOX,-1) )
|
|
@@ -21,7 +21,7 @@ cdef class LinearOperator :
|
|
|
21
21
|
unsigned int [::1] ICv
|
|
22
22
|
unsigned int [::1] ECv
|
|
23
23
|
unsigned int [::1] ISOv
|
|
24
|
-
unsigned int [::1]
|
|
24
|
+
unsigned int [::1] ICm # debias mask for IC columns
|
|
25
25
|
float [::1] ICl
|
|
26
26
|
float [:, :, ::1] LUT_IC
|
|
27
27
|
float [:, :, ::1] LUT_EC
|
|
@@ -74,7 +74,7 @@ cdef class LinearOperator :
|
|
|
74
74
|
self.ICl = DICTIONARY['IC']['len']
|
|
75
75
|
self.ICv = DICTIONARY['IC']['vox']
|
|
76
76
|
self.ICo = DICTIONARY['IC']['dir']
|
|
77
|
-
self.
|
|
77
|
+
self.ICm = DICTIONARY['IC']['debias_mask']
|
|
78
78
|
self.ECv = DICTIONARY['EC']['vox']
|
|
79
79
|
self.ECo = DICTIONARY['EC']['dir']
|
|
80
80
|
self.ISOv = DICTIONARY['ISO']['vox']
|
|
@@ -140,7 +140,7 @@ cdef class LinearOperator :
|
|
|
140
140
|
COMMIT_A_nolut(
|
|
141
141
|
&v_in[0], &v_out[0],
|
|
142
142
|
self.ICnSTR,
|
|
143
|
-
&self.ICf[0], &self.
|
|
143
|
+
&self.ICf[0], &self.ICm[0], &self.ICv[0], &self.ICl[0],
|
|
144
144
|
&self.ISOv[0],
|
|
145
145
|
&self.ICthreads[0], &self.ISOthreads[0],
|
|
146
146
|
self.ISOnRF, self.nThreads
|
|
@@ -150,7 +150,7 @@ cdef class LinearOperator :
|
|
|
150
150
|
&v_in[0], &v_out[0],
|
|
151
151
|
self.nSAMPLES, self.ndirs,
|
|
152
152
|
self.ICnSTR, self.ECn, self.ISOn,
|
|
153
|
-
&self.ICf[0], &self.
|
|
153
|
+
&self.ICf[0], &self.ICm[0], &self.ICv[0], &self.ICo[0], &self.ICl[0],
|
|
154
154
|
&self.ECv[0], &self.ECo[0],
|
|
155
155
|
&self.ISOv[0],
|
|
156
156
|
&self.LUT_IC[0,0,0], &self.LUT_EC[0,0,0], &self.LUT_ISO[0,0],
|
|
@@ -163,7 +163,7 @@ cdef class LinearOperator :
|
|
|
163
163
|
COMMIT_At_nolut(
|
|
164
164
|
&v_in[0], &v_out[0],
|
|
165
165
|
self.ICnSTR, self.ICn,
|
|
166
|
-
&self.ICf[0], &self.
|
|
166
|
+
&self.ICf[0], &self.ICm[0], &self.ICv[0], &self.ICl[0],
|
|
167
167
|
&self.ISOv[0],
|
|
168
168
|
&self.ICthreadsT[0], &self.ISOthreadsT[0],
|
|
169
169
|
self.ISOnRF, self.nThreads
|
|
@@ -173,7 +173,7 @@ cdef class LinearOperator :
|
|
|
173
173
|
&v_in[0], &v_out[0],
|
|
174
174
|
self.nSAMPLES, self.ndirs,
|
|
175
175
|
self.ICnSTR, self.ICn, self.ECn, self.ISOn,
|
|
176
|
-
&self.ICf[0], &self.
|
|
176
|
+
&self.ICf[0], &self.ICm[0], &self.ICv[0], &self.ICo[0], &self.ICl[0],
|
|
177
177
|
&self.ECv[0], &self.ECo[0],
|
|
178
178
|
&self.ISOv[0],
|
|
179
179
|
&self.LUT_IC[0,0,0], &self.LUT_EC[0,0,0], &self.LUT_ISO[0,0],
|