-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitfunctions.py
188 lines (142 loc) · 7.12 KB
/
fitfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import numpy as np
import fit_parents as fp
class cosh(fp.mass_amp, fp.periodic):
def __init__(self, Nt=None):
super(cosh, self).__init__()
self.setNt(Nt)
self.description = "cosh"
self.template = "{1: f}Cosh(-{0: f}*(t-%d/2))" % self.Nt
def formula(self, v, x):
#return ((2*v[1])/np.exp(v[0]*Nt/2.0) * np.cosh((-1.0)* v[0]*((x-(Nt/2.0)))))
return (v[1] * np.cosh((-1.0)*v[0]*((x-(self.Nt/2.0)))))
class single_exp(fp.mass_amp):
def __init__(self, **kargs):
super(single_exp, self).__init__()
self.description = "exp"
self.template = "{1: f}exp(-{0: f}*t)"
def formula(self, v, x):
return (v[1] * np.exp((-1.0) * v[0] * x))
class periodic_exp(fp.mass_amp, fp.periodic):
def __init__(self, Nt=None):
super(periodic_exp, self).__init__()
self.setNt(Nt)
self.description = "fwd-back-exp"
self.template = "{1: f}(exp(-{0: f}*t)+exp(-{0: f}*(t-%d))" % self.Nt
def formula(self, v, x):
return (v[1] * (np.exp((-1.0) * v[0] * x) + np.exp(v[0] * (x-(self.Nt)))))
class antiperiodic_exp(fp.mass_amp, fp.periodic):
def __init__(self, Nt=None):
super(antiperiodic_exp, self).__init__()
self.setNt(Nt)
self.description = "sinh"
self.template = "{1: f}(exp(-{0: f}*t)-exp(-{0: f}*(t-%d))" % self.Nt
def formula(self, v, x):
return (v[1] * (np.exp((-1.0) * v[0] * x) - np.exp(v[0] * (x-(self.Nt)))))
class periodic_exp_subtracted(fp.mass_amp, fp.periodic):
def __init__(self, Nt=None):
super(periodic_exp_subtracted, self).__init__()
self.setNt(Nt)
self.description = "fwd-back-exp subtracted"
self.subtract = 1
self.template = "{1: f}(exp(-{0: f}*t)+exp(-{0: f}*(t-%d)) - {1: f}(exp(-{0: f}*%d)+exp(-{0: f}*(%d-%d)) - " % (self.Nt, self.subtract, self.subtract, self.Nt)
self.fallback = None
def formula(self, v, x):
return (v[1] * (np.exp((-1.0) * v[0] * x) + np.exp(v[0] * (x-(self.Nt))))) - (v[1] * (np.exp((-1.0) * v[0] * self.subtract) + np.exp(v[0] * (self.subtract-(self.Nt)))))
class periodic_exp_const(fp.mass_amp_const, fp.periodic):
def __init__(self, Nt=None):
super(periodic_exp_const, self).__init__()
self.setNt(Nt)
self.description = "fwd-back-exp_const"
self.template = "{1: f}(exp(-{0: f}*t)+exp(-{0: f}*(t-%d))+{2: f}" % self.Nt
def formula(self, v, x):
return (v[1] * (np.exp((-1.0) * v[0] * x) + np.exp(v[0] * (x-(self.Nt)))))+v[2]
class cosh_const(fp.mass_amp_const, fp.periodic):
def __init__(self, Nt=None):
super(cosh_const, self).__init__()
self.setNt(Nt)
self.description = "cosh+const"
self.template = "{1: f}Cosh(-{0: f}*(t-%d/2))+{2: f}" % self.Nt
def formula(self, v, x):
return (v[1] * np.cosh((-1.0)*v[0]*((x-(self.Nt/2.0)))))+v[2]
class two_exp(fp.twice_mass_amp):
def __init__(self, **kargs):
super(two_exp, self).__init__()
self.description = "two_exp"
self.template = "{1: f}exp(-{0: f}*t)(1+{3: f}exp(-{2: f}^2*t)"
self.fallback = "single_exp"
def formula(self, v, x):
return (v[1] * np.exp((-1.0) * v[0] * x)*(1.0 + v[3]*np.exp((-1.0)*(v[2]**2)*x)))
class periodic_two_exp(fp.twice_mass_amp, fp.periodic):
def __init__(self, Nt=None):
super(periodic_two_exp, self).__init__()
self.setNt(Nt)
self.description = "periodic_two_exp"
self.template = "{1: f}exp(-{0: f}*t)(1+{3: f}exp(-{2: f}^2*t)"
self.fallback = "periodic_exp"
def formula(self, v, x):
return ((v[1]*np.exp((-1.0)*v[0]*x)*(1.0 + v[3]*np.exp((-1.0)*(v[2]**2)*x))) +
(v[1]*np.exp(v[0]*(x-(self.Nt)))*(1.0 + v[3]*np.exp((v[2]**2)*(x-(self.Nt)))))) # noqa
class periodic_two_exp_subtracted(fp.twice_mass_amp, fp.periodic):
def __init__(self, Nt=None):
super(periodic_two_exp_subtracted, self).__init__()
self.setNt(Nt)
self.description = "periodic_two_exp_subtracted"
self.subtract = 1
self.template = "{1: f}exp(-{0: f}*t)(1+{3: f}exp(-{2: f}^2*t)"
self.fallback = None
def formula(self, v, x):
return (((v[1]*np.exp((-1.0)*v[0]*x)*(1.0 + v[3]*np.exp((-1.0)*(v[2]**2)*x))) +
(v[1]*np.exp(v[0]*(x-(self.Nt)))*(1.0 + v[3]*np.exp((v[2]**2)*(x-(self.Nt)))))) -
((v[1]*np.exp((-1.0)*v[0]*self.subtract)*(1.0 + v[3]*np.exp((-1.0)*(v[2]**2)*self.subtract))) +
(v[1]*np.exp(v[0]*(self.subtract-(self.Nt)))*(1.0 + v[3]*np.exp((v[2]**2)*(self.subtract-(self.Nt))))))) # noqa
class periodic_two_exp_const(fp.twice_mass_amp_const, fp.periodic):
def __init__(self, Nt=None):
super(periodic_two_exp_const, self).__init__()
self.setNt(Nt)
self.description = "periodic_two_exp_const"
self.template = "{1: f}exp(-{0: f}*t)(1+{3: f}exp(-{2: f}^2*t)+{4: f}"
self.fallback = "periodic_exp_const"
def formula(self, v, x):
return ((v[1]*np.exp((-1.0)*v[0]*x)*(1.0 + v[3]*np.exp((-1.0)*(v[2]**2)*x))) +
(v[1]*np.exp(v[0]*(x-(self.Nt)))*(1.0 + v[3]*np.exp((v[2]**2)*(x-(self.Nt))))))+v[4] # noqa
# def pade_guess(*args, **kargs):
# first_two = fit_parents.massamp_guess(args[0], args[1])
# return [first_two[0], first_two[1], 0.0]
# mass_bounds = (0.005, 2.0)
# amp_bounds = (0.0, 1000.0)
# class pade:
# """ exp( - E * t ) * A / ( 1 + a1* t + a2 * t^2 ... ) """
# def __init__(self, Nt=None):
# self.starting_guess = pade_guess
# self.bounds = [mass_bounds, amp_bounds, (-100.0,100.0)]
# self.parameter_names = ["mass", "amp", "B"]
# self.description = "Pade"
# self.template = "{1: f}exp(-{0: f}*t)/(1+{3: f}t)"
# def formula(self, v, x):
# return (v[1]*np.exp((-1.0)*v[0]*x)) / (1.0 + v[2]*x)
# def my_cov_fun(self, mass, amp, B):
# vect = self.aoc - self.formula((mass, amp, B), self.times)
# return vect.dot(self.inv_cov).dot(vect)
# def custom_minuit(self, data, invmatrix, times, guess):
# self.aoc = data
# self.inv_cov = invmatrix
# self.times = times
# m = Minuit(self.my_cov_fun, mass=guess[0], amp=guess[1], B=guess[2],
# print_level=0, pedantic=False, limit_mass=mass_bounds)
# return m
# class jlab:
# def __init__(self, **kargs):
# self.starting_guess = twoexp_sqr_guess
# self.parameter_names = ["mass", "amp", "mass2"]
# self.description = "jlab"
# self.template = "{1: f}exp(-{0: f}*t)+{1: f}exp(-{2: f}*t)"
# def formula(self, v, x):
# return ((1 - v[1]) * np.exp((-1.0) * v[0] * x))+(v[1] * np.exp((-1.0) * v[2] * x))
# class twocor_periodic_exp(twocor_sharedmass_amp, fp.periodic):
# def __init__(self, Nt=None):
# super(twocor_periodic_exp, self).__init__()
# self.setNt(Nt)
# self.description = "two_cor-fwd-back-exp"
# self.template = "{1: f}(exp(-{0: f}*t)+exp(-{0: f}*(t-%d))" % self.Nt
# def formula(self, v, x):
# return (v[1] * (np.exp((-1.0) * v[0] * x) + np.exp(v[0] * (x-(self.Nt)))))