1
+ from src .wrappers .OsipiBase import OsipiBase
2
+ from src .original .OGC_AmsterdamUMC .LSQ_fitting import flat_neg_log_prior , fit_bayesian
3
+ import numpy as np
4
+
5
+ class OGC_AmsterdamUMC_Bayesian_biexp (OsipiBase ):
6
+ """
7
+ Bayesian Bi-exponential fitting algorithm by Oliver Gurney-Champion, Amsterdam UMC
8
+ """
9
+
10
+ # I'm thinking that we define default attributes for each submission like this
11
+ # And in __init__, we can call the OsipiBase control functions to check whether
12
+ # the user inputs fulfil the requirements
13
+
14
+ # Some basic stuff that identifies the algorithm
15
+ id_author = "Oliver Gurney Champion, Amsterdam UMC"
16
+ id_algorithm_type = "Bi-exponential fit"
17
+ id_return_parameters = "f, D*, D, S0"
18
+ id_units = "seconds per milli metre squared or milliseconds per micro metre squared"
19
+
20
+ # Algorithm requirements
21
+ required_bvalues = 4
22
+ required_thresholds = [0 ,
23
+ 0 ] # Interval from "at least" to "at most", in case submissions allow a custom number of thresholds
24
+ required_bounds = False
25
+ required_bounds_optional = True # Bounds may not be required but are optional
26
+ required_initial_guess = False
27
+ required_initial_guess_optional = True
28
+ accepted_dimensions = 1 # Not sure how to define this for the number of accepted dimensions. Perhaps like the thresholds, at least and at most?
29
+
30
+ def __init__ (self , bvalues = None , bounds = ([0 , 0 , 0.005 , 0.7 ],[0.005 , 0.7 , 0.2 , 1.3 ]), initial_guess = None , fitS0 = True , thresholds = None ):
31
+ """
32
+ Everything this algorithm requires should be implemented here.
33
+ Number of segmentation thresholds, bounds, etc.
34
+
35
+ Our OsipiBase object could contain functions that compare the inputs with
36
+ the requirements.
37
+ """
38
+ super (OGC_AmsterdamUMC_Bayesian_biexp , self ).__init__ (bvalues , bounds ,initial_guess ,fitS0 )
39
+ if bounds is None :
40
+ self .bounds = ([0 , 0 , 0.005 , 0.7 ],[0.005 , 0.7 , 0.2 , 1.3 ])
41
+ else :
42
+ self .bounds = bounds
43
+ self .neg_log_prior = flat_neg_log_prior ([self .bounds [0 ][0 ],self .bounds [1 ][0 ]],[self .bounds [0 ][1 ],self .bounds [1 ][1 ]],[self .bounds [0 ][1 ],self .bounds [1 ][1 ]],[self .bounds [0 ][2 ],self .bounds [1 ][2 ]])
44
+ self .OGC_algorithm = fit_bayesian
45
+ self .bounds = bounds
46
+ self .initial_guess = initial_guess
47
+ self .fitS0 = fitS0
48
+
49
+ def ivim_fit (self , signals , bvalues = None ):
50
+ """Perform the IVIM fit
51
+
52
+ Args:
53
+ signals (array-like)
54
+ bvalues (array-like, optional): b-values for the signals. If None, self.bvalues will be used. Default is None.
55
+
56
+ Returns:
57
+ _type_: _description_
58
+ """
59
+ bvalues = np .array (bvalues )
60
+ fit_results = self .OGC_algorithm (bvalues , signals , self .neg_log_prior , x0 = self .initial_guess , fitS0 = self .fitS0 )
61
+
62
+ D = fit_results [0 ]
63
+ f = fit_results [1 ]
64
+ Dstar = fit_results [2 ]
65
+
66
+ return f , Dstar , D
0 commit comments