src.original.fitting.OGC_AmsterdamUMC package
Submodules
src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting module
September 2020 by Oliver Gurney-Champion oliver.gurney.champion@gmail.com / o.j.gurney-champion@amsterdamumc.nl https://www.github.com/ochampion
requirements: numpy tqdm matplotlib scipy joblib
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.MSE(bvalues, Dt, Fp, Dp, S0, dw_data)[source]
Calculates the MSE as a measure for goodness of fit. input parameters are :param b: 1D Array b-values :param Dt: 1D Array with fitted D :param Fp: 1D Array with fitted f :param Dp: 1D Array with fitted D* :param S0: 1D Array with fitted S0 (or ones) :param dw_data: 2D array containing data, as voxels x b-values :return MSError: 1D Array with the R-squared for each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.empirical_neg_log_prior(Dt0, Fp0, Dp0, S00=None)[source]
This function determines the negative of the log of the empirical prior probability of the IVIM parameters :param Dt0: 1D Array with the initial D estimates :param Dt0: 1D Array with the initial f estimates :param Dt0: 1D Array with the initial D* estimates :param Dt0: 1D Array with the initial S0 estimates (optional)
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_bayesian(bvalues, dw_data, neg_log_prior, x0=[0.001, 0.2, 0.05, 1], fitS0=True, bounds=([0, 0, 0, 0], [0.005, 1.5, 2, 2.5]))[source]
This is an implementation of the Bayesian IVIM fit. It returns the Maximum a posterior probability. The fit is taken from Barbieri et al. which was initially introduced in http://arxiv.org/10.1002/mrm.25765 and later further improved in http://arxiv.org/abs/1903.00095. If found useful, please cite those papers. :param bvalues: Array with the b-values :param dw_data: 1D Array with diffusion-weighted signal at different b-values :param neg_log_prior: the prior :param x0: 1D array with initial parameter guess :param fitS0: boolean, if set to False, S0 is not fitted :return Dt: estimated D :return Fp: estimated f :return Dp: estimated D* :return S0: estimated S0 (optional)
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_bayesian_array(bvalues, dw_data, paramslsq, arg)[source]
This is an implementation of the Bayesian IVIM fit for arrays. The fit is taken from Barbieri et al. which was initially introduced in http://arxiv.org/10.1002/mrm.25765 and later further improved in http://arxiv.org/abs/1903.00095. If found useful, please cite those papers. :param bvalues: Array with the b-values :param dw_data: 2D Array with diffusion-weighted signal in different voxels at different b-values :param paramslsq: 2D Array with initial estimates for the parameters. These form the base for the Bayesian prior distribution and are typically obtained by least squares fitting of the data :param arg: an object with fit options, with attributes: arg.fitS0 –> Boolean; False fixes S0 to 1, True fits S0 arg.jobs –> Integer specifying the number of parallel processes used in fitting. If <2, regular fitting is used instead arg.bounds –> 2D Array of fit bounds ([Dtmin, Fpmin, Dpmin, S0min],[Dtmax, Fpmax, Dpmax, S0max]) :return Dt: Array with D in each voxel :return Fp: Array with f in each voxel :return Dp: Array with Dp in each voxel :return S0: Array with S0 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_least_squares(bvalues, dw_data, S0_output=False, fitS0=True, bounds=([0, 0, 0.005, 0.7], [0.005, 0.7, 0.2, 1.3]), p0=[0.001, 0.1, 0.01, 1])[source]
This is an implementation of the conventional IVIM fit. It fits a single curve :param bvalues: Array with the b-values :param dw_data: Array with diffusion-weighted signal at different b-values :param S0_output: Boolean determining whether to output (often a dummy) variable S0; default = True :param fix_S0: Boolean determining whether to fix S0 to 1; default = False :param bounds: Array with fit bounds ([Dtmin, Fpmin, Dpmin, S0min],[Dtmax, Fpmax, Dpmax, S0max]). Default: ([0.005, 0, 0, 0.8], [0.2, 0.7, 0.005, 1.2]) :return Dt: Array with D in each voxel :return Fp: Array with f in each voxel :return Dp: Array with Dp in each voxel :return S0: Array with S0 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_least_squares_array(bvalues, dw_data, S0_output=True, fitS0=True, njobs=4, bounds=([0, 0, 0.005, 0.7], [0.005, 0.7, 0.2, 1.3]), p0=[0.001, 0.1, 0.01, 1])[source]
This is an implementation of the conventional IVIM fit. It is fitted in array form. :param bvalues: 1D Array with the b-values :param dw_data: 2D Array with diffusion-weighted signal in different voxels at different b-values :param S0_output: Boolean determining whether to output (often a dummy) variable S0; default = True :param fix_S0: Boolean determining whether to fix S0 to 1; default = False :param njobs: Integer determining the number of parallel processes; default = 4 :param bounds: Array with fit bounds ([Dtmin, Fpmin, Dpmin, S0min],[Dtmax, Fpmax, Dpmax, S0max]). Default: ([0.005, 0, 0, 0.8], [0.2, 0.7, 0.005, 1.2]) :return Dt: 1D Array with D in each voxel :return Fp: 1D Array with f in each voxel :return Dp: 1D Array with Dp in each voxel :return S0: 1D Array with S0 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_least_squares_array_tri_exp(bvalues, dw_data, S0_output=True, fitS0=True, njobs=4, bounds=([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]))[source]
This is an implementation of a tri-exponential fit. It is fitted in array form. :param bvalues: 1D Array with the b-values :param dw_data: 2D Array with diffusion-weighted signal in different voxels at different b-values :param S0_output: Boolean determining whether to output (often a dummy) variable S0; default = True :param fix_S0: Boolean determining whether to fix S0 to 1; default = False :param njobs: Integer determining the number of parallel processes; default = 4 :param bounds: Array with fit bounds ([fp0min, Dtmin, Fp1min, Dp1min, Fp2min, Dp2min],[fp0max, Dtmax, Fp1max, Dp1max, Fp2max, Dp2max]). Default: ([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]) :return S0: optional 1D Array with S0 in each voxel :return Dt: 1D Array with D in each voxel :return Fp1: 1D Array with Fp1 in each voxel :return Dp1: 1D Array with Dp1 in each voxel :return Fp2: 1D Array with Fp2 in each voxel :return Dp2: 1D Array with Dp2 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_least_squares_tri_exp(bvalues, dw_data, S0_output=False, fitS0=True, bounds=([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]))[source]
This is an implementation of the tri-exponential fit. It fits a single curve :param bvalues: 1D Array with the b-values :param dw_data: 2D Array with diffusion-weighted signal in different voxels at different b-values :param S0_output: Boolean determining whether to output (often a dummy) variable S0; default = True :param fix_S0: Boolean determining whether to fix S0 to 1; default = False :param bounds: Array with fit bounds ([fp0min, Dtmin, Fp1min, Dp1min, Fp2min, Dp2min],[fp0max, Dtmax, Fp1max, Dp1max, Fp2max, Dp2max]). Default: ([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]) :return Fp0: optional 1D Array with f0 in each voxel :return Dt: 1D Array with D in each voxel :return Fp1: 1D Array with fp1 in each voxel :return Dp1: 1D Array with Dp1 in each voxel :return Fp2: 1D Array with the fraciton of signal for Dp2 in each voxel :return Dp2: 1D Array with Dp2 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_segmented(bvalues, dw_data, bounds=([0, 0, 0.005], [0.005, 0.7, 0.2]), cutoff=75, p0=[0.001, 0.1, 0.01, 1])[source]
This is an implementation of the segmented fit, in which we first estimate D using a curve fit to b-values>cutoff; then estimate f from the fitted S0 and the measured S0 and finally estimate D* while fixing D and f. :param bvalues: Array with the b-values :param dw_data: Array with diffusion-weighted signal at different b-values :param bounds: Array with fit bounds ([Dtmin, Fpmin, Dpmin, S0min],[Dtmax, Fpmax, Dpmax, S0max]). Default: ([0.005, 0, 0, 0.8], [0.2, 0.7, 0.005, 1.2]) :param cutoff: cutoff value for determining which data is taken along in fitting D :return Dt: Fitted D :return Fp: Fitted f :return Dp: Fitted Dp :return S0: Fitted S0
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_segmented_array(bvalues, dw_data, njobs=4, bounds=([0, 0, 0.005], [0.005, 0.7, 0.2]), cutoff=75, p0=[0.001, 0.1, 0.01, 1])[source]
This is an implementation of the segmented fit, in which we first estimate D using a curve fit to b-values>cutoff; then estimate f from the fitted S0 and the measured S0 and finally estimate D* while fixing D and f. This fit is done on an array. :param bvalues: 1D Array with the b-values :param dw_data: 2D Array with diffusion-weighted signal in different voxels at different b-values :param njobs: Integer determining the number of parallel processes; default = 4 :param bounds: 2D Array with fit bounds ([Dtmin, Fpmin, Dpmin, S0min],[Dtmax, Fpmax, Dpmax, S0max]). Default: ([0.005, 0, 0, 0.8], [0.2, 0.7, 0.005, 1.2]) :param cutoff: cutoff value for determining which data is taken along in fitting D :return Dt: 1D Array with D in each voxel :return Fp: 1D Array with f in each voxel :return Dp: 1D Array with Dp in each voxel :return S0: 1D Array with S0 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_segmented_array_tri_exp(bvalues, dw_data, njobs=4, bounds=([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]), cutoff=[15, 120])[source]
This is an implementation of the segmented fit for a tri-exp model, in which we first estimate D using a curve fit to b-values>cutoff; then estimate f from the fitted S0 and the measured S0 and finally estimate D* while fixing D and f. This fit is done on an array. :param bvalues: 1D Array with the b-values :param dw_data: 2D Array with diffusion-weighted signal in different voxels at different b-values :param njobs: Integer determining the number of parallel processes; default = 4 :param bounds: Array with fit bounds ([fp0min, Dtmin, Fp1min, Dp1min, Fp2min, Dp2min],[fp0max, Dtmax, Fp1max, Dp1max, Fp2max, Dp2max]). Default: ([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]) :param cutoff: 2 cutoff values for determining which data is taken along in fitting D, and subsequently D* and F :return S0: 1D Array with S0 in each voxel :return Dt: 1D Array with D in each voxel :return Fp1: 1D Array with Fp1 in each voxel :return Dp1: 1D Array with Dp1 in each voxel :return Fp2: 1D Array with Fp2 in each voxel :return Dp2: 1D Array with Dp2 in each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.fit_segmented_tri_exp(bvalues, dw_data, bounds=([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]), cutoff=[15, 120])[source]
This is an implementation of the segmented fit, in which we first estimate D using a curve fit to b-values>cutoff; then estimate f from the fitted S0 and the measured S0 and finally estimate D* while fixing D and f. :param bvalues: Array with the b-values :param dw_data: Array with diffusion-weighted signal at different b-values :param bounds: Array with fit bounds ([fp0min, Dtmin, Fp1min, Dp1min, Fp2min, Dp2min],[fp0max, Dtmax, Fp1max, Dp1max, Fp2max, Dp2max]). Default: ([0, 0, 0, 0.005, 0, 0.06], [2.5, 0.005, 1, 0.06, 1, 0.5]) :param cutoff: 2 cutoff values for determining which data is taken along in fitting D, and subsequently D* and F :return Fp0: 1D Array with Fp1 in each voxel :return Dt: Fitted D :return Fp1: Fitted f :return Dp1: Fitted Dp :return Fp2: Fitted Fp2 :return Dp2: Fitted Dp2
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.flat_neg_log_prior(Dt_range, Fp_range, Dp_range, S0_range=None)[source]
This function determines the negative of the log of the empirical prior probability of the IVIM parameters :param Dt0: 1D Array with the initial D estimates :param Dt0: 1D Array with the initial f estimates :param Dt0: 1D Array with the initial D* estimates :param Dt0: 1D Array with the initial S0 estimates (optional)
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.goodness_of_fit(bvalues, Dt, Fp, Dp, S0, dw_data, Fp2=None, Dp2=None)[source]
Calculates the R-squared as a measure for goodness of fit. input parameters are :param b: 1D Array b-values :param Dt: 1D Array with fitted D :param Fp: 1D Array with fitted f :param Dp: 1D Array with fitted D* :param S0: 1D Array with fitted S0 (or ones) :param dw_data: 2D array containing data, as voxels x b-values :return R2: 1D Array with the R-squared for each voxel
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.neg_log_likelihood(p, bvalues, dw_data)[source]
This function determines the negative of the log of the likelihood of parameters p, given the data dw_data for the Bayesian fit :param p: 1D Array with the estimates of D, f, D* and (optionally) S0 :param bvalues: 1D array with b-values :param dw_data: 1D Array diffusion-weighted data :returns: the log-likelihood of the parameters given the data
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.neg_log_posterior(p, bvalues, dw_data, neg_log_prior)[source]
This function determines the negative of the log of the likelihood of parameters p, given the prior likelihood and the data :param p: 1D Array with the estimates of D, f, D* and (optionally) S0 :param bvalues: 1D array with b-values :param dw_data: 1D Array diffusion-weighted data :param neg_log_prior: prior likelihood function (created with empirical_neg_log_prior) :returns: the posterior probability given the data and the prior
- src.original.fitting.OGC_AmsterdamUMC.LSQ_fitting.tri_exp(bvalues, Fp0, Dt, Fp1, Dp1, Fp2, Dp2)[source]