Changeset 4dd63eb in sasview
- Timestamp:
- Jul 10, 2008 6:05:09 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:
- 49b3ddd
- Parents:
- 83ca047
- Location:
- park_integration
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/Fitting.py
r93f0a586 r4dd63eb 50 50 return self._engine 51 51 52 def fit(self, pars,qmin=None, qmax=None):52 def fit(self, qmin=None, qmax=None): 53 53 """Perform the fit """ 54 55 def set_model(self,model, Uid):54 return self._engine.fit(qmin,qmax) 55 def set_model(self,model,name,Uid,pars={}): 56 56 """ Set model """ 57 57 self._engine.set_model(model,name,Uid, pars) 58 58 def set_data(self,data,Uid): 59 59 """ Receive plottable and create a list of data to fit""" 60 60 self._engine.set_data(data,Uid) 61 61 def get_model(self,Uid): 62 62 """ return list of data""" 63 64 def set_param(self,model,name, pars): 65 """ Recieve a dictionary of parameter and save it """ 66 self._engine.set_param(model, name, pars) 63 self._engine.get_model(Uid) 67 64 68 def remove_data(self,Uid,data=None): 69 """ remove one or all data""" 70 71 def remove_model(self,Uid): 72 """ remove model """ 65 def remove_Fit_Problem(self,Uid): 66 """remove fitarrange in Uid""" 67 self._engine.remove_Fit_Problem(Uid) 73 68 -
park_integration/ParkFitting.py
r792db7d5 r4dd63eb 185 185 self.fitArrangeList={} 186 186 187 def createProblem(self ,pars={}):187 def createProblem(self): 188 188 """ 189 189 Extract sansmodel and sansdata from self.FitArrangelist ={Uid:FitArrange} … … 211 211 212 212 213 def fit(self, pars=None,qmin=None, qmax=None):213 def fit(self, qmin=None, qmax=None): 214 214 """ 215 215 Performs fit with park.fit module.It can perform fit with one model … … 229 229 230 230 231 self.createProblem( pars)231 self.createProblem() 232 232 pars=self.problem.fit_parameters() 233 233 self.problem.eval() … … 240 240 fitter=fitter, 241 241 handler= fitresult.ConsoleUpdate(improvement_delta=0.1)) 242 242 print "result",result 243 243 return result.fitness,result.pvec,result.cov 244 244 245 def set_model(self,model,Uid): 246 """ 245 def set_model(self,model,name,Uid,pars={}): 246 """ 247 248 Receive a dictionary of parameter and save it Parameter list 249 For scipy.fit use. 247 250 Set model in a FitArrange object and add that object in a dictionary 248 251 with key Uid. 249 @param model: the model added 252 @param model: model on with parameter values are set 253 @param name: model name 250 254 @param Uid: unique key corresponding to a fitArrange object with model 251 """ 255 @param pars: dictionary of paramaters name and value 256 pars={parameter's name: parameter's value} 257 258 """ 259 self.parameters=[] 260 if model==None: 261 raise ValueError, "Cannot set parameters for empty model" 262 else: 263 model.name=name 264 for key, value in pars.iteritems(): 265 param = Parameter(model, key, value) 266 self.parameters.append(param) 267 252 268 #A fitArrange is already created but contains dList only at Uid 253 269 if self.fitArrangeList.has_key(Uid): … … 258 274 fitproblem.set_model(model) 259 275 self.fitArrangeList[Uid]=fitproblem 276 260 277 261 278 def set_data(self,data,Uid): … … 286 303 return None 287 304 288 def set_param(self,model,name, pars):289 """290 Recieve a dictionary of parameter and save it291 @param model: model on with parameter values are set292 @param name: model name293 @param pars: dictionary of paramaters name and value294 pars={parameter's name: parameter's value}295 @return list of Parameter instance296 """297 parameters=[]298 if model==None:299 raise ValueError, "Cannot set parameters for empty model"300 else:301 model.name=name302 for key, value in pars.iteritems():303 param = Parameter(model, key, value)304 parameters.append(param)305 return parameters306 307 def remove_data(self,Uid,data=None):308 """ remove one or all data.if data ==None will remove the whole309 list of data at Uid; else will remove only data in that list.310 @param Uid: unique id containing FitArrange object with data311 @param data:data to be removed312 """313 if data==None:314 # remove all element in data list315 if self.fitArrangeList.has_key(Uid):316 self.fitArrangeList[Uid].remove_datalist()317 else:318 #remove only data in dList319 if self.fitArrangeList.has_key(Uid):320 self.fitArrangeList[Uid].remove_data(data)321 322 def remove_model(self,Uid):323 """324 remove model in FitArrange object with Uid.325 @param Uid: Unique id corresponding to the FitArrange object326 where model must be removed.327 """328 if self.fitArrangeList.has_key(Uid):329 self.fitArrangeList[Uid].remove_model()330 305 def remove_Fit_Problem(self,Uid): 331 306 """remove fitarrange in Uid""" 332 307 if self.fitArrangeList.has_key(Uid): 333 308 del self.fitArrangeList[Uid] 309 334 310 def _concatenateData(self, listdata=[]): 335 311 """ -
park_integration/ScipyFitting.py
r792db7d5 r4dd63eb 88 88 self.fitArrangeList={} 89 89 90 def fit(self, pars,qmin=None, qmax=None):90 def fit(self,qmin=None, qmax=None): 91 91 """ 92 92 Performs fit with scipy optimizer.It can only perform fit with one model … … 107 107 listdata = fitproblem.get_data() 108 108 109 #Create list of Parameter instances and save parameters values in model110 parameters = self.set_param(model,model.name,pars)111 109 112 110 # Concatenate dList set (contains one or more data)before fitting … … 119 117 if qmax==None: 120 118 qmax= max(xtemp) 121 119 122 120 #perform the fit 123 chisqr, out, cov = fitHelper(model,parameters, xtemp,ytemp, dytemp ,qmin,qmax) 121 chisqr, out, cov = fitHelper(model,self.parameters, xtemp,ytemp, dytemp ,qmin,qmax) 122 124 123 return chisqr, out, cov 125 124 … … 158 157 return xtemp, ytemp,dytemp 159 158 160 def set_model(self,model,Uid): 161 """ 159 def set_model(self,model,name,Uid,pars={}): 160 """ 161 162 Receive a dictionary of parameter and save it Parameter list 163 For scipy.fit use. 162 164 Set model in a FitArrange object and add that object in a dictionary 163 165 with key Uid. 164 @param model: the model added 166 @param model: model on with parameter values are set 167 @param name: model name 165 168 @param Uid: unique key corresponding to a fitArrange object with model 166 """ 169 @param pars: dictionary of paramaters name and value 170 pars={parameter's name: parameter's value} 171 172 """ 173 self.parameters=[] 174 if model==None: 175 raise ValueError, "Cannot set parameters for empty model" 176 else: 177 model.name=name 178 for key, value in pars.iteritems(): 179 param = Parameter(model, key, value) 180 self.parameters.append(param) 181 167 182 #A fitArrange is already created but contains dList only at Uid 168 183 if self.fitArrangeList.has_key(Uid): … … 201 216 return None 202 217 203 def set_param(self,model,name, pars): 204 """ 205 Recieve a dictionary of parameter and save it 206 @param model: model on with parameter values are set 207 @param name: model name 208 @param pars: dictionary of paramaters name and value 209 pars={parameter's name: parameter's value} 210 @return list of Parameter instance 211 """ 212 parameters=[] 213 if model==None: 214 raise ValueError, "Cannot set parameters for empty model" 215 else: 216 model.name=name 217 for key, value in pars.iteritems(): 218 param = Parameter(model, key, value) 219 parameters.append(param) 220 return parameters 221 222 def remove_data(self,Uid,data=None): 223 """ remove one or all data.if data ==None will remove the whole 224 list of data at Uid; else will remove only data in that list. 225 @param Uid: unique id containing FitArrange object with data 226 @param data:data to be removed 227 """ 228 if data==None: 229 # remove all element in data list 230 if self.fitArrangeList.has_key(Uid): 231 self.fitArrangeList[Uid].remove_datalist() 232 else: 233 #remove only data in dList 234 if self.fitArrangeList.has_key(Uid): 235 self.fitArrangeList[Uid].remove_data(data) 236 237 def remove_model(self,Uid): 238 """ 239 remove model in FitArrange object with Uid. 240 @param Uid: Unique id corresponding to the FitArrange object 241 where model must be removed. 242 """ 218 219 220 def remove_Fit_Problem(self,Uid): 221 """remove fitarrange in Uid""" 243 222 if self.fitArrangeList.has_key(Uid): 244 self.fitArrangeList[Uid].remove_model()223 del self.fitArrangeList[Uid] 245 224 246 225 -
park_integration/test/constrainttestpark.py
r792db7d5 r4dd63eb 27 27 #Importing the Fit module 28 28 from sans.fit.Fitting import Fit 29 fitter= Fit( )29 fitter= Fit('park') 30 30 # Receives the type of model for the fitting 31 31 from sans.guitools.LineModel import LineModel 32 32 model1 = LineModel() 33 33 model2 = LineModel() 34 #set engine for scipy 35 fitter.fit_engine('park') 36 engine = fitter.returnEngine() 34 37 35 #Do the fit 38 engine.set_param( model1,"M1", {'A':2,'B':3})39 engine.set_model(model1,1)40 engine.set_data(data1,1)41 #print "m1 param b", M1.B42 engine.set_param( model2,"M2", {'A':'M1.A','B':'M1.B'})43 engine.set_model(model2,2)44 36 45 engine.set_data(data2,2) 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) 46 42 47 43 48 chisqr2, out2, cov2= engine.fit({'A':2,'B':1},None,None)44 chisqr2, out2, cov2= fitter.fit() 49 45 print "chisqr2",chisqr2 50 46 print "out2", out2 -
park_integration/test/testfitting.py
r792db7d5 r4dd63eb 5 5 from sans.guitools.plottables import Theory1D 6 6 from sans.guitools.plottables import Data1D 7 from sans.fit.ScipyFitting import Parameter 7 8 8 import math 9 9 class testFitModule(unittest.TestCase): … … 64 64 #Importing the Fit module 65 65 from sans.fit.Fitting import Fit 66 fitter= Fit() 67 fitter.fit_engine('scipy') 68 engine = fitter.returnEngine() 66 fitter= Fit('scipy') 67 69 68 # Receives the type of model for the fitting 70 69 from sans.guitools.LineModel import LineModel … … 73 72 74 73 #Do the fit SCIPY 75 engine.set_data(data1,1) 76 #engine.set_param( model1,"M1", {'A':2,'B':4}) 77 engine.set_model(model1,1) 74 fitter.set_data(data1,1) 75 fitter.set_model(model1,"M1",1,{'A':2,'B':1}) 78 76 79 chisqr1, out1, cov1= engine.fit({'A':2,'B':1},None,None)77 chisqr1, out1, cov1=fitter.fit() 80 78 """ testing SCIPy results""" 81 79 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2) … … 83 81 self.assert_(chisqr1/len(data1.x) < 2) 84 82 # PARK 85 fitter= Fit() 86 fitter.fit_engine('park') 87 engine = fitter.returnEngine() 83 fitter= Fit('park') 88 84 89 85 #Do the fit 90 engine.set_data(data1,1) 91 engine.set_param( model2,"M1", {'A':2,'B':1}) 92 engine.set_model(model2,1) 86 fitter.set_data(data1,1) 87 fitter.set_model(model2,"M1",1,{'A':2,'B':1}) 93 88 94 chisqr2, out2, cov2= engine.fit({'A':2,'B':1},None,None)89 chisqr2, out2, cov2=fitter.fit(None,None) 95 90 96 91 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) -
park_integration/test/testpark.py
r792db7d5 r4dd63eb 33 33 #Importing the Fit module 34 34 from sans.fit.Fitting import Fit 35 fitter= Fit( )35 fitter= Fit('park') 36 36 # Receives the type of model for the fitting 37 37 from sans.guitools.LineModel import LineModel 38 38 model1 = LineModel() 39 39 model2 = LineModel() 40 #set engine for scipy 41 fitter.fit_engine('park') 42 engine = fitter.returnEngine() 40 43 41 #Do the fit 44 engine.set_param( model1,"M1", {'A':2.5,'B':4}) 45 engine.set_model(model1,1) 46 engine.set_data(data1,1) 42 fitter.set_model(model1,"M1",1, {'A':2.5,'B':4}) 43 fitter.set_data(data1,1) 47 44 48 engine.set_param( model2,"M2", {'A':2,'B':4}) 49 engine.set_model(model2,2) 50 engine.set_data(data2,2) 45 fitter.set_model(model2,"M2",2, {'A':2,'B':3}) 46 fitter.set_data(data2,2) 51 47 52 chisqr1, out1, cov1= engine.fit({'A':2,'B':1},None,None)48 chisqr1, out1, cov1= fitter.fit() 53 49 54 50 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2) … … 63 59 64 60 65 engine.set_data(data3,1)66 chisqr2, out2, cov2= engine.fit({'A':2,'B':1},None,None)61 fitter.set_data(data3,1) 62 chisqr2, out2, cov2= fitter.fit(None,None) 67 63 self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2) 68 64 print math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) … … 75 71 #self.assert_(chisqr2/len(data2.x) < 2) 76 72 73 fitter.remove_Fit_Problem(2) 77 74 78 79 engine.remove_Fit_Problem(2) 80 chisqr3, out3, cov3= engine.fit({'A':2,'B':1},None,None) 75 chisqr3, out3, cov3= fitter.fit() 81 76 #print "park",chisqr3, out3, cov3 82 77 self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2)
Note: See TracChangeset
for help on using the changeset viewer.