def test4(self): """ fit 2 data concatenates with limited range of x and one model """ #load data l = Loader() data1 = l.load("testdata_line.txt") data1.name = data1.filename data2 = l.load("testdata_line1.txt") data2.name = data2.filename # Receives the type of model for the fitting model1 = LineModel() model1.name= "M1" model1.setParam("A", 1.0) model1.setParam("B",1.0) model = Model(model1,data1) pars1= ['A','B'] #Importing the Fit module fitter = Fit() fitter.set_data(data1,1,qmin=0, qmax=7) fitter.set_model(model,1,pars1) fitter.set_data(data2,1,qmin=1,qmax=10) fitter.select_problem_for_fit(id=1,value=1) result2, = fitter.fit(handler=FitHandler()) self.assert_(result2) self.assertTrue( math.fabs(result2.pvec[0]-4)/3 <= result2.stderr[0] ) self.assertTrue( math.fabs(result2.pvec[1]-2.5)/3 <= result2.stderr[1] ) self.assertTrue( result2.fitness/len(data1.x) < 2)
def test4(self): """ fit 2 data concatenates with limited range of x and one model """ #load data l = Loader() data1 = l.load("testdata_line.txt") data1.name = data1.filename data2 = l.load("testdata_line1.txt") data2.name = data2.filename # Receives the type of model for the fitting model1 = LineModel() model1.name = "M1" model1.setParam("A", 1.0) model1.setParam("B", 1.0) model = Model(model1, data1) pars1 = ['A', 'B'] #Importing the Fit module fitter = Fit('bumps') fitter.set_data(data1, 1, qmin=0, qmax=7) fitter.set_model(model, 1, pars1) fitter.set_data(data2, 1, qmin=1, qmax=10) fitter.select_problem_for_fit(id=1, value=1) result2, = fitter.fit(handler=FitHandler()) self.assert_(result2) self.assertTrue( math.fabs(result2.pvec[0] - 4) / 3 <= result2.stderr[0]) self.assertTrue( math.fabs(result2.pvec[1] - 2.5) / 3 <= result2.stderr[1]) self.assertTrue(result2.fitness / len(data1.x) < 2)
def test_constraints(self): """ fit 2 data and 2 model with 1 constrainst""" #load data l = Loader() data1= l.load("testdata_line.txt") data1.name = data1.filename data2= l.load("testdata_cst.txt") data2.name = data2.filename # Receives the type of model for the fitting model11 = LineModel() model11.name= "line" model11.setParam("A", 1.0) model11.setParam("B",1.0) model22 = Constant() model22.name= "cst" model22.setParam("value", 1.0) model1 = Model(model11,data1) model2 = Model(model22,data2) model1.set(A=4) model1.set(B=3) # Constraint the constant value to be equal to parameter B (the real value is 2.5) #model2.set(value='line.B') pars1= ['A','B'] pars2= ['value'] #Importing the Fit module fitter = Fit() fitter.set_data(data1,1) fitter.set_model(model1,1,pars1) fitter.set_data(data2,2,smearer=None) fitter.set_model(model2,2,pars2,constraints=[("value","line.B")]) fitter.select_problem_for_fit(id=1,value=1) fitter.select_problem_for_fit(id=2,value=1) R1,R2 = fitter.fit(handler=FitHandler()) self.assertTrue( math.fabs(R1.pvec[0]-4.0)/3. <= R1.stderr[0]) self.assertTrue( math.fabs(R1.pvec[1]-2.5)/3. <= R1.stderr[1]) self.assertTrue( R1.fitness/(len(data1.x)+len(data2.x)) < 2)
def test_constraints(self): """ fit 2 data and 2 model with 1 constrainst""" #load data l = Loader() data1 = l.load("testdata_line.txt") data1.name = data1.filename data2 = l.load("testdata_cst.txt") data2.name = data2.filename # Receives the type of model for the fitting model11 = LineModel() model11.name = "line" model11.setParam("A", 1.0) model11.setParam("B", 1.0) model22 = Constant() model22.name = "cst" model22.setParam("value", 1.0) model1 = Model(model11, data1) model2 = Model(model22, data2) model1.set(A=4) model1.set(B=3) # Constraint the constant value to be equal to parameter B (the real value is 2.5) #model2.set(value='line.B') pars1 = ['A', 'B'] pars2 = ['value'] #Importing the Fit module fitter = Fit('bumps') fitter.set_data(data1, 1) fitter.set_model(model1, 1, pars1) fitter.set_data(data2, 2, smearer=None) fitter.set_model(model2, 2, pars2, constraints=[("value", "line.B")]) fitter.select_problem_for_fit(id=1, value=1) fitter.select_problem_for_fit(id=2, value=1) R1, R2 = fitter.fit(handler=FitHandler()) self.assertTrue(math.fabs(R1.pvec[0] - 4.0) / 3. <= R1.stderr[0]) self.assertTrue(math.fabs(R1.pvec[1] - 2.5) / 3. <= R1.stderr[1]) self.assertTrue(R1.fitness / (len(data1.x) + len(data2.x)) < 2)