Changeset cf3b781 in sasview for park_integration/test
- Timestamp:
- Jul 7, 2008 6:37:27 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:
- 1b0b3ca
- Parents:
- 672c44da
- Location:
- park_integration/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/test/constrainttestpark.py
r9e85792 rcf3b781 40 40 engine.set_data(data1,1) 41 41 #print "m1 param b", M1.B 42 engine.set_param( model2,"M2", {'A': 1,'B':'2*M1.B'})42 engine.set_param( model2,"M2", {'A':'M1.A','B':'M1.B'}) 43 43 engine.set_model(model2,2) 44 44 engine.set_data(data2,2) … … 46 46 47 47 print engine.fit({'A':2,'B':1},None,None) 48 48 if True: 49 import pylab 50 x1 = engine.problem[0].data.x 51 x2 = engine.problem[1].data.x 52 y1 = engine.problem[0].data.y 53 y2 = engine.problem[1].data.y 54 fx1 = engine.problem[0].data.fx 55 fx2 = engine.problem[1].data.fx 56 pylab.plot(x1,y1,'xb',x1,fx1,'-b',x2,y2,'xr',x2,fx2,'-r') 57 pylab.show() -
park_integration/test/testfitting.py
r9e85792 rcf3b781 73 73 #Do the fit SCIPY 74 74 engine.set_data(data1,1) 75 engine.set_param( model,"M1", {'A':2,'B':4}) 75 76 engine.set_model(model,1) 76 77 … … 87 88 #Do the fit 88 89 engine.set_data(data1,1) 90 engine.set_param( model1,"M1", {'A':2,'B':4}) 89 91 engine.set_model(model,1) 90 92 91 93 engine.fit({'A':2,'B':1},None,None) 92 """ 93 94 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 95 self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2) 96 self.assert_(chisqr2/len(data1.x) < 2) 97 98 self.assertEqual(out1[1], out2[1]) 99 self.assertEquals(out1[0], out2[0]) 100 self.assertEquals(cov1[0][0], cov2[0][0]) 101 self.assertEquals(cov1[1][1], cov2[1][1]) 102 self.assertEquals(chisqr1, chisqr2) 103 """ 94 95 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 96 self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2) 97 self.assert_(chisqr2/len(data1.x) < 2) 98 99 self.assertEqual(out1[1], out2[1]) 100 self.assertEquals(out1[0], out2[0]) 101 self.assertEquals(cov1[0][0], cov2[0][0]) 102 self.assertEquals(cov1[1][1], cov2[1][1]) 103 self.assertEquals(chisqr1, chisqr2) 104 104 105 def testfit_2Data_1Model(self): 105 106 """ test fitting for two set of data and one model""" … … 128 129 engine = fitter.returnEngine() 129 130 #Do the fit 130 engine.set_model(model,1) 131 engine.set_param( model,"M1", {'A':2,'B':4}) 132 engine.set_model(model,1) 133 131 134 engine.set_data(data1,1) 132 135 engine.set_data(data2,1) … … 150 153 engine.set_data(data2,1) 151 154 engine.fit({'A':2,'B':1},None,None) 152 """ 153 chisqr2, out2, cov2= engine.fit({'A':2,'B':1},None,None) 154 155 156 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 157 self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2) 158 self.assert_(chisqr2/len(data1.x) < 2) 159 self.assert_(chisqr2/len(data2.x) < 2) 160 161 self.assertEqual(out1[0],out2[0]) 162 self.assertEqual(out1[1],out2[1]) 163 self.assertEqual(chisqr1,chisqr2) 164 self.assertEqual(cov1[0][0],cov2[0][0]) 165 self.assertEqual(cov1[1][1],cov2[1][1]) 166 """ 155 156 chisqr2, out2, cov2= engine.fit({'A':2,'B':1},None,None) 157 #print "park",chisqr2, out2, cov2 158 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 159 self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2) 160 self.assert_(chisqr2/len(data1.x) < 2) 161 self.assert_(chisqr2/len(data2.x) < 2) 162 163 self.assertEqual(out1[0],out2[0]) 164 self.assertEqual(out1[1],out2[1]) 165 self.assertEqual(chisqr1,chisqr2) 166 self.assertEqual(cov1[0][0],cov2[0][0]) 167 self.assertEqual(cov1[1][1],cov2[1][1]) 168 167 169 def test2models2dataonconstraint(self): 168 170 """ test for 2 Models two data one constraint""" … … 187 189 from sans.guitools.LineModel import LineModel 188 190 model1 = LineModel() 189 model1.name='M1'190 191 model2 = LineModel() 191 model2.name='M2'192 192 193 #set engine for scipy 193 fitter.fit_engine('scipy') 194 engine = fitter.returnEngine() 195 #Do the fit 194 """ 195 fitter.fit_engine('scipy') 196 engine = fitter.returnEngine() 197 #Do the fit 198 engine.set_param( model1,"M1", {'A':2,'B':4}) 199 engine.set_model(model1,1) 200 engine.set_data(data1,1) 201 engine.set_param( model1,"M2", {'A':2.1,'B':3}) 202 engine.set_model(model2,2) 203 engine.set_data(data2,2) 204 205 try: engine.fit({'A':2,'B':1},None,None) 206 except ValueError,msg: 207 assert str(msg)=="cannot fit more than one model",'Message: <%s>'%(msg) 208 """ 209 #set engine for park 210 fitter= Fit() 211 fitter.fit_engine('park') 212 engine = fitter.returnEngine() 213 #Do the fit 214 engine.set_data(data1,1) 215 engine.set_param(model1,"M1",{'A':2,'B':1}) 196 216 engine.set_model(model1,1) 197 engine.set_data(data1,1) 217 218 engine.set_param(model2,"M2",{'A':3,'B':'M1.B'}) 198 219 engine.set_model(model2,2) 199 220 engine.set_data(data2,2) 200 201 try: engine.fit({'A':2,'B':1},None,None) 202 except ValueError,msg: 203 assert str(msg)=="cannot fit more than one model",'Message: <%s>'%(msg) 204 205 #set engine for park 206 fitter= Fit() 207 fitter.fit_engine('park') 208 engine = fitter.returnEngine() 209 #Do the fit 210 engine.set_data(data1,1) 211 engine.set_param(model1,{'A':2,'B':1}) 212 engine.set_model(model1,1) 213 214 engine.set_param(model2,{'A':3,'B':'5*M1.B'}) 215 engine.set_model(model2,2) 216 engine.set_data(data2,2) 217 engine.fit({'A':2,'B':1},None,None) 218 221 chisqr2, out2, cov2= engine.fit({'A':2,'B':1},None,None) 222 223 224 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 225 self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2) 226 self.assert_(chisqr2/len(data1.x) < 2) 227 self.assert_(chisqr2/len(data2.x) < 2) 228 -
park_integration/test/testpark.py
r9e85792 rcf3b781 40 40 engine.set_data(data1,1) 41 41 42 import numpy 43 #print engine.fit({'A':2,'B':1},None,None) 44 #engine.remove_data(2,data2) 45 #engine.remove_model(2) 46 42 47 engine.set_param( model2,"M2", {'A':2.5,'B':4}) 43 48 engine.set_model(model2,2) 44 49 engine.set_data(data2,2) 45 46 47 50 print engine.fit({'A':2,'B':1},None,None) 48 51 52 if True: 53 import pylab 54 x1 = engine.problem[0].data.x 55 x2 = engine.problem[1].data.x 56 y1 = engine.problem[0].data.y 57 y2 = engine.problem[1].data.y 58 fx1 = engine.problem[0].data.fx 59 fx2 = engine.problem[1].data.fx 60 pylab.plot(x1,y1,'xb',x1,fx1,'-b',x2,y2,'xr',x2,fx2,'-r') 61 pylab.show() 62 if False: 63 print "current" 64 print engine.problem.chisq 65 print engine.problem.residuals 66 print "M1.y",engine.problem[0].data.y 67 print "M1.fx",engine.problem[0].data.fx 68 print "M1 delta",numpy.asarray(engine.problem[0].data.y)-engine.problem[0].data.fx 69 print "M2.y",engine.problem[0].data.y 70 print "M2.fx",engine.problem[0].data.fx 71 print "M2 delta",numpy.asarray(engine.problem[1].data.y)-engine.problem[1].data.fx 72 print "target" 73 engine.problem(numpy.array([4,2.5,4,2.5])) 74 print engine.problem.chisq 75 print engine.problem.residuals 76 print "M1.y",engine.problem[0].data.y 77 print "M1.fx",engine.problem[0].data.fx 78 print "M1 delta",numpy.asarray(engine.problem[0].data.y)-engine.problem[0].data.fx 79 print "M2.y",engine.problem[0].data.y 80 print "M2.fx",engine.problem[0].data.fx 81 print "M2 delta",numpy.asarray(engine.problem[1].data.y)-engine.problem[1].data.fx 82
Note: See TracChangeset
for help on using the changeset viewer.