Skip to content

Commit c7c4376

Browse files
author
IvanARashid
committed
Added support for initial guesses, bounds, and thresholds where applicable
1 parent 9dfe0af commit c7c4376

13 files changed

+95
-22
lines changed

src/standardized/ETP_SRI_LinearFitting.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class ETP_SRI_LinearFitting(OsipiBase):
2727
required_initial_guess_optional = False
2828
accepted_dimensions = 1
2929
# Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
30+
31+
# Supported inputs in the standardized class
32+
supported_bounds = False
33+
supported_initial_guess = False
34+
supported_thresholds = True
3035

3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
3237
"""
@@ -36,7 +41,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
3641
Our OsipiBase object could contain functions that compare the inputs with
3742
the requirements.
3843
"""
39-
super(ETP_SRI_LinearFitting, self).__init__(bvalues, thresholds, bounds, initial_guess)
44+
super(ETP_SRI_LinearFitting, self).__init__(bvalues=bvalues, thresholds=thresholds, bounds=bounds, initial_guess=initial_guess)
4045

4146
# Could be a good idea to have all the submission-specfic variable be
4247
# defined with initials?
@@ -67,7 +72,7 @@ def ivim_fit(self, signals, bvalues=None, linear_fit_option=False, **kwargs):
6772

6873
results = {}
6974
if linear_fit_option:
70-
f, Dstar = ETP_object.linear_fit(bvalues, signals)
75+
f, Dstar = ETP_object.linear_fit(bvalues, signals, self.ETP_weighting, self.ETP_stats)
7176

7277
results["f"] = f
7378
results["D*"] = Dstar

src/standardized/IAR_LU_biexp.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class IAR_LU_biexp(OsipiBase):
2727
required_initial_guess = False
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
30+
31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = True
34+
supported_thresholds = False
3035

3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
3237
"""
@@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4651
bvec[:,2] = 1
4752
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
4853

49-
self.IAR_algorithm = IvimModelBiExp(gtab)
54+
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
5055
else:
5156
self.IAR_algorithm = None
5257

@@ -72,7 +77,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7277
bvec[:,2] = 1
7378
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
7479

75-
self.IAR_algorithm = IvimModelBiExp(gtab)
80+
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
7681

7782
fit_results = self.IAR_algorithm.fit(signals)
7883

@@ -104,7 +109,7 @@ def ivim_fit_full_volume(self, signals, bvalues, **kwargs):
104109
bvec[:,2] = 1
105110
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
106111

107-
self.IAR_algorithm = IvimModelBiExp(gtab)
112+
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
108113

109114
fit_results = self.IAR_algorithm.fit(signals)
110115

src/standardized/IAR_LU_modified_mix.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class IAR_LU_modified_mix(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = False
34+
supported_thresholds = False
35+
3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
3237
"""
3338
Everything this algorithm requires should be implemented here.
@@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4651
bvec[:,2] = 1
4752
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
4853

49-
self.IAR_algorithm = IvimModelVP(gtab)
54+
self.IAR_algorithm = IvimModelVP(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
5055
else:
5156
self.IAR_algorithm = None
5257

@@ -72,7 +77,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7277
bvec[:,2] = 1
7378
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
7479

75-
self.IAR_algorithm = IvimModelVP(gtab, rescale_results_to_mm2_s=True)
80+
self.IAR_algorithm = IvimModelVP(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
7681

7782
fit_results = self.IAR_algorithm.fit(signals)
7883

src/standardized/IAR_LU_modified_topopro.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class IAR_LU_modified_topopro(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = False
34+
supported_thresholds = False
35+
3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
3237
"""
3338
Everything this algorithm requires should be implemented here.
@@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4651
bvec[:,2] = 1
4752
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
4853

49-
self.IAR_algorithm = IvimModelTopoPro(gtab)
54+
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
5055
else:
5156
self.IAR_algorithm = None
5257

@@ -72,7 +77,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7277
bvec[:,2] = 1
7378
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
7479

75-
self.IAR_algorithm = IvimModelTopoPro(gtab, rescale_results_to_mm2_s=True)
80+
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
7681

7782
fit_results = self.IAR_algorithm.fit(signals)
7883

src/standardized/IAR_LU_segmented_2step.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class IAR_LU_segmented_2step(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = True
34+
supported_thresholds = True
35+
3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None):
3237
"""
3338
Everything this algorithm requires should be implemented here.
@@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4651
bvec[:,2] = 1
4752
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
4853

49-
self.IAR_algorithm = IvimModelSegmented2Step(gtab)
54+
self.IAR_algorithm = IvimModelSegmented2Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess, b_threshold=self.thresholds)
5055
else:
5156
self.IAR_algorithm = None
5257

@@ -72,8 +77,11 @@ def ivim_fit(self, signals, bvalues, thresholds=None, **kwargs):
7277
bvec = np.zeros((bvalues.size, 3))
7378
bvec[:,2] = 1
7479
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
75-
76-
self.IAR_algorithm = IvimModelSegmented2Step(gtab)
80+
81+
if self.thresholds is None:
82+
self.thresholds = 200
83+
84+
self.IAR_algorithm = IvimModelSegmented2Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess, b_threshold=self.thresholds)
7785

7886
fit_results = self.IAR_algorithm.fit(signals)
7987

src/standardized/IAR_LU_segmented_3step.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class IAR_LU_segmented_3step(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = True
34+
supported_thresholds = False
35+
3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
3237
"""
3338
Everything this algorithm requires should be implemented here.
@@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4651
bvec[:,2] = 1
4752
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
4853

49-
self.IAR_algorithm = IvimModelSegmented3Step(gtab)
54+
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
5055
else:
5156
self.IAR_algorithm = None
5257

@@ -72,7 +77,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7277
bvec[:,2] = 1
7378
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
7479

75-
self.IAR_algorithm = IvimModelSegmented3Step(gtab)
80+
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
7681

7782
fit_results = self.IAR_algorithm.fit(signals)
7883

src/standardized/IAR_LU_subtracted.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class IAR_LU_subtracted(OsipiBase):
2828
required_initial_guess_optional = True
2929
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
3030

31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = True
34+
supported_thresholds = False
35+
3136
def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None):
3237
"""
3338
Everything this algorithm requires should be implemented here.
@@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4651
bvec[:,2] = 1
4752
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
4853

49-
self.IAR_algorithm = IvimModelSubtracted(gtab)
54+
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
5055
else:
5156
self.IAR_algorithm = None
5257

@@ -72,7 +77,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7277
bvec[:,2] = 1
7378
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
7479

75-
self.IAR_algorithm = IvimModelSubtracted(gtab)
80+
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
7681

7782
fit_results = self.IAR_algorithm.fit(signals)
7883

src/standardized/OGC_AmsterdamUMC_Bayesian_biexp.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class OGC_AmsterdamUMC_Bayesian_biexp(OsipiBase):
2828
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
2929
accepts_priors = True
3030

31+
# Supported inputs in the standardized class
32+
supported_bounds = True
33+
supported_initial_guess = True
34+
supported_thresholds = True
35+
3136
def __init__(self, bvalues=None, thresholds=None, bounds=([0, 0, 0.005, 0.7],[0.005, 0.7, 0.2, 1.3]), initial_guess=None, fitS0=True, prior_in=None):
3237
"""
3338
Everything this algorithm requires should be implemented here.
@@ -39,7 +44,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=([0, 0, 0.005, 0.7],[0.
3944
Args:
4045
datain is a 2D array with values of D, f, D* (and S0) that will form the prior.
4146
"""
42-
super(OGC_AmsterdamUMC_Bayesian_biexp, self).__init__(bvalues, bounds, initial_guess) #, fitS0, prior_in)
47+
super(OGC_AmsterdamUMC_Bayesian_biexp, self).__init__(bvalues=bvalues, bounds=bounds, thresholds=thresholds, initial_guess=initial_guess) #, fitS0, prior_in)
4348
self.OGC_algorithm = fit_bayesian
4449
self.initialize(bounds, initial_guess, fitS0, prior_in)
4550

@@ -74,7 +79,7 @@ def ivim_fit(self, signals, bvalues, initial_guess=None, **kwargs):
7479
if initial_guess is not None and len(initial_guess) == 4:
7580
self.initial_guess = initial_guess
7681
bvalues=np.array(bvalues)
77-
fit_results = fit_segmented(bvalues, signals, bounds=self.bounds, cutoff=150, p0=self.initial_guess)
82+
fit_results = fit_segmented(bvalues, signals, bounds=self.bounds, cutoff=self.thresholds, p0=self.initial_guess)
7883
fit_results=fit_results+(1,)
7984
fit_results = self.OGC_algorithm(bvalues, signals, self.neg_log_prior, x0=fit_results, fitS0=self.fitS0)
8085

src/standardized/OGC_AmsterdamUMC_biexp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class OGC_AmsterdamUMC_biexp(OsipiBase):
2727
required_initial_guess_optional = True
2828
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
2929

30+
# Supported inputs in the standardized class
31+
supported_bounds = True
32+
supported_initial_guess = True
33+
supported_thresholds = False
34+
3035
def __init__(self, bvalues=None, thresholds=None, bounds=([0, 0, 0.005, 0.7],[0.005, 0.7, 0.2, 1.3]), initial_guess=None, fitS0=False):
3136
"""
3237
Everything this algorithm requires should be implemented here.

src/standardized/OGC_AmsterdamUMC_biexp_segmented.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class OGC_AmsterdamUMC_biexp_segmented(OsipiBase):
2727
required_initial_guess_optional = True
2828
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
2929

30+
# Supported inputs in the standardized class
31+
supported_bounds = True
32+
supported_initial_guess = True
33+
supported_thresholds = True
34+
3035
def __init__(self, bvalues=None, thresholds=150, bounds=([0, 0, 0.005],[0.005, 0.7, 0.2]), initial_guess=[0.001, 0.01, 0.01,1]):
3136
"""
3237
Everything this algorithm requires should be implemented here.

0 commit comments

Comments
 (0)