Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for bounds, initial guess, and threhold inputs #90

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/original/IAR_LundUniversity/ivim_fit_method_biexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def ivim_model(self, b, S0, f, D_star, D):

def set_bounds(self, bounds):
# Use this function for fits that uses curve_fit
if bounds == None:
if bounds is None:
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
else:
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
self.bounds = np.array([bounds[0], bounds[1]])

def set_initial_guess(self, initial_guess):
if initial_guess == None:
if initial_guess is None:
self.initial_guess = (1, 0.2, 0.03, 0.001)
else:
self.initial_guess = initial_guess
Expand Down
6 changes: 3 additions & 3 deletions src/original/IAR_LundUniversity/ivim_fit_method_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def sivim_model(self, b, S0, f, D):

def set_bounds(self, bounds):
# Use this function for fits that uses curve_fit
if bounds == None:
if bounds is None:
self.bounds = np.array([(0, 0, 0), (np.inf, 1, 0.004)])
else:
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
self.bounds = np.array([bounds[0], bounds[1]])

def set_initial_guess(self, initial_guess):
if initial_guess == None:
if initial_guess is None:
self.initial_guess = (1, 0.2, 0.001)
else:
self.initial_guess = initial_guess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, gtab, bounds=None, maxiter=10, xtol=1e-8, rescale_units=False
if gtab.bvals[-1] >= 10:
self.bvals = gtab.bvals/1000

if bounds == None:
if bounds is None:
# Bounds expressed as (lower bound, upper bound) for [f, D*, D].
self.bounds = np.array([(0, 1), (5, 100), (0, 4)])
elif (bounds[0][1] <= 1) or rescale_units: # Realistically, if mm2/s units are used, D* bound is <= 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, gtab, bounds=[[0, 0.005, 1e-5], [1, 0.1, 0.004]], \
# and are thus not changed.
if gtab.bvals[-1] >= 10:
self.bvals = gtab.bvals/1000
if bounds == None:
if bounds is None:
# Bounds expressed as (lower bound, upper bound) for [f, D*, D].
self.bounds = np.array([(0, 1), (5, 100), (0, 4)])
elif (bounds[0][1] <= 1) or rescale_units: # Realistically, if mm2/s units are used, D* bound is <= 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def ivim_signal(self, b, S0, f, D_star, D):

def set_bounds(self, bounds):
# Use this function for fits that uses curve_fit
if bounds == None:
if bounds is None:
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
else:
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
self.bounds = np.array([bounds[0], bounds[1]])

def set_initial_guess(self, initial_guess):
if initial_guess == None:
if initial_guess is None:
self.initial_guess = (1, 0.2, 0.03, 0.001)
else:
self.initial_guess = initial_guess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def ivim_signal(self, b, S0, f, D_star, D):

def set_bounds(self, bounds):
# Use this function for fits that uses curve_fit
if bounds == None:
if bounds is None:
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
else:
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
self.bounds = np.array([bounds[0], bounds[1]])

def set_initial_guess(self, initial_guess):
if initial_guess == None:
if initial_guess is None:
self.initial_guess = (1, 0.2, 0.03, 0.001)
else:
self.initial_guess = initial_guess
Expand Down
6 changes: 3 additions & 3 deletions src/original/IAR_LundUniversity/ivim_fit_method_sivim.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def sivim_model(self, b, S0, f, D):

def set_bounds(self, bounds):
# Use this function for fits that uses curve_fit
if bounds == None:
if bounds is None:
self.bounds = np.array([(0, 0, 0), (np.inf, 1, 0.004)])
else:
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
self.bounds = np.array([bounds[0], bounds[1]])

def set_initial_guess(self, initial_guess):
if initial_guess == None:
if initial_guess is None:
self.initial_guess = (1, 0.2, 0.001)
else:
self.initial_guess = initial_guess
Expand Down
6 changes: 3 additions & 3 deletions src/original/IAR_LundUniversity/ivim_fit_method_subtracted.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def perfusion_signal(self, b, S0, D_star):

def set_bounds(self, bounds):
# Use this function for fits that uses curve_fit
if bounds == None:
if bounds is None:
self.bounds = np.array([(0, 0, 0.005, 0), (np.inf, 1, 0.1, 0.004)])
else:
self.bounds = np.array([(0, *bounds[0]), (np.inf, *bounds[1])])
self.bounds = np.array([bounds[0], bounds[1]])

def set_initial_guess(self, initial_guess):
if initial_guess == None:
if initial_guess is None:
self.initial_guess = (1, 0.2, 0.03, 0.001)
else:
self.initial_guess = initial_guess
Expand Down
130 changes: 0 additions & 130 deletions src/original/IAR_LundUniversity/simple_test_of_fits.py

This file was deleted.

9 changes: 7 additions & 2 deletions src/standardized/ETP_SRI_LinearFitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class ETP_SRI_LinearFitting(OsipiBase):
required_initial_guess_optional = False
accepted_dimensions = 1
# Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?

# Supported inputs in the standardized class
supported_bounds = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how these are used.
Are these now properties of the class that I can ask using self.supported_bounds? That would help with testing :)

supported_initial_guess = False
supported_thresholds = True

def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
"""
Expand All @@ -36,7 +41,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
Our OsipiBase object could contain functions that compare the inputs with
the requirements.
"""
super(ETP_SRI_LinearFitting, self).__init__(bvalues, thresholds, bounds, initial_guess)
super(ETP_SRI_LinearFitting, self).__init__(bvalues=bvalues, thresholds=thresholds, bounds=bounds, initial_guess=initial_guess)

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

results = {}
if linear_fit_option:
f, Dstar = ETP_object.linear_fit(bvalues, signals)
f, Dstar = ETP_object.linear_fit(bvalues, signals, self.ETP_weighting, self.ETP_stats)

results["f"] = f
results["D*"] = Dstar
Expand Down
11 changes: 8 additions & 3 deletions src/standardized/IAR_LU_biexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class IAR_LU_biexp(OsipiBase):
required_initial_guess = False
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?

# Supported inputs in the standardized class
supported_bounds = True
supported_initial_guess = True
supported_thresholds = False

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

self.IAR_algorithm = IvimModelBiExp(gtab)
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)
else:
self.IAR_algorithm = None

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

self.IAR_algorithm = IvimModelBiExp(gtab)
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)

fit_results = self.IAR_algorithm.fit(signals)

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

self.IAR_algorithm = IvimModelBiExp(gtab)
self.IAR_algorithm = IvimModelBiExp(gtab, bounds=self.bounds, initial_guess=self.initial_guess)

fit_results = self.IAR_algorithm.fit(signals)

Expand Down
9 changes: 7 additions & 2 deletions src/standardized/IAR_LU_modified_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class IAR_LU_modified_mix(OsipiBase):
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?

# Supported inputs in the standardized class
supported_bounds = True
supported_initial_guess = False
supported_thresholds = False

def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
"""
Everything this algorithm requires should be implemented here.
Expand All @@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
bvec[:,2] = 1
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)

self.IAR_algorithm = IvimModelVP(gtab)
self.IAR_algorithm = IvimModelVP(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
else:
self.IAR_algorithm = None

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

self.IAR_algorithm = IvimModelVP(gtab, rescale_results_to_mm2_s=True)
self.IAR_algorithm = IvimModelVP(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)

fit_results = self.IAR_algorithm.fit(signals)

Expand Down
9 changes: 7 additions & 2 deletions src/standardized/IAR_LU_modified_topopro.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class IAR_LU_modified_topopro(OsipiBase):
required_initial_guess_optional = True
accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?

# Supported inputs in the standardized class
supported_bounds = True
supported_initial_guess = False
supported_thresholds = False

def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=None, weighting=None, stats=False):
"""
Everything this algorithm requires should be implemented here.
Expand All @@ -46,7 +51,7 @@ def __init__(self, bvalues=None, thresholds=None, bounds=None, initial_guess=Non
bvec[:,2] = 1
gtab = gradient_table(self.bvalues, bvec, b0_threshold=0)

self.IAR_algorithm = IvimModelTopoPro(gtab)
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)
else:
self.IAR_algorithm = None

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

self.IAR_algorithm = IvimModelTopoPro(gtab, rescale_results_to_mm2_s=True)
self.IAR_algorithm = IvimModelTopoPro(gtab, bounds=self.bounds, rescale_results_to_mm2_s=True)

fit_results = self.IAR_algorithm.fit(signals)

Expand Down
Loading
Loading