Skip to content

Commit 1d26bad

Browse files
Test whether initial guesses and fit bounds are reasonable
1 parent 1bcb389 commit 1d26bad

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

tests/IVIMmodels/unit_tests/algorithms.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
"OJ_GU_seg"
1616
],
1717
"IAR_LU_biexp": {
18-
"skip_bounds": true
18+
"test_bounds": false
1919
},
2020
"IAR_LU_modified_mix": {
21-
"skip_bounds": true
21+
"test_bounds": false
2222
},
2323
"IAR_LU_modified_topopro": {
24-
"skip_bounds": true
24+
"test_bounds": false
2525
},
2626
"IAR_LU_segmented_2step": {
27-
"skip_bounds": true
27+
"test_bounds": false
2828
},
2929
"IAR_LU_segmented_3step": {
30-
"skip_bounds": true
30+
"test_bounds": false
3131
},
3232
"IAR_LU_subtracted": {
33-
"skip_bounds": true
33+
"test_bounds": false
3434
},
3535
"ETP_SRI_LinearFitting": {
3636
"options": {
@@ -62,10 +62,10 @@
6262
"Dp": 2
6363
}
6464
},
65-
"skip_bounds": true
65+
"test_bounds": false
6666
},
6767
"OGC_AmsterdamUMC_biexp_segmented": {
68-
"skip_bounds": true
68+
"test_bounds": false
6969
},
7070
"OJ_GU_seg": {
7171
"test_bounds": false

tests/IVIMmodels/unit_tests/test_ivim_fit.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,39 @@ def test_ivim_fit_saved(name, bvals, data, algorithm, xfail, kwargs, tolerances,
177177
npt.assert_allclose(Dp_fit,data['Dp'], rtol=tolerances["rtol"]["Dp"], atol=tolerances["atol"]["Dp"])
178178
assert elapsed_time < 2, f"Algorithm {name} took {elapsed_time} seconds, which is longer than 2 second to fit per voxel" #less than 0.5 seconds per voxel
179179

180+
181+
def algorithms():
182+
# Find the algorithms from algorithms.json
183+
file = pathlib.Path(__file__)
184+
algorithm_path = file.with_name('algorithms.json')
185+
with algorithm_path.open() as f:
186+
algorithm_information = json.load(f)
187+
algorithms = algorithm_information["algorithms"]
188+
for algorithm in algorithms:
189+
yield algorithm
190+
191+
@pytest.mark.parametrize("algorithm", algorithms())
192+
def test_default_bounds_and_initial_guesses(algorithm):
193+
fit = OsipiBase(algorithm=algorithm)
194+
#assert fit.bounds is not None, f"For {algorithm}, there is no default fit boundary"
195+
#assert fit.initial_guess is not None, f"For {algorithm}, there is no default fit initial guess"
196+
if fit.bounds is not None:
197+
assert 0 <= fit.bounds[0][0] <= 0.003, f"For {algorithm}, the default lower bound of D {fit.bounds[0][0]} is unrealistic"
198+
assert 0 <= fit.bounds[1][0] <= 0.01, f"For {algorithm}, the default upper bound of D {fit.bounds[1][0]} is unrealistic"
199+
assert 0 <= fit.bounds[0][1] <= 1, f"For {algorithm}, the default lower bound of f {fit.bounds[0][1]} is unrealistic"
200+
assert 0 <= fit.bounds[1][1] <= 1, f"For {algorithm}, the default upper bound of f {fit.bounds[1][1]} is unrealistic"
201+
assert 0.003 <= fit.bounds[0][2] <= 0.05, f"For {algorithm}, the default lower bound of Ds {fit.bounds[0][2]} is unrealistic"
202+
assert 0.003 <= fit.bounds[1][2] <= 0.5, f"For {algorithm}, the default upper bound of Ds {fit.bounds[1][2]} is unrealistic"
203+
assert 0 <= fit.bounds[0][3] <= 1, f"For {algorithm}, the default lower bound of S {fit.bounds[0][3]} is unrealistic; note data is normaized"
204+
assert 1 <= fit.bounds[1][3] <= 1000, f"For {algorithm}, the default upper bound of S {fit.bounds[1][3]} is unrealistic; note data is normaized"
205+
assert fit.bounds[1][0] <= fit.bounds[0][2], f"For {algorithm}, the default upper bound of D {fit.bounds[1][0]} is higher than lower bound of D* {fit.bounds[0][2]}"
206+
if fit.initial_guess is not None:
207+
assert 0.0008 <= fit.initial_guess[0] <= 0.002, f"For {algorithm}, the default initial guess for D {fit.initial_guess[0]} is unrealistic"
208+
assert 0 <= fit.initial_guess[1] <= 0.5, f"For {algorithm}, the default initial guess for f {fit.initial_guess[1]} is unrealistic"
209+
assert 0.003 <= fit.initial_guess[2] <= 0.1, f"For {algorithm}, the default initial guess for Ds {fit.initial_guess[2]} is unrealistic"
210+
assert 0.9 <= fit.initial_guess[3] <= 1.1, f"For {algorithm}, the default initial guess for S {fit.initial_guess[3]} is unrealistic; note signal is normalized"
211+
212+
180213
def bound_input():
181214
# Find the algorithms from algorithms.json
182215
file = pathlib.Path(__file__)

0 commit comments

Comments
 (0)