@@ -150,7 +150,7 @@ def fit_segmented(bvalues, dw_data, bounds=([0, 0, 0.005],[0.005, 0.7, 0.2]), cu
150
150
151
151
152
152
def fit_least_squares_array (bvalues , dw_data , S0_output = True , fitS0 = True , njobs = 4 ,
153
- bounds = ([0 , 0 , 0.005 , 0.7 ],[0.005 , 0.7 , 0.2 , 1.3 ])):
153
+ bounds = ([0 , 0 , 0.005 , 0.7 ],[0.005 , 0.7 , 0.2 , 1.3 ]), p0 = [ 1 , 1 , 0.1 , 1 ] ):
154
154
"""
155
155
This is an implementation of the conventional IVIM fit. It is fitted in array form.
156
156
:param bvalues: 1D Array with the b-values
@@ -175,7 +175,7 @@ def fit_least_squares_array(bvalues, dw_data, S0_output=True, fitS0=True, njobs=
175
175
try :
176
176
# defining parallel function
177
177
def parfun (i ):
178
- return fit_least_squares (bvalues , dw_data [i , :], S0_output = S0_output , fitS0 = fitS0 , bounds = bounds )
178
+ return fit_least_squares (bvalues , dw_data [i , :], S0_output = S0_output , fitS0 = fitS0 , bounds = bounds , p0 = p0 )
179
179
180
180
output = Parallel (n_jobs = njobs )(delayed (parfun )(i ) for i in tqdm (range (len (dw_data )), position = 0 , leave = True ))
181
181
Dt , Fp , Dp , S0 = np .transpose (output )
@@ -192,14 +192,14 @@ def parfun(i):
192
192
# running in a single loop and filling arrays
193
193
for i in tqdm (range (len (dw_data )), position = 0 , leave = True ):
194
194
Dt [i ], Fp [i ], Dp [i ], S0 [i ] = fit_least_squares (bvalues , dw_data [i , :], S0_output = S0_output , fitS0 = fitS0 ,
195
- bounds = bounds )
195
+ bounds = bounds , p0 = p0 )
196
196
return [Dt , Fp , Dp , S0 ]
197
197
else :
198
198
# if S0 is not exported
199
199
if njobs > 1 :
200
200
try :
201
201
def parfun (i ):
202
- return fit_least_squares (bvalues , dw_data [i , :], fitS0 = fitS0 , bounds = bounds )
202
+ return fit_least_squares (bvalues , dw_data [i , :], fitS0 = fitS0 , bounds = bounds , p0 = p0 )
203
203
204
204
output = Parallel (n_jobs = njobs )(delayed (parfun )(i ) for i in tqdm (range (len (dw_data )), position = 0 , leave = True ))
205
205
Dt , Fp , Dp = np .transpose (output )
@@ -213,12 +213,12 @@ def parfun(i):
213
213
Fp = np .zeros (len (dw_data ))
214
214
for i in range (len (dw_data )):
215
215
Dt [i ], Fp [i ], Dp [i ] = fit_least_squares (bvalues , dw_data [i , :], S0_output = S0_output , fitS0 = fitS0 ,
216
- bounds = bounds )
216
+ bounds = bounds , p0 = p0 )
217
217
return [Dt , Fp , Dp ]
218
218
219
219
220
220
def fit_least_squares (bvalues , dw_data , S0_output = False , fitS0 = True ,
221
- bounds = ([0 , 0 , 0.005 , 0.7 ],[0.005 , 0.7 , 0.2 , 1.3 ])):
221
+ bounds = ([0 , 0 , 0.005 , 0.7 ],[0.005 , 0.7 , 0.2 , 1.3 ]), p0 = [ 1 , 1 , 0.1 , 1 ] ):
222
222
"""
223
223
This is an implementation of the conventional IVIM fit. It fits a single curve
224
224
:param bvalues: Array with the b-values
@@ -242,7 +242,7 @@ def fit_least_squares(bvalues, dw_data, S0_output=False, fitS0=True,
242
242
# bounds are rescaled such that each parameter changes at roughly the same rate to help fitting.
243
243
bounds = ([bounds [0 ][0 ] * 1000 , bounds [0 ][1 ] * 10 , bounds [0 ][2 ] * 10 , bounds [0 ][3 ]],
244
244
[bounds [1 ][0 ] * 1000 , bounds [1 ][1 ] * 10 , bounds [1 ][2 ] * 10 , bounds [1 ][3 ]])
245
- params , _ = curve_fit (ivimN , bvalues , dw_data , p0 = [ 1 , 1 , 0.1 , 1 ] , bounds = bounds )
245
+ params , _ = curve_fit (ivimN , bvalues , dw_data , p0 = p0 , bounds = bounds )
246
246
S0 = params [3 ]
247
247
# correct for the rescaling of parameters
248
248
Dt , Fp , Dp = params [0 ] / 1000 , params [1 ] / 10 , params [2 ] / 10
@@ -563,7 +563,6 @@ def fit_bayesian_array(bvalues, dw_data, paramslsq, arg):
563
563
:return Dp: Array with Dp in each voxel
564
564
:return S0: Array with S0 in each voxel
565
565
"""
566
- arg = checkarg_lsq (arg )
567
566
# fill out missing args
568
567
Dt0 , Fp0 , Dp0 , S00 = paramslsq
569
568
# determine prior
0 commit comments