Changeset f24b8f4 in sasview for park_integration/test/testfitting.py
- Timestamp:
- May 23, 2008 9:10:39 AM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- a1718df
- Parents:
- dfb58f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/test/testfitting.py
r93c2ef2 rf24b8f4 52 52 53 53 54 def testfit(self): 55 """ test fitting""" 54 def testfit_1Data_1Model(self): 55 """ test fitting for one data and one model""" 56 #load data 56 57 from Loader import Load 57 58 load= Load() 58 59 load.set_filename("testdata_line.txt") 59 60 load.set_values() 60 x,y,dx,dy = load.get_values()61 61 data1 = Data1D(x=[], y=[],dx=None, dy=None) 62 62 load.load_data(data1) 63 63 64 #Importing the Fit module 65 from FittingModule import Fitting 66 Fit= Fitting() 64 67 # Receives the type of model for the fitting 65 68 from sans.guitools.LineModel import LineModel 66 69 model = LineModel() 67 70 71 #Do the fit 72 Fit.set_data(data1,1) 73 Fit.set_model(model,1) 74 chisqr, out, cov=Fit.fit({'A':2,'B':1},None,None) 75 #print"fit only one data",chisqr, out, cov 76 #Testing results 77 self.assertEqual(Fit.fit_engine("scipy"),True) 78 self.assert_(math.fabs(out[1]-2.5)/math.sqrt(cov[1][1]) < 2) 79 self.assert_(math.fabs(out[0]-4.0)/math.sqrt(cov[0][0]) < 2) 80 self.assert_(chisqr/len(data1.x) < 2) 81 82 #print "chisqr",chisqr/len(data1.x) 83 #print "Error on A",math.fabs(out[1]-2.5)/math.sqrt(cov[1][1]) 84 #print "Error on B",math.fabs(out[0]-4.0)/math.sqrt(cov[0][0]) 85 86 def testfit_2Data_1Model(self): 87 """ test fitting for two set of data data and one model""" 88 from Loader import Load 89 load= Load() 90 #Load the first set of data 91 load.set_filename("testdata1.txt") 92 load.set_values() 93 data1 = Data1D(x=[], y=[],dx=None, dy=None) 94 load.load_data(data1) 95 96 #Load the second set of data 97 load.set_filename("testdata2.txt") 98 load.set_values() 99 data2 = Data1D(x=[], y=[],dx=None, dy=None) 100 load.load_data(data2) 101 102 #Importing the Fit module 68 103 from FittingModule import Fitting 69 104 Fit= Fitting() 70 Fit.set_data(data1) 71 Fit.set_model(model) 105 # Receives the type of model for the fitting 106 from sans.guitools.LineModel import LineModel 107 model = LineModel() 72 108 73 default_A = model.getParam('A') 74 default_B = model.getParam('B') 75 cstA = Parameter(model, 'A', default_A) 76 cstB = Parameter(model, 'B', default_B) 77 chisqr, out, cov=Fit.fit([cstA,cstB],None,None) 78 print"fit only one data",chisqr, out, cov 79 80 self.assertEqual(Fit.fit_engine(),True) 109 #Do the fit 110 Fit.set_data(data1,1) 111 Fit.set_model(model,1) 81 112 113 Fit.set_data(data2,2) 114 Fit.set_model(model,2) 115 116 chisqr, out, cov=Fit.fit({'A':2,'B':1},None,None) 117 #print"fit only one data",chisqr, out, cov 118 119 #Testing results 120 self.assertEqual(Fit.fit_engine("scipy"),True) 82 121 self.assert_(math.fabs(out[1]-2.5)/math.sqrt(cov[1][1]) < 2) 83 print "chisqr",chisqr/len(data1.x)122 self.assert_(math.fabs(out[0]-4.0)/math.sqrt(cov[0][0]) < 2) 84 123 self.assert_(chisqr/len(data1.x) < 2) 85 # self.assertAlmostEqual(out[1],2.5)86 #self.assertAlmostEquals(out[0],4.0)87 #self.assertAlmostEquals(out[1]+cov[1][1],2.5)88 #self.assertAlmostEquals(out[0]+cov[0][0],4.0)89 124
Note: See TracChangeset
for help on using the changeset viewer.