Changeset d831626 in sasview for park_integration
- Timestamp:
- Sep 3, 2008 12:58:30 PM (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:
- 84545dd
- Parents:
- daa56d0
- Location:
- park_integration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r3c404d3 rd831626 36 36 def __init__(self, sans_model): 37 37 self.model = sans_model 38 self.name=sans_model.name 38 39 #print "ParkFitting:sans model",self.model 39 40 self.sansp = sans_model.getParamList() … … 67 68 68 69 def eval(self,x): 69 #print "eval",self.parameterset[0].value,self.parameterset[1].value70 70 71 return self.model.runXY(x) 71 72 … … 193 194 else: 194 195 model.model.name = name 196 model.name = name 195 197 self.paramList=pars 196 198 #A fitArrange is already created but contains dList only at Uid -
park_integration/test/test_large_model.py
r48882d1 rd831626 31 31 32 32 #Do the fit SCIPY 33 fitter.set_data(data1,1)33 34 34 import math 35 35 #pars1=['background','contrast', 'length'] -
park_integration/test/testnewscipys.py
r48882d1 rd831626 1 1 """ 2 Unit tests for fitting module2 test Data, Model , fucntor classes of AbstractFittingModule 3 3 """ 4 4 import unittest … … 12 12 13 13 def test_Data(self): 14 """ test data"""14 """ test Data""" 15 15 #load data 16 16 from sans.fit.Loader import Load … … 37 37 #fitter.set_model_assembly(model,"M1",1,['A','B']) 38 38 def test_Model(self): 39 """ test model"""39 """ test Model""" 40 40 #load data 41 41 from sans.fit.Loader import Load -
park_integration/test/testpark.py
r985c88b rd831626 1 1 """ 2 Unit tests for fitting module 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 3 4 """ 4 5 import unittest 5 6 from sans.guitools.plottables import Theory1D 6 7 from sans.guitools.plottables import Data1D 7 from sans.fit. ScipyFitting import Parameter8 from sans.fit.AbstractFitEngine import Model,Data 8 9 import math 9 10 class testFitModule(unittest.TestCase): 10 11 11 def test2models2data onconstraint(self):12 """ test fitting for two set of data and one model"""12 def test2models2data2constraints(self): 13 """ test fitting for two data , 2 model , 2 constraints""" 13 14 from sans.fit.Loader import Load 14 15 load= Load() … … 42 43 model1.setParam( 'A', 2.5) 43 44 model1.setParam( 'B', 4) 44 fitter.set_model(model1,"M1",1, ['A','B']) 45 fitter.set_data(data1,1) 45 model1.name="M1" 46 fitter.set_model(Model(model1),"M1",1, ['A','B']) 47 fitter.set_data(Data(sans_data=data1),1) 48 model2.name="M2" 49 model2.setParam( 'A', "M1.A+1") 50 model2.setParam( 'B', 'M1.B*2') 46 51 47 model1.setParam( 'A', 2) 48 model1.setParam( 'B', 3) 49 fitter.set_model(model2,"M2",2, ['A','B']) 50 fitter.set_data(data2,2) 52 fitter.set_model(Model(model2),"M2",2, ['A','B']) 53 fitter.set_data(Data(sans_data=data2),2) 51 54 52 chisqr1, out1, cov1,result= fitter.fit() 53 55 result = fitter.fit() 56 chisqr1 = result.fitness 57 out1 = result.pvec 58 cov1 = result.cov 54 59 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2) 55 60 print math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) … … 61 66 print chisqr1/len(data2.x) 62 67 #self.assert_(chisqr2/len(data2.x) < 2) 68 69 def test2models2data1constraint(self): 70 """ test fitting for two data , 2 model ,1 constraint""" 71 from sans.fit.Loader import Load 72 load= Load() 73 #Load the first data 74 load.set_filename("testdata1.txt") 75 load.set_values() 76 data1 = Data1D(x=[], y=[],dx=None, dy=None) 77 load.load_data(data1) 63 78 79 #Load the second data 80 load.set_filename("testdata2.txt") 81 load.set_values() 82 data2 = Data1D(x=[], y=[],dx=None, dy=None) 83 load.load_data(data2) 64 84 65 fitter.set_data(data3,1) 66 chisqr2, out2, cov2, result= fitter.fit(None,None) 67 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 68 print math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) 85 #Load the third data 86 load.set_filename("testdata_line.txt") 87 load.set_values() 88 data3 = Data1D(x=[], y=[],dx=None, dy=None) 89 load.load_data(data3) 90 91 #Importing the Fit module 92 from sans.fit.Fitting import Fit 93 fitter= Fit('park') 94 # Receives the type of model for the fitting 95 from sans.guitools.LineModel import LineModel 96 model1 = LineModel() 97 model2 = LineModel() 98 99 #Do the fit 100 model1.setParam( 'A', 2.5) 101 model1.setParam( 'B', 4) 102 model1.name="M1" 103 fitter.set_model(Model(model1),"M1",1, ['A','B']) 104 fitter.set_data(Data(sans_data=data1),1) 105 model2.name="M2" 106 model2.setParam( 'A', 2) 107 model2.setParam( 'B', 'M1.B*2') 108 109 fitter.set_model(Model(model2),"M2",2, ['A','B']) 110 fitter.set_data(Data(sans_data=data2),2) 111 112 result = fitter.fit() 113 chisqr1 = result.fitness 114 out1 = result.pvec 115 cov1 = result.cov 116 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2) 117 print math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) 69 118 #self.assert_(math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) < 2) 70 self.assert_(math.fabs(out2[3]-2.5)/math.sqrt(cov2[3][3]) < 2) 71 self.assert_(math.fabs(out2[2]-4.0)/math.sqrt(cov2[2][2]) < 2) 72 print chisqr2/len(data1.x) 73 #self.assert_(chisqr1/len(data1.x) < 2) 74 print chisqr2/len(data2.x) 75 #self.assert_(chisqr2/len(data2.x) < 2) 76 77 fitter.remove_Fit_Problem(2) 78 79 chisqr3, out3, cov3= fitter.fit() 80 #print "park",chisqr3, out3, cov3 81 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2) 82 print math.fabs(out1[0]-4.0) 83 #self.assert_(math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) < 2) 119 self.assert_(math.fabs(out1[3]-2.5)/math.sqrt(cov1[3][3]) < 2) 120 self.assert_(math.fabs(out1[2]-4.0)/math.sqrt(cov1[2][2]) < 2) 84 121 print chisqr1/len(data1.x) 85 122 #self.assert_(chisqr1/len(data1.x) < 2) 86 #self.assert_(chisqr1/len(data2.x) < 2) 87 #failing at 7 place 88 self.assertAlmostEquals(out3[1],out1[1]) 89 self.assertAlmostEquals(out3[0],out1[0]) 90 self.assertAlmostEquals(cov3[1][1],cov1[1][1]) 91 self.assertAlmostEquals(cov3[0][0],cov1[0][0]) 123 print chisqr1/len(data2.x) 124 #self.assert_(chisqr2/len(data2.x) < 2) 125 92 126 93 self.assertAlmostEquals(out2[1],out1[1]) 94 self.assertAlmostEquals(out2[0],out1[0]) 95 self.assertAlmostEquals(cov2[1][1],cov1[1][1]) 96 self.assertAlmostEquals(cov2[0][0],cov1[0][0]) 127 def test2models2dataNoconstraint(self): 128 """ test fitting for two data and 2 models no cosntrainst""" 129 from sans.fit.Loader import Load 130 load= Load() 131 #Load the first data 132 load.set_filename("testdata1.txt") 133 load.set_values() 134 data1 = Data1D(x=[], y=[],dx=None, dy=None) 135 load.load_data(data1) 97 136 98 self.assertAlmostEquals(out2[1],out3[1]) 99 self.assertAlmostEquals(out2[0],out3[0]) 100 self.assertAlmostEquals(cov2[1][1],cov3[1][1]) 101 self.assertAlmostEquals(cov2[0][0],cov3[0][0]) 102 print chisqr1,chisqr2,chisqr3 103 #self.assertAlmostEquals(chisqr1,chisqr2) 104 self.assert_(chisqr1) 137 #Load the second data 138 load.set_filename("testdata2.txt") 139 load.set_values() 140 data2 = Data1D(x=[], y=[],dx=None, dy=None) 141 load.load_data(data2) 142 143 #Load the third data 144 load.set_filename("testdata_line.txt") 145 load.set_values() 146 data3 = Data1D(x=[], y=[],dx=None, dy=None) 147 load.load_data(data3) 148 149 #Importing the Fit module 150 from sans.fit.Fitting import Fit 151 fitter= Fit('park') 152 # Receives the type of model for the fitting 153 from sans.guitools.LineModel import LineModel 154 model1 = LineModel() 155 model2 = LineModel() 156 157 #Do the fit 158 model1.setParam( 'A', 2.5) 159 model1.setParam( 'B', 4) 160 model1.name="M1" 161 fitter.set_model(Model(model1),"M1",1, ['A','B']) 162 fitter.set_data(Data(sans_data=data1),1) 163 model2.name="M2" 164 model2.setParam( 'A', 1) 165 model2.setParam( 'B', 2) 166 167 fitter.set_model(Model(model2),"M2",2, ['A','B']) 168 fitter.set_data(Data(sans_data=data2),2) 169 170 result = fitter.fit() 171 chisqr1 = result.fitness 172 out1 = result.pvec 173 cov1 = result.cov 174 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2) 175 print math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) 176 #self.assert_(math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) < 2) 177 self.assert_(math.fabs(out1[3]-2.5)/math.sqrt(cov1[3][3]) < 2) 178 self.assert_(math.fabs(out1[2]-4.0)/math.sqrt(cov1[2][2]) < 2) 179 print chisqr1/len(data1.x) 180 #self.assert_(chisqr1/len(data1.x) < 2) 181 print chisqr1/len(data2.x) 182 #self.assert_(chisqr2/len(data2.x) < 2) 183 184 185
Note: See TracChangeset
for help on using the changeset viewer.