source: sasview/park_integration/test/testpark_line.py @ 1f8accb

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 1f8accb was 388309d, checked in by Gervaise Alina <gervyh@…>, 16 years ago

park_integration working better for large model

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"""
2    Unit tests for fitting module  using park integration
3    fitting 2 data with 2 model and one constraint on only one parameter is not working
4"""
5import unittest
6from sans.guitools.plottables import Theory1D
7from sans.guitools.plottables import Data1D
8from sans.fit.AbstractFitEngine import Model,Data
9import math
10class testFitModule(unittest.TestCase):
11   
12    def test2models2data2constraints(self):
13        """ test fitting for two data , 2 model , 2 constraints"""
14        from sans.fit.Loader import Load
15        load= Load()
16        #Load the first data
17        load.set_filename("testdata1.txt")
18        load.set_values()
19        data1 = Data1D(x=[], y=[],dx=None, dy=None)
20        load.load_data(data1)
21       
22        #Load the second data
23        load.set_filename("testdata2.txt")
24        load.set_values()
25        data2 = Data1D(x=[], y=[],dx=None, dy=None)
26        load.load_data(data2)
27       
28        #Load the third data
29        load.set_filename("testdata_line.txt")
30        load.set_values()
31        data3 = Data1D(x=[], y=[],dx=None, dy=None)
32        load.load_data(data3)
33       
34        #Importing the Fit module
35        from sans.fit.Fitting import Fit
36        fitter= Fit('park')
37        # Receives the type of model for the fitting
38        from sans.guitools.LineModel import LineModel
39        model1  = LineModel()
40       
41        #Do the fit
42        model1.setParam( 'A', 2.5)
43        model1.setParam( 'B', 4)
44        model1.name="M1"
45        fitter.set_model(Model(model1),"M1",1, ['A','B'])
46        fitter.set_data(Data(sans_data=data1),1)
47       
48       
49        result = fitter.fit()
50        chisqr1 = result.fitness
51        out1 = result.pvec
52        cov1 = result.cov
53        self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2)
54        print math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0])
55        #self.assert_(math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) < 2)
56        self.assert_(math.fabs(out1[3]-2.5)/math.sqrt(cov1[3][3]) < 2)
57        self.assert_(math.fabs(out1[2]-4.0)/math.sqrt(cov1[2][2]) < 2)
58        print chisqr1/len(data1.x)
59        #self.assert_(chisqr1/len(data1.x) < 2)
60        print chisqr1/len(data2.x)
61        #self.assert_(chisqr2/len(data2.x) < 2)
62   
Note: See TracBrowser for help on using the repository browser.