def setUpClass(cls): "===Exponential_decay_Jacobian===" pnames = ['p1', 'p2', 'p3'] def func(var, x): return var[0] * np.exp(-var[1] * x) + var[2] def dfunc(var, x): v = np.exp(-var[1] * x) return np.array([-v, +var[0] * x * v, -np.ones(len(x))]).T cls.function = func cls.jacobian = dfunc model = fit.Function(function=func, par_names=pnames, jacobian=dfunc) pars = [10, 10, 10] bounds = [(0, 20), (0, 20), (0, 20)] vary = [True, True, True] model.setup_parameters(values=pars, bounds=bounds, vary=vary) cls._model = model #-- Creating data to fit xs = np.linspace(0, 4, 50) ys = func([2.5, 1.3, 0.5], xs) np.random.seed(3333) err = 0.1 * np.random.normal(size=len(xs)) yn = ys + err cls.x = xs cls.y = yn cls.err = np.abs(err)
def setUpClass(cls): #-- setup the function pnames = ['ampl', 'freq', 'phase'] function = lambda p, x: p[0] * np.sin(2 * np.pi * (p[1] * x + p[2])) Dfunction = lambda p, x: p[0] * np.cos(2 * np.pi * (p[1] * x + p[2])) fitFunc = fit.Function(function=function, par_names=pnames) value = [1.5, 0.12, 3.14] bounds = [[1.0, 2.0], [0.0, 0.25], [0.0, 6.28]] vary = [True, True, True] fitFunc.setup_parameters(values=value, bounds=bounds, vary=vary) #-- create fake data x = np.linspace(0, 10, 1000) np.random.seed(1111) y = fitFunc.evaluate(x) + np.random.normal( loc=0.0, scale=0.1, size=1000) #-- Change starting parameters fitFunc.update_parameter(parameter='ampl', values=1.2) fitFunc.update_parameter(parameter='freq', values=0.10) fitFunc.update_parameter(parameter='phase', values=3.0) cls.x = x cls.y = y cls.pnames = pnames cls.value = value cls.fitFunc = fitFunc cls.dFunc = Dfunction
def setUp(self): self.pnames1 = ['p1', 'p2'] self.function1 = lambda p, x: p[0] + p[1] * x self.func1 = fit.Function(function=self.function1, par_names=self.pnames1) self.values1 = [2.5, 1.0] self.func1.setup_parameters(values=self.values1) self.pnames2 = ['p3', 'p4'] self.function2 = lambda p, x: p[0] * x**2 + p[1] * x**3 self.func2 = fit.Function(function=self.function2, par_names=self.pnames2) self.values2 = [-1.0, 0.5] self.func2.setup_parameters(values=self.values2) self.mexpr = lambda x: x[0] + x[1] self.model = fit.Model(functions=[self.func1, self.func2], expr=self.mexpr)
def setUp(self): self.pnames = ['ampl', 'freq', 'phase'] self.function = lambda p, x: p[0] * np.sin(2 * np.pi * (p[1] * x + p[2])) self.Dfunction = lambda p, x: p[0] * np.cos(2 * np.pi * (p[1] * x + p[2])) self.model = fit.Function(function=self.function, par_names=self.pnames,\ jacobian=self.Dfunction) self.value = [1.5, 0.12, 3.14] self.bounds = [[1.0, 2.0], [-0.20, 0.20], [0.0, 6.24]] self.vary = [True, True, True] self.expression = ['<10', None, None] self.model.setup_parameters(values=self.value, bounds=self.bounds, vary=self.vary,\ exprs=self.expression)