Skip to content

Commit bf52071

Browse files
committed
Bounds update
1 parent 5b92c3a commit bf52071

File tree

6 files changed

+99
-69
lines changed

6 files changed

+99
-69
lines changed

src/standardized/IAR_LU_biexp.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,17 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4343
the requirements.
4444
"""
4545
super(IAR_LU_biexp, self).__init__(bvalues, thresholds, bounds, initial_guess)
46-
if bounds is not None:
47-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
4846
if bounds is None:
49-
self.use_bounds = False
47+
self.use_bounds = {"f": False, "Dp": False, "D": False}
48+
else:
49+
self.use_bounds = {"f": True, "Dp": True, "D": True}
50+
5051
if initial_guess is None:
51-
self.use_initial_guess = False
52+
self.use_initial_guess = {"f": False, "Dp": False, "D": False}
53+
else:
54+
self.use_initial_guess = {"f": True, "Dp": True, "D": True}
5255

5356
# Check the inputs
54-
# Adapt the standardized bounds to the format of the specific algorithm
55-
self.bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]],
56-
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
57-
58-
# Adapt the standardized initial guess to the format of the specific algorithm
59-
self.initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
6057

6158
# Initialize the algorithm
6259
if self.bvalues is not None:
@@ -79,6 +76,11 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7976
Returns:
8077
_type_: _description_
8178
"""
79+
80+
# Make sure bounds and initial guess conform to the algorithm requirements
81+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]],
82+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
83+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
8284

8385
if self.IAR_algorithm is None:
8486
if bvalues is None:
@@ -90,7 +92,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
9092
bvec[:,2] = 1
9193
gtab = gradient_table(bvalues, bvecs=bvec, b0_threshold=0)
9294

93-
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
95+
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=bounds, initial_guess=initial_guess)
9496

9597
fit_results = self.IAR_algorithm.fit(signals)
9698

src/standardized/IAR_LU_modified_mix.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,25 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4444
the requirements.
4545
"""
4646
super(IAR_LU_modified_mix, self).__init__(bvalues, thresholds, bounds, initial_guess)
47-
if bounds is not None:
48-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
49-
if bounds is None:
50-
self.use_bounds = False
51-
self.use_initial_guess = False # This algorithm does not use initial guesses
47+
48+
self.use_bounds = {"f": False, "Dp": False, "D": False} # This algorithm performs intermediate steps that generates initial guesses outside very constrainted bounds
49+
self.use_initial_guess = {"f": False, "Dp": False, "D": False} # This algorithm does not use initial guesses
5250

5351
# Additional options
5452
self.stochastic = True
5553

5654
# Check the inputs
57-
# Adapt the standardized bounds to the format of the specific algorithm
58-
self.bounds = [[self.bounds["f"][0], self.bounds["Dp"][0]*1000, self.bounds["D"][0]*1000],
59-
[self.bounds["f"][1], self.bounds["Dp"][1]*1000, self.bounds["D"][1]*1000]]
60-
#self.bounds = [[bounds["f"][0], bounds["f"][1]], [bounds["Dp"][0]*1000, bounds["Dp"][1]*1000], [bounds["D"][0]*1000, bounds["D"][1]*1000]]
6155

6256
# Initialize the algorithm
6357
if self.bvalues is not None:
6458
bvec = np.zeros((self.bvalues.size, 3))
6559
bvec[:,2] = 1
6660
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
6761

68-
self.IAR_algorithm = IvimModelVP(gtab, bounds=self.bounds, rescale_units=False, rescale_results_to_mm2_s=True)
62+
bounds = [[self.bounds["f"][0], self.bounds["Dp"][0]*1000, self.bounds["D"][0]*1000],
63+
[self.bounds["f"][1], self.bounds["Dp"][1]*1000, self.bounds["D"][1]*1000]]
64+
65+
self.IAR_algorithm = IvimModelVP(gtab, bounds=bounds, rescale_units=False, rescale_results_to_mm2_s=True)
6966
else:
7067
self.IAR_algorithm = None
7168

@@ -80,6 +77,9 @@ def ivim_fit(self, signals, bvalues, **kwargs):
8077
Returns:
8178
_type_: _description_
8279
"""
80+
81+
bounds = [[self.bounds["f"][0], self.bounds["Dp"][0]*1000, self.bounds["D"][0]*1000],
82+
[self.bounds["f"][1], self.bounds["Dp"][1]*1000, self.bounds["D"][1]*1000]]
8383

8484
if self.IAR_algorithm is None:
8585
if bvalues is None:
@@ -91,7 +91,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
9191
bvec[:,2] = 1
9292
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
9393

94-
self.IAR_algorithm = IvimModelVP(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
94+
self.IAR_algorithm = IvimModelVP(gtab, bounds=bounds, rescale_results_to_mm2_s=True)
9595

9696
fit_results = self.IAR_algorithm.fit(signals)
9797

src/standardized/IAR_LU_modified_topopro.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,29 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4343
the requirements.
4444
"""
4545
super(IAR_LU_modified_topopro, self).__init__(bvalues, thresholds, bounds, initial_guess)
46-
if bounds is not None:
47-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
48-
if bounds is None:
49-
self.use_bounds = False
50-
self.use_initial_guess = False # This algorithm does not use initial guesses
46+
47+
self.use_bounds = {"f" : False, "Dp": False, "D": False} # This algorithm performs intermediate steps that generates new bounds
48+
self.use_initial_guess = {"f" : False, "Dp": False, "D": False} # This algorithm does not use initial guesses
5149

5250
# Additional options
5351
self.stochastic = True
5452

5553
# Check the inputs
56-
# Adapt the standardized bounds to the format of the specific algorithm
5754
if self.bounds["Dp"][0] == self.bounds["D"][1]:
5855
print('warning, bounds for D* and D are equal, this will likely cause fitting errors. Setting D_upper to 99 percent of D_upper')
5956
self.bounds["D"][1] = self.bounds["D"][1]*0.99
60-
self.bounds = [[self.bounds["f"][0], self.bounds["Dp"][0]*1000, self.bounds["D"][0]*1000],
61-
[self.bounds["f"][1], self.bounds["Dp"][1]*1000, self.bounds["D"][1]*1000]]
6257
# Check the inputs
6358

6459
# Initialize the algorithm
6560
if self.bvalues is not None:
6661
bvec = np.zeros((self.bvalues.size, 3))
6762
bvec[:,2] = 1
6863
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
64+
65+
bounds = [[self.bounds["f"][0], self.bounds["Dp"][0]*1000, self.bounds["D"][0]*1000],
66+
[self.bounds["f"][1], self.bounds["Dp"][1]*1000, self.bounds["D"][1]*1000]]
6967

70-
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
68+
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=bounds, rescale_results_to_mm2_s=True)
7169
else:
7270
self.IAR_algorithm = None
7371

@@ -82,6 +80,8 @@ def ivim_fit(self, signals, bvalues, **kwargs):
8280
Returns:
8381
_type_: _description_
8482
"""
83+
bounds = [[self.bounds["f"][0], self.bounds["Dp"][0]*1000, self.bounds["D"][0]*1000],
84+
[self.bounds["f"][1], self.bounds["Dp"][1]*1000, self.bounds["D"][1]*1000]]
8585

8686
if self.IAR_algorithm is None:
8787
if bvalues is None:
@@ -93,7 +93,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
9393
bvec[:,2] = 1
9494
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
9595

96-
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
96+
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=bounds, rescale_results_to_mm2_s=True)
9797

9898
fit_results = self.IAR_algorithm.fit(signals)
9999

src/standardized/IAR_LU_segmented_2step.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,31 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4343
the requirements.
4444
"""
4545
super(IAR_LU_segmented_2step, self).__init__(bvalues, thresholds, bounds, initial_guess)
46-
if bounds is not None:
47-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
4846
if bounds is None:
49-
self.use_bounds = False
47+
self.use_bounds = {"f": False, "Dp": False, "D": False, "S0": False}
48+
else:
49+
self.use_bounds = {"f": True, "Dp": True, "D": True, "S0": True}
50+
5051
if initial_guess is None:
51-
self.use_initial_guess = False
52+
self.use_initial_guess = {"f": False, "Dp": False, "D": False, "S0": False}
53+
else:
54+
self.use_initial_guess = {"f": True, "Dp": True, "D": True, "S0": True}
55+
5256
# Check the inputs
5357

54-
# Adapt the bounds to the format needed for the algorithm
55-
self.bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
56-
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
57-
58-
# Adapt the initial guess to the format needed for the algorithm
59-
self.initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
6058

6159
# Initialize the algorithm
6260
if self.bvalues is not None:
6361
bvec = np.zeros((self.bvalues.size, 3))
6462
bvec[:,2] = 1
6563
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
64+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
65+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
66+
67+
# Adapt the initial guess to the format needed for the algorithm
68+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
6669

67-
self.IAR_algorithm = IvimModelSegmented2Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess, b_threshold=self.thresholds)
70+
self.IAR_algorithm = IvimModelSegmented2Step(gtab, bounds=bounds, initial_guess=initial_guess, b_threshold=self.thresholds)
6871
else:
6972
self.IAR_algorithm = None
7073

@@ -79,7 +82,12 @@ def ivim_fit(self, signals, bvalues, thresholds=None, **kwargs):
7982
Returns:
8083
_type_: _description_
8184
"""
82-
print(thresholds)
85+
# Adapt the bounds to the format needed for the algorithm
86+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
87+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
88+
89+
# Adapt the initial guess to the format needed for the algorithm
90+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
8391

8492
if self.IAR_algorithm is None:
8593
if bvalues is None:
@@ -94,7 +102,7 @@ def ivim_fit(self, signals, bvalues, thresholds=None, **kwargs):
94102
if self.thresholds is None:
95103
self.thresholds = 200
96104

97-
self.IAR_algorithm = IvimModelSegmented2Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess, b_threshold=self.thresholds)
105+
self.IAR_algorithm = IvimModelSegmented2Step(gtab, bounds=bounds, initial_guess=initial_guess, b_threshold=self.thresholds)
98106

99107
fit_results = self.IAR_algorithm.fit(signals)
100108

src/standardized/IAR_LU_segmented_3step.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,31 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4343
the requirements.
4444
"""
4545
super(IAR_LU_segmented_3step, self).__init__(bvalues, thresholds, bounds, initial_guess)
46-
if bounds is not None:
47-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
4846
if bounds is None:
49-
self.use_bounds = False
47+
self.use_bounds = {"f" : False, "Dp" : False, "D" : False, "S0" : False}
48+
else:
49+
self.use_bounds = {"f" : True, "Dp" : True, "D" : True, "S0" : True}
50+
5051
if initial_guess is None:
51-
self.use_initial_guess = False
52+
self.use_initial_guess = {"f" : False, "Dp" : False, "D" : False, "S0" : False}
53+
else:
54+
self.use_initial_guess = {"f" : True, "Dp" : True, "D" : True, "S0" : True}
55+
5256
# Check the inputs
5357

54-
# Adapt the bounds to the format needed for the algorithm
55-
self.bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
56-
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
57-
58-
# Adapt the initial guess to the format needed for the algorithm
59-
self.initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
6058

6159
# Initialize the algorithm
6260
if self.bvalues is not None:
6361
bvec = np.zeros((self.bvalues.size, 3))
6462
bvec[:,2] = 1
6563
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
64+
65+
# Adapt the bounds to the format needed for the algorithm
66+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
67+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
68+
69+
# Adapt the initial guess to the format needed for the algorithm
70+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
6671

6772
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
6873
else:
@@ -79,6 +84,12 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7984
Returns:
8085
_type_: _description_
8186
"""
87+
# Adapt the bounds to the format needed for the algorithm
88+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
89+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
90+
91+
# Adapt the initial guess to the format needed for the algorithm
92+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
8293

8394
if self.IAR_algorithm is None:
8495
if bvalues is None:
@@ -90,7 +101,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
90101
bvec[:,2] = 1
91102
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
92103

93-
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
104+
self.IAR_algorithm = IvimModelSegmented3Step(gtab, bounds=bounds, initial_guess=initial_guess)
94105

95106
fit_results = self.IAR_algorithm.fit(signals)
96107

src/standardized/IAR_LU_subtracted.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,31 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
4343
the requirements.
4444
"""
4545
super(IAR_LU_subtracted, self).__init__(bvalues, thresholds, bounds, initial_guess)
46-
if bounds is not None:
47-
print('warning, bounds from wrapper are not (yet) used in this algorithm')
4846
if bounds is None:
49-
self.use_bounds = False
47+
self.use_bounds = {"f" : False, "Dp" : False, "D" : False, "S0" : False}
48+
else:
49+
self.use_bounds = {"f" : False, "Dp" : True, "D" : True, "S0" : True}
5050
if initial_guess is None:
51-
self.use_initial_guess = False
52-
# Check the inputs
51+
self.use_initial_guess = {"f" : False, "Dp" : False, "D" : False, "S0" : False}
52+
else:
53+
self.use_initial_guess = {"f" : False, "Dp" : True, "D" : True, "S0" : True}
5354

54-
# Adapt the bounds to the format needed for the algorithm
55-
self.bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
56-
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
57-
58-
# Adapt the initial guess to the format needed for the algorithm
59-
self.initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
55+
# Check the inputs
6056

6157
# Initialize the algorithm
6258
if self.bvalues is not None:
6359
bvec = np.zeros((self.bvalues.size, 3))
6460
bvec[:,2] = 1
6561
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)
62+
63+
# Adapt the bounds to the format needed for the algorithm
64+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
65+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
6666

67-
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
67+
# Adapt the initial guess to the format needed for the algorithm
68+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
69+
70+
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=bounds, initial_guess=initial_guess)
6871
else:
6972
self.IAR_algorithm = None
7073

@@ -79,6 +82,12 @@ def ivim_fit(self, signals, bvalues, **kwargs):
7982
Returns:
8083
_type_: _description_
8184
"""
85+
# Adapt the bounds to the format needed for the algorithm
86+
bounds = [[self.bounds["S0"][0], self.bounds["f"][0], self.bounds["Dp"][0], self.bounds["D"][0]], \
87+
[self.bounds["S0"][1], self.bounds["f"][1], self.bounds["Dp"][1], self.bounds["D"][1]]]
88+
89+
# Adapt the initial guess to the format needed for the algorithm
90+
initial_guess = [self.initial_guess["S0"], self.initial_guess["f"], self.initial_guess["Dp"], self.initial_guess["D"]]
8291

8392
if self.IAR_algorithm is None:
8493
if bvalues is None:
@@ -90,7 +99,7 @@ def ivim_fit(self, signals, bvalues, **kwargs):
9099
bvec[:,2] = 1
91100
gtab = gradient_table(bvalues, bvec, b0_threshold=0)
92101

93-
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
102+
self.IAR_algorithm = IvimModelSubtracted(gtab, bounds=bounds, initial_guess=initial_guess)
94103

95104
fit_results = self.IAR_algorithm.fit(signals)
96105

0 commit comments

Comments
 (0)