Skip to content

Commit c9af8ef

Browse files
Merge pull request #90 from OSIPI/wrapper_dev
Support for bounds, initial guess, and threhold inputs
2 parents 91df0c6 + 3f36ddc commit c9af8ef

22 files changed

+115
-172
lines changed

src/original/IAR_LundUniversity/ivim_fit_method_biexp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ def ivim_model(self, b, S0, f, D_star, D):
6161

6262
def set_bounds(self, bounds):
6363
# Use this function for fits that uses curve_fit
64-
if bounds == None:
64+
if bounds is None:
6565
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
6666
else:
67-
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
67+
self.bounds = np.array([bounds[0], bounds[1]])
6868

6969
def set_initial_guess(self, initial_guess):
70-
if initial_guess == None:
70+
if initial_guess is None:
7171
self.initial_guess = (1, 0.2, 0.03, 0.001)
7272
else:
7373
self.initial_guess = initial_guess

src/original/IAR_LundUniversity/ivim_fit_method_linear.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ def sivim_model(self, b, S0, f, D):
8383

8484
def set_bounds(self, bounds):
8585
# Use this function for fits that uses curve_fit
86-
if bounds == None:
86+
if bounds is None:
8787
self.bounds = np.array([(0, 0, 0), (np.inf, 1, 0.004)])
8888
else:
89-
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
89+
self.bounds = np.array([bounds[0], bounds[1]])
9090

9191
def set_initial_guess(self, initial_guess):
92-
if initial_guess == None:
92+
if initial_guess is None:
9393
self.initial_guess = (1, 0.2, 0.001)
9494
else:
9595
self.initial_guess = initial_guess

src/original/IAR_LundUniversity/ivim_fit_method_modified_mix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, gtab, bounds=None, maxiter=10, xtol=1e-8, rescale_units=False
7878
if gtab.bvals[-1] >= 10:
7979
self.bvals = gtab.bvals/1000
8080

81-
if bounds == None:
81+
if bounds is None:
8282
# Bounds expressed as (lower bound, upper bound) for [f, D*, D].
8383
self.bounds = np.array([(0, 1), (5, 100), (0, 4)])
8484
elif (bounds[0][1] <= 1) or rescale_units: # Realistically, if mm2/s units are used, D* bound is <= 1

src/original/IAR_LundUniversity/ivim_fit_method_modified_topopro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, gtab, bounds=[[0, 0.005, 1e-5], [1, 0.1, 0.004]], \
7676
# and are thus not changed.
7777
if gtab.bvals[-1] >= 10:
7878
self.bvals = gtab.bvals/1000
79-
if bounds == None:
79+
if bounds is None:
8080
# Bounds expressed as (lower bound, upper bound) for [f, D*, D].
8181
self.bounds = np.array([(0, 1), (5, 100), (0, 4)])
8282
elif (bounds[0][1] <= 1) or rescale_units: # Realistically, if mm2/s units are used, D* bound is <= 1

src/original/IAR_LundUniversity/ivim_fit_method_segmented_2step.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ def ivim_signal(self, b, S0, f, D_star, D):
8686

8787
def set_bounds(self, bounds):
8888
# Use this function for fits that uses curve_fit
89-
if bounds == None:
89+
if bounds is None:
9090
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
9191
else:
92-
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
92+
self.bounds = np.array([bounds[0], bounds[1]])
9393

9494
def set_initial_guess(self, initial_guess):
95-
if initial_guess == None:
95+
if initial_guess is None:
9696
self.initial_guess = (1, 0.2, 0.03, 0.001)
9797
else:
9898
self.initial_guess = initial_guess

src/original/IAR_LundUniversity/ivim_fit_method_segmented_3step.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def ivim_signal(self, b, S0, f, D_star, D):
105105

106106
def set_bounds(self, bounds):
107107
# Use this function for fits that uses curve_fit
108-
if bounds == None:
108+
if bounds is None:
109109
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
110110
else:
111-
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
111+
self.bounds = np.array([bounds[0], bounds[1]])
112112

113113
def set_initial_guess(self, initial_guess):
114-
if initial_guess == None:
114+
if initial_guess is None:
115115
self.initial_guess = (1, 0.2, 0.03, 0.001)
116116
else:
117117
self.initial_guess = initial_guess

src/original/IAR_LundUniversity/ivim_fit_method_sivim.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ def sivim_model(self, b, S0, f, D):
7777

7878
def set_bounds(self, bounds):
7979
# Use this function for fits that uses curve_fit
80-
if bounds == None:
80+
if bounds is None:
8181
self.bounds = np.array([(0, 0, 0), (np.inf, 1, 0.004)])
8282
else:
83-
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
83+
self.bounds = np.array([bounds[0], bounds[1]])
8484

8585
def set_initial_guess(self, initial_guess):
86-
if initial_guess == None:
86+
if initial_guess is None:
8787
self.initial_guess = (1, 0.2, 0.001)
8888
else:
8989
self.initial_guess = initial_guess

src/original/IAR_LundUniversity/ivim_fit_method_subtracted.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ def perfusion_signal(self, b, S0, D_star):
9393

9494
def set_bounds(self, bounds):
9595
# Use this function for fits that uses curve_fit
96-
if bounds == None:
96+
if bounds is None:
9797
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
9898
else:
99-
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
99+
self.bounds = np.array([bounds[0], bounds[1]])
100100

101101
def set_initial_guess(self, initial_guess):
102-
if initial_guess == None:
102+
if initial_guess is None:
103103
self.initial_guess = (1, 0.2, 0.03, 0.001)
104104
else:
105105
self.initial_guess = initial_guess

src/original/IAR_LundUniversity/simple_test_of_fits.py

Lines changed: 0 additions & 130 deletions
This file was deleted.

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

0 commit comments

Comments
 (0)