dmri-commit 2.0.0__tar.gz → 2.1.0__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.
Files changed (32) hide show
  1. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/LICENSE +1 -1
  2. {dmri-commit-2.0.0/build/dmri_commit.egg-info → dmri-commit-2.1.0}/PKG-INFO +4 -4
  3. {dmri-commit-2.0.0 → dmri-commit-2.1.0/build/dmri_commit.egg-info}/PKG-INFO +4 -4
  4. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/build/dmri_commit.egg-info/requires.txt +2 -2
  5. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/core.pyx +267 -50
  6. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/info.py +2 -2
  7. dmri-commit-2.1.0/commit/models.py +98 -0
  8. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/operator/operator.pyx +1 -0
  9. dmri-commit-2.1.0/commit/proximals.pyx +198 -0
  10. dmri-commit-2.1.0/commit/solvers.py +364 -0
  11. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/trk2dictionary/trk2dictionary.pyx +38 -14
  12. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/trk2dictionary/trk2dictionary_c.cpp +87 -10
  13. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/setup.cfg +3 -3
  14. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/setup.py +7 -1
  15. dmri-commit-2.0.0/commit/models.py +0 -32
  16. dmri-commit-2.0.0/commit/proximals.pyx +0 -141
  17. dmri-commit-2.0.0/commit/solvers.py +0 -443
  18. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/MANIFEST.in +0 -0
  19. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/README.md +0 -0
  20. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/build/dmri_commit.egg-info/SOURCES.txt +0 -0
  21. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/build/dmri_commit.egg-info/dependency_links.txt +0 -0
  22. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/build/dmri_commit.egg-info/top_level.txt +0 -0
  23. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/__init__.py +0 -0
  24. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/core.cpp +0 -0
  25. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/operator/__init__.py +0 -0
  26. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/operator/config.py +0 -0
  27. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/operator/operator.pyxbld +0 -0
  28. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/operator/operator_noLUT.c +0 -0
  29. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/operator/operator_withLUT.c +0 -0
  30. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/trk2dictionary/ProgressBar.h +0 -0
  31. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/trk2dictionary/Vector.h +0 -0
  32. {dmri-commit-2.0.0 → dmri-commit-2.1.0}/commit/trk2dictionary/trk2dictionary.cpp +0 -0
@@ -1,6 +1,6 @@
1
1
  ################################################################################
2
2
  COMMIT software license agreement
3
- Version 2.0.0, 24 July 2023
3
+ Version 2, 24 July 2023
4
4
  ################################################################################
5
5
 
6
6
  ------------------------------------PREAMBLE------------------------------------
@@ -1,19 +1,19 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dmri-commit
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Convex Optimization Modeling for Microstructure Informed Tractography (COMMIT)
5
5
  Home-page: https://github.com/daducci/COMMIT
6
6
  Author: Alessandro Daducci
7
7
  Author-email: alessandro.daducci@univr.it
8
- License: BSD license
8
+ License: Proprietary license
9
9
  License-File: LICENSE
10
10
  Requires-Dist: setuptools>=46.1
11
11
  Requires-Dist: Cython>=0.29
12
12
  Requires-Dist: numpy>=1.12
13
13
  Requires-Dist: scipy>=1.0
14
14
  Requires-Dist: dipy>=1.0
15
- Requires-Dist: dmri-dicelib>=1.0.0
16
- Requires-Dist: dmri-amico>=2.0.0
15
+ Requires-Dist: dmri-dicelib>=1.0.3
16
+ Requires-Dist: dmri-amico>=2.0.1
17
17
 
18
18
 
19
19
  ========
@@ -1,19 +1,19 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dmri-commit
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Convex Optimization Modeling for Microstructure Informed Tractography (COMMIT)
5
5
  Home-page: https://github.com/daducci/COMMIT
6
6
  Author: Alessandro Daducci
7
7
  Author-email: alessandro.daducci@univr.it
8
- License: BSD license
8
+ License: Proprietary license
9
9
  License-File: LICENSE
10
10
  Requires-Dist: setuptools>=46.1
11
11
  Requires-Dist: Cython>=0.29
12
12
  Requires-Dist: numpy>=1.12
13
13
  Requires-Dist: scipy>=1.0
14
14
  Requires-Dist: dipy>=1.0
15
- Requires-Dist: dmri-dicelib>=1.0.0
16
- Requires-Dist: dmri-amico>=2.0.0
15
+ Requires-Dist: dmri-dicelib>=1.0.3
16
+ Requires-Dist: dmri-amico>=2.0.1
17
17
 
18
18
 
19
19
  ========
@@ -3,5 +3,5 @@ Cython>=0.29
3
3
  numpy>=1.12
4
4
  scipy>=1.0
5
5
  dipy>=1.0
6
- dmri-dicelib>=1.0.0
7
- dmri-amico>=2.0.0
6
+ dmri-dicelib>=1.0.3
7
+ dmri-amico>=2.0.1
@@ -1,6 +1,5 @@
1
1
  #!python
2
2
  #cython: language_level=3, boundscheck=False, wraparound=False, nonecheck=False, cdivision=True, initializedcheck=False, binding=False
3
- from __future__ import print_function
4
3
  cimport cython
5
4
  import numpy as np
6
5
  cimport numpy as np
@@ -16,6 +15,7 @@ import commit.models
16
15
  import commit.solvers
17
16
  import amico.scheme
18
17
  import amico.lut
18
+ from importlib import reload, invalidate_caches
19
19
  import pyximport
20
20
  from pkg_resources import get_distribution
21
21
 
@@ -67,8 +67,10 @@ cdef class Evaluation :
67
67
  cdef public DICTIONARY
68
68
  cdef public THREADS
69
69
  cdef public A
70
+ cdef public regularisation_params
70
71
  cdef public x
71
72
  cdef public CONFIG
73
+ cdef public temp_data
72
74
  cdef public confidence_map_img
73
75
 
74
76
  def __init__( self, study_path='.', subject='.' ) :
@@ -81,18 +83,20 @@ cdef class Evaluation :
81
83
  subject : string
82
84
  The path (relative to previous folder) to the subject folder (default : '.')
83
85
  """
84
- self.niiDWI = None # set by "load_data" method
85
- self.scheme = None # set by "load_data" method
86
- self.model = None # set by "set_model" method
87
- self.KERNELS = None # set by "load_kernels" method
88
- self.DICTIONARY = None # set by "load_dictionary" method
89
- self.THREADS = None # set by "set_threads" method
90
- self.A = None # set by "build_operator" method
91
- self.x = None # set by "fit" method
92
- self.confidence_map_img = None # set by "fit" method
86
+ self.niiDWI = None # set by "load_data" method
87
+ self.scheme = None # set by "load_data" method
88
+ self.model = None # set by "set_model" method
89
+ self.KERNELS = None # set by "load_kernels" method
90
+ self.DICTIONARY = None # set by "load_dictionary" method
91
+ self.THREADS = None # set by "set_threads" method
92
+ self.A = None # set by "build_operator" method
93
+ self.regularisation_params = None # set by "set_regularisation" method
94
+ self.x = None # set by "fit" method
95
+ self.confidence_map_img = None # set by "fit" method
93
96
 
94
97
  # store all the parameters of an evaluation with COMMIT
95
98
  self.CONFIG = {}
99
+ self.temp_data = {}
96
100
  self.set_config('version', get_distribution('dmri-commit').version)
97
101
  self.set_config('study_path', study_path)
98
102
  self.set_config('subject', subject)
@@ -107,13 +111,18 @@ cdef class Evaluation :
107
111
 
108
112
  def set_config( self, key, value ) :
109
113
  self.CONFIG[ key ] = value
114
+ self.temp_data[ key ] = value
110
115
 
111
116
 
112
117
  def get_config( self, key ) :
113
118
  return self.CONFIG.get( key )
114
119
 
115
120
 
116
- def load_data( self, dwi_filename, scheme_filename, b0_thr=0, b0_min_signal=0, replace_bad_voxels=None ) :
121
+ def get_temp_data( self, key ) :
122
+ return self.temp_data.get( key )
123
+
124
+
125
+ def load_data( self, dwi_filename, scheme_filename=None, b0_thr=0, b0_min_signal=0, replace_bad_voxels=None ) :
117
126
  """Load the diffusion signal and its corresponding acquisition scheme.
118
127
 
119
128
  Parameters
@@ -170,7 +179,7 @@ cdef class Evaluation :
170
179
  ERROR( 'Scheme does not match with input data' )
171
180
  if self.scheme.dwi_count == 0 :
172
181
  ERROR( 'There are no DWI volumes in the data' )
173
-
182
+
174
183
  # Check for Nan or Inf values in raw data
175
184
  if np.isnan(self.niiDWI_img).any() or np.isinf(self.niiDWI_img).any():
176
185
  if replace_bad_voxels is not None:
@@ -240,7 +249,7 @@ cdef class Evaluation :
240
249
  """
241
250
  # Call the specific model constructor
242
251
  if hasattr(commit.models, model_name ) :
243
- self.model = getattr(commit.models,model_name)()
252
+ self.model = getattr(commit.models, model_name)()
244
253
  else :
245
254
  ERROR( 'Model "%s" not recognized' % model_name )
246
255
 
@@ -271,7 +280,11 @@ cdef class Evaluation :
271
280
  if self.model.id=='VolumeFractions' and ndirs!=1:
272
281
  ndirs = 1
273
282
  print( '\t* Forcing "ndirs" to 1 because model is isotropic' )
274
-
283
+ if 'commitwipmodels' in sys.modules :
284
+ if self.model.restrictedISO is not None and ndirs!=1:
285
+ ndirs = 1
286
+ print( '\t* Forcing "ndirs" to 1 because model is isotropic' )
287
+
275
288
  # store some values for later use
276
289
  self.set_config('lmax', lmax)
277
290
  self.set_config('ndirs', ndirs)
@@ -482,21 +495,20 @@ cdef class Evaluation :
482
495
 
483
496
  self.DICTIONARY['ISO'] = {}
484
497
 
485
- self.DICTIONARY['nV'] = self.DICTIONARY['MASK'].sum()
498
+ self.DICTIONARY['ISO']['v'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_ISO_v.dict'), dtype=np.uint32 )
499
+ if self.DICTIONARY['ISO']['v'].size > 0:
500
+ self.DICTIONARY['ISO']['nV'] = self.DICTIONARY['ISO']['v'].size
501
+ else:
502
+ self.DICTIONARY['ISO']['nV'] = self.DICTIONARY['MASK'].sum()
486
503
 
487
- vx, vy, vz = ( self.DICTIONARY['MASK'] > 0 ).nonzero() # [TODO] find a way to avoid using int64 (not necessary and waste of memory)
488
- vx = vx.astype(np.int32)
489
- vy = vy.astype(np.int32)
490
- vz = vz.astype(np.int32)
491
- self.DICTIONARY['ISO']['v'] = vx + self.get_config('dim')[0] * ( vy + self.get_config('dim')[1] * vz )
492
- del vx, vy, vz
504
+ self.DICTIONARY['nV'] = self.DICTIONARY['MASK'].sum()
493
505
 
494
506
  # reorder the segments based on the "v" field
495
507
  idx = np.argsort( self.DICTIONARY['ISO']['v'], kind='mergesort' )
496
508
  self.DICTIONARY['ISO']['v'] = self.DICTIONARY['ISO']['v'][ idx ]
497
509
  del idx
498
510
 
499
- print( '[ %d voxels ]' % self.DICTIONARY['nV'] )
511
+ print( '[ %d voxels ]' % self.DICTIONARY['ISO']['nV'] )
500
512
 
501
513
  # post-processing
502
514
  # ---------------
@@ -591,10 +603,24 @@ cdef class Evaluation :
591
603
  self.THREADS['EC'] = None
592
604
 
593
605
  if self.DICTIONARY['nV'] > 0 :
594
- self.THREADS['ISO'] = np.zeros( n+1, dtype=np.uint32 )
595
- for i in xrange(n) :
596
- self.THREADS['ISO'][i] = np.searchsorted( self.DICTIONARY['ISO']['v'], self.DICTIONARY['IC']['v'][ self.THREADS['IC'][i] ] )
597
- self.THREADS['ISO'][n] = self.DICTIONARY['nV']
606
+ if self.DICTIONARY['ISO']['nV'] > 0 :
607
+ self.THREADS['ISO'] = np.zeros( n+1, dtype=np.uint32 )
608
+ N = np.floor( self.DICTIONARY['ISO']['nV']/n )
609
+ t = 1
610
+ tot = 0
611
+ C = np.bincount( self.DICTIONARY['ISO']['v'] )
612
+ for c in C :
613
+ tot += c
614
+ if tot >= N and t <= n :
615
+ self.THREADS['ISO'][t] = self.THREADS['ISO'][t-1] + tot
616
+ t += 1
617
+ tot = 0
618
+ self.THREADS['ISO'][n] = self.DICTIONARY['ISO']['nV']
619
+ else:
620
+ self.THREADS['ISO'] = np.zeros( n+1, dtype=np.uint32 )
621
+ for i in xrange(n) :
622
+ self.THREADS['ISO'][i] = np.searchsorted( self.DICTIONARY['ISO']['v'], self.DICTIONARY['IC']['v'][ self.THREADS['IC'][i] ] )
623
+ self.THREADS['ISO'][n] = self.DICTIONARY['ISO']['nV']
598
624
 
599
625
  # check if some threads are not assigned any segment
600
626
  if np.count_nonzero( np.diff( self.THREADS['ISO'].astype(np.int32) ) <= 0 ) :
@@ -647,10 +673,11 @@ cdef class Evaluation :
647
673
 
648
674
  if self.DICTIONARY['nV'] > 0 :
649
675
  self.THREADS['ISOt'] = np.zeros( n+1, dtype=np.uint32 )
650
- N = np.floor( self.DICTIONARY['nV']/n )
676
+ N = np.floor( self.DICTIONARY['ISO']['nV']/n )
677
+
651
678
  for i in xrange(1,n) :
652
679
  self.THREADS['ISOt'][i] = self.THREADS['ISOt'][i-1] + N
653
- self.THREADS['ISOt'][n] = self.DICTIONARY['nV']
680
+ self.THREADS['ISOt'][n] = self.DICTIONARY['ISO']['nV']
654
681
 
655
682
  # check if some threads are not assigned any segment
656
683
  if np.count_nonzero( np.diff( self.THREADS['ISOt'].astype(np.int32) ) <= 0 ) :
@@ -728,14 +755,14 @@ cdef class Evaluation :
728
755
  config.nISO = self.KERNELS['iso'].shape[0]
729
756
  config.build_dir = build_dir
730
757
 
758
+ sys.dont_write_bytecode = True
731
759
  pyximport.install( reload_support=True, language_level=3, build_dir=build_dir, build_in_temp=True, inplace=False )
732
760
 
733
- if not 'commit.operator.operator' in sys.modules :
734
- import commit.operator.operator
735
- else :
736
- reload( sys.modules['commit.operator.operator'] )
761
+ if 'commit.operator.operator' in sys.modules :
762
+ del sys.modules['commit.operator.operator']
763
+ import commit.operator.operator
737
764
 
738
- self.A = sys.modules['commit.operator.operator'].LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS )
765
+ self.A = commit.operator.operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS )
739
766
 
740
767
  LOG( ' [ %.1f seconds ]' % ( time.time() - tic ) )
741
768
 
@@ -751,11 +778,182 @@ cdef class Evaluation :
751
778
  ERROR( 'Data not loaded; call "load_data()" first' )
752
779
 
753
780
  y = self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float64)
754
- y[y < 0] = 0
781
+ # y[y < 0] = 0
755
782
  return y
756
783
 
784
+ def set_regularisation(self, regularisers=(None, None, None), lambdas=(None, None, None), is_nonnegative=(True, True, True), params=(None, None, None)):
785
+ """
786
+ Set the regularisation parameters for the optimisation problem.
787
+ Input
788
+ -----
789
+ regularisers - tuple :
790
+ sets the penalty term to be used for each compartment:
791
+ regularisers[0] corresponds to the Intracellular compartment
792
+ regularisers[1] corresponds to the Extracellular compartment
793
+ regularisers[2] corresponds to the Isotropic compartment
794
+ Each regularisers[k] must be one of: {None, 'lasso', weighted_lasso, 'group_lasso'}:
795
+ 'lasso' penalises with the 1-norm of the coefficients
796
+ corresponding to the compartment.
797
+ 'group_lasso' penalises according to the following formulation (see [1]):
798
+ $\Omega(x) = \lambda \sum_{g\in G} w_g |x_g|
799
+ Considers both the non-overlapping and the hierarchical formulations.
800
+ NB: this option is allowed only in the IC compartment.
801
+ Default = (None, None, None).
802
+
803
+ lambdas - tuple :
804
+ regularisation parameter for each compartment.
805
+ The lambdas correspond to the ones described in the mathematical
806
+ formulation of the regularisation term
807
+ $\Omega(x) = lambdas[0]*regnorm[0](x) + lambdas[1]*regnorm[1](x) + lambdas[2]*regnorm[2](x)$
808
+ Default = (0.0, 0.0, 0.0, 0.0).
809
+
810
+ is_nonnegative - tuple :
811
+ impose a non negativity constraint for each compartment:
812
+ is_nonnegative[0] corresponds to the Intracellular compartment
813
+ is_nonnegative[1] corresponds to the Extracellular compartment
814
+ is_nonnegative[2] corresponds to the Isotropic compartment
815
+ Default = (True, True, True).
816
+
817
+ structureIC - np.array(list(list), dtype=np.object_) :
818
+ group structure for the IC compartment.
819
+ This field is necessary only if regterm[0]='group_lasso'.
820
+ Example:
821
+ structureIC = np.array([[0,2,5],[1,3,4],[0,1,2,3,4,5],[6]], dtype=np.object_)
822
+
823
+ that is equivalent to
824
+ [0,1,2,3,4,5] [6]
825
+ / \
826
+ [0,2,5] [1,3,4]
827
+ which has two non overlapping groups, one of which is the union
828
+ of two other non-overlapping groups.
829
+
830
+ weightsIC - np.array(np.float64) :
831
+ this defines the weights associated to each element of structure IC.
832
+
833
+ weightsIC_group - np.array(np.float64) :
834
+ this defines the weights associated to each group of structure IC.
835
+
836
+ """
837
+
838
+ regularisation = {}
839
+
840
+ regularisation['startIC'] = 0
841
+ regularisation['sizeIC'] = int( self.DICTIONARY['IC']['nF'] * self.KERNELS['wmr'].shape[0])
842
+ regularisation['startEC'] = int( regularisation['sizeIC'] )
843
+ regularisation['sizeEC'] = int( self.DICTIONARY['EC']['nE'] * self.KERNELS['wmh'].shape[0])
844
+ regularisation['startISO'] = int( regularisation['sizeIC'] + regularisation['sizeEC'] )
845
+ regularisation['sizeISO'] = int( self.DICTIONARY['nV'] * self.KERNELS['iso'].shape[0])
846
+
847
+ regularisation['regIC'] = regularisers[0]
848
+ regularisation['regEC'] = regularisers[1]
849
+ regularisation['regISO'] = regularisers[2]
850
+
851
+ regularisation['nnIC'] = is_nonnegative[0]
852
+ regularisation['nnEC'] = is_nonnegative[1]
853
+ regularisation['nnISO'] = is_nonnegative[2]
854
+
855
+ regularisation['paramsIC'] = params[0]
856
+ regularisation['paramsEC'] = params[1]
857
+ regularisation['paramsISO'] = params[2]
757
858
 
758
- def fit( self, tol_fun=1e-3, tol_x=1e-6, max_iter=100, verbose=True, x0=None, regularisation=None, confidence_map_filename=None, confidence_map_rescale=False ) :
859
+ regularisation['dictIC_params'] = params[0]
860
+ regularisation['dictEC_params'] = params[1]
861
+ regularisation['dictISO_params'] = params[2]
862
+
863
+ # unpack parameters inside params as three separate dictionaries
864
+ dictIC_params, dictEC_params, dictISO_params = params
865
+
866
+ if regularisation['regIC'] == 'lasso':
867
+ if lambdas[0] is None:
868
+ raise ValueError('Missing regularisation parameter for the IC compartment')
869
+ else:
870
+ regularisation['lambdaIC'] = lambdas[0]
871
+ elif regularisation['regEC'] == 'lasso':
872
+ if lambdas[1] is None:
873
+ raise ValueError('Missing regularisation parameter for the EC compartment')
874
+ else:
875
+ regularisation['lambdaEC'] = lambdas[1]
876
+ elif regularisation['regISO'] == 'lasso':
877
+ if lambdas[2] is None:
878
+ raise ValueError('Missing regularisation parameter for the ISO compartment')
879
+ else:
880
+ regularisation['lambdaISO'] = lambdas[2]
881
+
882
+ elif regularisation['regIC'] == 'smoothness':
883
+ if lambdas[0] is None:
884
+ raise ValueError('Missing regularisation parameter for the IC compartment')
885
+ else:
886
+ regularisation['lambdaIC'] = lambdas[0]
887
+ elif regularisation['regEC'] == 'smoothness':
888
+ raise ValueError('Not yet implemented')
889
+ elif regularisation['regISO'] == 'smoothness':
890
+ raise ValueError('Not yet implemented')
891
+
892
+ elif regularisation['regIC'] == 'group_lasso':
893
+ if lambdas[0] is None:
894
+ raise ValueError('Group structure for the IC compartment not provided')
895
+ else:
896
+ regularisation['lambdaIC'] = lambdas[0]
897
+ if lambdas[1] is not None:
898
+ raise ValueError('Not yet implemented')
899
+ if lambdas[2] is not None:
900
+ raise ValueError('Not yet implemented')
901
+ if dictIC_params["group_idx"] is None:
902
+ raise ValueError('Group structure for the IC compartment not provided')
903
+ if dictIC_params["group_weights"] is None:
904
+ raise ValueError('Group weights for the IC compartment not provided')
905
+ elif regularisation['regEC'] == 'group_lasso':
906
+ raise ValueError('Not yet implemented')
907
+ elif regularisation['regISO'] == 'group_lasso':
908
+ raise ValueError('Not yet implemented')
909
+
910
+ elif regularisation['regIC'] == 'sparse_group_lasso':
911
+ if len(lambdas[0]) != 2:
912
+ raise ValueError('Group structure for the IC compartment not provided')
913
+ else:
914
+ regularisation['lambdaIC'] = lambdas[0]
915
+ if lambdas[1] is not None:
916
+ raise ValueError('Not yet implemented')
917
+ if lambdas[2] is not None:
918
+ raise ValueError('Not yet implemented')
919
+ if dictIC_params["group_idx"] is None:
920
+ raise ValueError('Group structure for the IC compartment not provided')
921
+ if dictIC_params["group_weights"] is None:
922
+ raise ValueError('Group weights for the IC compartment not provided')
923
+ elif regularisation['regEC'] == 'sparse_group_lasso':
924
+ raise ValueError('Not yet implemented')
925
+ elif regularisation['regISO'] == 'sparse_group_lasso':
926
+ raise ValueError('Not yet implemented')
927
+
928
+ # Check if group indices need to be updated in case of 'group_lasso' or 'sparse_group_lasso'
929
+ if regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso' and (0 in self.DICTIONARY['TRK']['kept']) :
930
+ dictionary_TRK_kept = self.DICTIONARY['TRK']['kept']
931
+ weightsIC_group = dictIC_params["group_weights"]
932
+ idx_in_kept = np.zeros(dictionary_TRK_kept.size, dtype=np.int32) - 1 # -1 is used to flag indices for removal
933
+ idx_in_kept[dictionary_TRK_kept==1] = list(range(self.DICTIONARY['IC']['nF']))
934
+
935
+ newICgroup_idx = []
936
+ newweightsIC_group = []
937
+ ICgroup_idx = dictIC_params["group_idx"]
938
+ for count, group in enumerate(ICgroup_idx):
939
+ group = idx_in_kept[group]
940
+ idx_to_delete = np.where(group==-1)[0]
941
+ if idx_to_delete.size>0:
942
+ group = np.delete(group,idx_to_delete)
943
+ if(group.size>0):
944
+ newICgroup_idx.append(group)
945
+ newweightsIC_group.append(weightsIC_group[count])
946
+ else:
947
+ newICgroup_idx.append(group)
948
+ newweightsIC_group.append(weightsIC_group[count])
949
+
950
+ dictIC_params["group_idx"] = np.array(newICgroup_idx, dtype=np.object_)
951
+ dictIC_params['group_weights'] = np.array(newweightsIC_group)
952
+
953
+ self.regularisation_params = commit.solvers.init_regularisation(regularisation)
954
+
955
+
956
+ def fit( self, tol_fun=1e-3, tol_x=1e-6, max_iter=100, verbose=True, x0=None, confidence_map_filename=None, confidence_map_rescale=False ) :
759
957
  """Fit the model to the data.
760
958
 
761
959
  Parameters
@@ -765,14 +963,9 @@ cdef class Evaluation :
765
963
  max_iter : integer
766
964
  Maximum number of iterations (default : 100)
767
965
  verbose : boolean
768
- Level of verbosity: 0=no print, 1=print progress (default : True)
966
+ Level of verbosity: 0=no print, 1=print info at each iteration, 2=print progress bar, 3=print debug info (default : 2)
769
967
  x0 : np.array
770
968
  Initial guess for the solution of the problem (default : None)
771
- regularisation : commit.solvers.init_regularisation object
772
- Python dictionary that describes the wanted regularisation term.
773
- Check the documentation of commit.solvers.init_regularisation to see
774
- how to properly define the wanted mathematical formulation
775
- (default : None)
776
969
  confidence_map_filename : string
777
970
  Path to the NIFTI file containing a confidence map on the data,
778
971
  relative to the subject folder. The file can be 3D or 4D in
@@ -864,21 +1057,23 @@ cdef class Evaluation :
864
1057
  if x0 is not None :
865
1058
  if x0.shape[0] != self.A.shape[1] :
866
1059
  ERROR( 'x0 dimension does not match the number of columns of the dictionary' )
867
- if regularisation is None :
868
- regularisation = commit.solvers.init_regularisation(self)
1060
+
1061
+ if self.regularisation_params is None:
1062
+ self.set_regularisation()
1063
+
869
1064
 
870
1065
  self.CONFIG['optimization'] = {}
871
1066
  self.CONFIG['optimization']['tol_fun'] = tol_fun
872
1067
  self.CONFIG['optimization']['tol_x'] = tol_x
873
1068
  self.CONFIG['optimization']['max_iter'] = max_iter
874
1069
  self.CONFIG['optimization']['verbose'] = verbose
875
- self.CONFIG['optimization']['regularisation'] = regularisation
1070
+ self.CONFIG['optimization']['regularisation'] = self.regularisation_params
876
1071
 
877
1072
  # run solver
878
1073
  t = time.time()
879
1074
  LOG( '\n-> Fit model:' )
880
1075
 
881
- 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 = verbose, x0 = x0, regularisation = regularisation, confidence_array = confidence_array)
1076
+ 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=verbose, x0=x0, regularisation=self.regularisation_params, confidence_array=confidence_array)
882
1077
 
883
1078
  self.CONFIG['optimization']['fit_details'] = opt_details
884
1079
  self.CONFIG['optimization']['fit_time'] = time.time()-t
@@ -1071,7 +1266,9 @@ cdef class Evaluation :
1071
1266
  niiISO_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
1072
1267
  if len(self.KERNELS['iso']) > 0 :
1073
1268
  offset = nF * self.KERNELS['wmr'].shape[0] + nE * self.KERNELS['wmh'].shape[0]
1074
- xv = x[offset:].reshape( (-1,nV) ).sum( axis=0 )
1269
+ offset_iso = offset + self.DICTIONARY['ISO']['nV']
1270
+ tmp = x[offset:offset_iso].reshape( (-1,self.DICTIONARY['ISO']['nV']) ).sum( axis=0 )
1271
+ xv = np.bincount( self.DICTIONARY['ISO']['v'], weights=tmp, minlength=nV ).astype(np.float32)
1075
1272
  niiISO_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = xv
1076
1273
  print( ' [ OK ]' )
1077
1274
 
@@ -1091,8 +1288,6 @@ cdef class Evaluation :
1091
1288
  # Configuration and results
1092
1289
  print( '\t* Configuration and results:' )
1093
1290
 
1094
- print( '\t\t- streamline_weights.txt... ', end='' )
1095
- sys.stdout.flush()
1096
1291
  xic, _, _ = self.get_coeffs()
1097
1292
  if stat_coeffs != 'all' and xic.size > 0 :
1098
1293
  xic = np.reshape( xic, (-1,self.DICTIONARY['TRK']['kept'].size) )
@@ -1118,7 +1313,7 @@ cdef class Evaluation :
1118
1313
  ordered_idx = dictionary_info["tractogram_centr_idx"].astype(np.int64)
1119
1314
  unravel_weights = np.zeros( dictionary_info['n_count'], dtype=np.float64)
1120
1315
  unravel_weights[ordered_idx] = self.DICTIONARY['TRK']['kept'].astype(np.float64)
1121
- temp_weights = unravel_weights[ordered_idx]
1316
+ temp_weights = unravel_weights[ordered_idx]
1122
1317
  if dictionary_info['blur_gauss_extent'] > 0 or dictionary_info['blur_core_extent'] > 0:
1123
1318
  temp_weights[temp_weights>0] = xic[self.DICTIONARY['TRK']['kept']>0] * self.DICTIONARY['TRK']['lenTot'] / self.DICTIONARY['TRK']['len']
1124
1319
  unravel_weights[ordered_idx] = temp_weights
@@ -1127,11 +1322,26 @@ cdef class Evaluation :
1127
1322
  temp_weights[temp_weights>0] = xic[self.DICTIONARY['TRK']['kept']>0]
1128
1323
  unravel_weights[ordered_idx] = temp_weights
1129
1324
  xic = unravel_weights
1130
-
1325
+
1131
1326
  else:
1132
1327
  if dictionary_info['blur_gauss_extent'] > 0 or dictionary_info['blur_core_extent'] > 0:
1133
1328
  xic[ self.DICTIONARY['TRK']['kept']==1 ] *= self.DICTIONARY['TRK']['lenTot'] / self.DICTIONARY['TRK']['len']
1134
1329
 
1330
+
1331
+ self.temp_data['DICTIONARY'] = self.DICTIONARY
1332
+ self.temp_data['niiIC_img'] = niiIC_img
1333
+ self.temp_data['niiEC_img'] = niiEC_img
1334
+ self.temp_data['niiISO_img'] = niiISO_img
1335
+ self.temp_data['streamline_weights'] = xic
1336
+ self.temp_data['RESULTS_path'] = RESULTS_path
1337
+
1338
+ if hasattr(self.model, '_postprocess'):
1339
+ self.model._postprocess(self.temp_data, verbose=self.CONFIG['optimization']['verbose'])
1340
+ else:
1341
+ print( '\t\t- streamline_weights.txt... ', end='' )
1342
+ sys.stdout.flush()
1343
+
1344
+
1135
1345
  np.savetxt( pjoin(RESULTS_path,'streamline_weights.txt'), xic, fmt=coeffs_format )
1136
1346
  self.set_config('stat_coeffs', stat_coeffs)
1137
1347
  print( '[ OK ]' )
@@ -1142,6 +1352,13 @@ cdef class Evaluation :
1142
1352
  # item 2: np.array renormalisation of coeffs in item 1
1143
1353
  print( '\t\t- results.pickle... ', end='' )
1144
1354
  sys.stdout.flush()
1355
+
1356
+ if self.CONFIG['optimization']['regularisation'] is not None:
1357
+ if 'omega' in self.CONFIG['optimization']['regularisation']:
1358
+ self.CONFIG['optimization']['regularisation'].pop('omega')
1359
+ if 'prox' in self.CONFIG['optimization']['regularisation']:
1360
+ self.CONFIG['optimization']['regularisation'].pop('prox')
1361
+
1145
1362
  with open( pjoin(RESULTS_path,'results.pickle'), 'wb+' ) as fid :
1146
1363
  pickle.dump( [self.CONFIG, self.x, x], fid, protocol=2 )
1147
1364
  print( ' [ OK ]' )
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Format version as expected by setup.py (string of form "X.Y.Z")
4
4
  _version_major = 2
5
- _version_minor = 0
5
+ _version_minor = 1
6
6
  _version_micro = 0
7
7
  _version_extra = '' #'.dev'
8
8
  __version__ = "%s.%s.%s%s" % (_version_major,_version_minor,_version_micro,_version_extra)
@@ -23,7 +23,7 @@ These weights can be easily estimated by solving a convenient global convex opti
23
23
  """
24
24
  URL = 'https://github.com/daducci/COMMIT'
25
25
  DOWNLOAD_URL = "N/A"
26
- LICENSE = 'BSD license'
26
+ LICENSE = 'Proprietary license'
27
27
  AUTHOR = 'Alessandro Daducci'
28
28
  AUTHOR_EMAIL = 'alessandro.daducci@univr.it'
29
29
  PLATFORMS = "OS independent"