source: sasview/park_integration/test/constrainttestpark.py @ 60dc5f2c

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 60dc5f2c was 202f93a, checked in by Gervaise Alina <gervyh@…>, 16 years ago

fixing fit , only fit parameters newly set in model

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"""
2    Unit tests for fitting module
3"""
4import unittest
5from sans.guitools.plottables import Theory1D
6from sans.guitools.plottables import Data1D
7from sans.fit.ScipyFitting import Parameter
8import math
9class testFitModule(unittest.TestCase):
10   
11    def test2models2dataonconstraint(self):
12        """ test fitting for two set of data  and one model with 2 constraint"""
13        from sans.fit.Loader import Load
14        load= Load()
15        #Load the first set of data
16        load.set_filename("testdata1.txt")
17        load.set_values()
18        data1 = Data1D(x=[], y=[],dx=None, dy=None)
19        load.load_data(data1)
20       
21        #Load the second set of data
22        load.set_filename("testdata2.txt")
23        load.set_values()
24        data2 = Data1D(x=[], y=[],dx=None, dy=None)
25        load.load_data(data2)
26       
27        #Importing the Fit module
28        from sans.fit.Fitting import Fit
29        fitter= Fit('park')
30        # Receives the type of model for the fitting
31        from sans.guitools.LineModel import LineModel
32        model1  = LineModel()
33        model2  = LineModel()
34       
35        #Do the fit
36       
37        fitter.set_model(model1,"M1",1, {'A':1,'B':2})
38        fitter.set_data(data1,1)
39       
40        fitter.set_model(model2,"M2",2, {'A':'M1.A','B':'M1.B'})
41        fitter.set_data(data2,2)
42   
43       
44        chisqr2, out2, cov2= fitter.fit()
45        print "chisqr2",chisqr2
46        print "out2", out2
47        print " cov2", cov2
48        print chisqr2/len(data1.x)
49       
50        self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2)
51        self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2)
52        #self.assert_(chisqr2/len(data1.x) < 2)
53        #self.assert_(chisqr2/len(data2.x) < 2)
54    def testmodel1data1param1(self):
55        """ test fitting for two set of data  and one model with 2 constraint"""
56        from sans.fit.Loader import Load
57        load= Load()
58        #Load the first set of data
59        load.set_filename("testdata1.txt")
60        load.set_values()
61        data1 = Data1D(x=[], y=[],dx=None, dy=None)
62        load.load_data(data1)
63       
64        #Load the second set of data
65        load.set_filename("testdata2.txt")
66        load.set_values()
67        data2 = Data1D(x=[], y=[],dx=None, dy=None)
68        load.load_data(data2)
69       
70        #Importing the Fit module
71        from sans.fit.Fitting import Fit
72        fitter= Fit('park')
73        # Receives the type of model for the fitting
74        from sans.guitools.LineModel import LineModel
75        model1  = LineModel()
76       
77       
78        #Do the fit
79       
80        fitter.set_model(model1,"M1",1, {'A':1})
81        fitter.set_data(data1,1)
82       
83     
84       
85        chisqr2, out2, cov2 = fitter.fit()
86        print "chisqr2",chisqr2
87        print "out2", out2
88        print " cov2", cov2
89        print chisqr2/len(data1.x)
90       
91        self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2)
92        self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2)
93        #self.assert_(chisqr2/len(data1.x) < 2)
94        #self.assert_(chisqr2/len(data2.x) < 2)
95   
Note: See TracBrowser for help on using the repository browser.