Example #1
0
    def fit_single(self, isdream=False):
        fitter = Fit()

        data = Loader().load("testdata_line.txt")
        data.name = data.filename
        fitter.set_data(data,1)

        # Receives the type of model for the fitting
        model1  = LineModel()
        model1.name = "M1"
        model = Model(model1,data)

        pars1= ['A','B']
        fitter.set_model(model,1,pars1)
        fitter.select_problem_for_fit(id=1,value=1)
        result1, = fitter.fit(handler=FitHandler())

        # The target values were generated from the following statements
        p,s,fx = result1.pvec, result1.stderr, result1.fitness
        #print "p0,p1,s0,s1,fx = %g, %g, %g, %g, %g"%(p[0],p[1],s[0],s[1],fx)
        p0,p1,s0,s1,fx_ = 3.68353, 2.61004, 0.336186, 0.105244, 1.20189

        if isdream:
            # Dream is not a minimizer: just check that the fit is within
            # uncertainty
            self.assertTrue( abs(p[0]-p0) <= s0 )
            self.assertTrue( abs(p[1]-p1) <= s1 )
        else:
            self.assertTrue( abs(p[0]-p0) <= 1e-5 )
            self.assertTrue( abs(p[1]-p1) <= 1e-5 )
            self.assertTrue( abs(fx-fx_) <= 1e-5 )
Example #2
0
    def fit_single(self, fitter_name, isdream=False):
        fitter = Fit(fitter_name)

        data = Loader().load("testdata_line.txt")
        data.name = data.filename
        fitter.set_data(data, 1)

        # Receives the type of model for the fitting
        model1 = LineModel()
        model1.name = "M1"
        model = Model(model1, data)

        pars1 = ['A', 'B']
        fitter.set_model(model, 1, pars1)
        fitter.select_problem_for_fit(id=1, value=1)
        result1, = fitter.fit(handler=FitHandler())

        # The target values were generated from the following statements
        p, s, fx = result1.pvec, result1.stderr, result1.fitness
        #print "p0,p1,s0,s1,fx = %g, %g, %g, %g, %g"%(p[0],p[1],s[0],s[1],fx)
        p0, p1, s0, s1, fx_ = 3.68353, 2.61004, 0.336186, 0.105244, 1.20189

        if isdream:
            # Dream is not a minimizer: just check that the fit is within
            # uncertainty
            self.assertTrue(abs(p[0] - p0) <= s0)
            self.assertTrue(abs(p[1] - p1) <= s1)
        else:
            self.assertTrue(abs(p[0] - p0) <= 1e-5)
            self.assertTrue(abs(p[1] - p1) <= 1e-5)
            self.assertTrue(abs(fx - fx_) <= 1e-5)
Example #3
0
    def test_bad_pars(self):
        fitter = Fit()

        data = Loader().load("testdata_line.txt")
        data.name = data.filename
        fitter.set_data(data,1)

        model1  = LineModel()
        model1.name = "M1"
        model = Model(model1, data)
        pars1= ['param1','param2']
        try:
            fitter.set_model(model,1,pars1)
        except ValueError,exc:
            #print "ValueError was correctly raised: "+str(msg)
            assert str(exc).startswith('parameter param1')
Example #4
0
    def test_bad_pars(self):
        fitter = Fit('bumps')

        data = Loader().load("testdata_line.txt")
        data.name = data.filename
        fitter.set_data(data, 1)

        model1 = LineModel()
        model1.name = "M1"
        model = Model(model1, data)
        pars1 = ['param1', 'param2']
        try:
            fitter.set_model(model, 1, pars1)
        except ValueError, exc:
            #print "ValueError was correctly raised: "+str(msg)
            assert str(exc).startswith('parameter param1')