Changeset fd6b789 in sasview
- Timestamp:
- Nov 16, 2009 12:50:50 PM (15 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:
- 464fce54
- Parents:
- 4026380
- Location:
- park_integration
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r12b76cf rfd6b789 365 365 self.model.setParams(self.paramlist,params) 366 366 self.res= self.data.residuals(self.model.eval) 367 #if self.curr_thread != None :368 #try:369 #self.curr_thread.isquit()370 #except:371 #raise FitAbort,"stop leastsqr optimizer"367 if self.curr_thread != None : 368 try: 369 self.curr_thread.isquit() 370 except: 371 raise FitAbort,"stop leastsqr optimizer" 372 372 return self.res 373 373 … … 435 435 436 436 437 def set_model(self,model,Uid,pars=[] ):437 def set_model(self,model,Uid,pars=[], constraints=[]): 438 438 """ 439 439 set a model on a given uid in the fit engine. 440 @param model: the model to fit440 @param model: sans.models type 441 441 @param Uid :is the key of the fitArrange dictionnary where model is saved as a value 442 442 @param pars: the list of parameters to fit 443 @param constraints: list of 444 tuple (name of parameter, value of parameters) 445 the value of parameter must be a string to constraint 2 different 446 parameters. 447 Example: 448 we want to fit 2 model M1 and M2 both have parameters A and B. 449 constraints can be: 450 constraints = [(M1.A, M2.B+2), (M1.B= M2.A *5),...,] 443 451 @note : pars must contains only name of existing model's paramaters 444 452 """ 453 if model == None: 454 raise ValueError, "AbstractFitEngine: Need to set model to fit" 455 456 new_model= model 457 if not issubclass(model.__class__, Model): 458 new_model= Model(model) 459 460 if len(constraints)>0: 461 for constraint in constraints: 462 name, value = constraint 463 try: 464 new_model.parameterset[ str(name)].set( str(value) ) 465 except: 466 msg= "Fit Engine: Error occurs when setting the constraint" 467 msg += " %s for parameter %s "%(value, name) 468 raise ValueError, msg 469 445 470 if len(pars) >0: 446 if model==None:447 raise ValueError, "AbstractFitEngine: Specify parameters to fit"448 else:449 temp=[]450 for item in pars:451 if item in model.model.getParamList():452 temp.append(item)453 self.paramList.append(item)454 else:455 raise ValueError,"wrong paramter %s used to set model %s. Choose\456 parameter name within %s"%(item, model.model.name,str(model.model.getParamList()))457 return471 temp=[] 472 for item in pars: 473 if item in new_model.model.getParamList(): 474 temp.append(item) 475 self.paramList.append(item) 476 else: 477 478 msg = "wrong parameter %s used"%str(item) 479 msg += "to set model %s. Choose"%str(new_model.model.name) 480 msg += "parameter name within %s"%str(new_model.model.getParamList()) 481 raise ValueError,msg 482 458 483 #A fitArrange is already created but contains dList only at Uid 459 484 if self.fitArrangeDict.has_key(Uid): 460 self.fitArrangeDict[Uid].set_model( model)485 self.fitArrangeDict[Uid].set_model(new_model) 461 486 self.fitArrangeDict[Uid].pars= pars 462 487 else: 463 488 #no fitArrange object has been create with this Uid 464 489 fitproblem = FitArrange() 465 fitproblem.set_model( model)490 fitproblem.set_model(new_model) 466 491 fitproblem.pars= pars 467 492 self.fitArrangeDict[Uid] = fitproblem -
park_integration/Fitting.py
rd8a2e31 rfd6b789 49 49 50 50 51 def fit(self, handler=None, curr_thread=None):51 def fit(self,q=None,handler=None, curr_thread=None): 52 52 """Perform the fit """ 53 53 try: 54 return self._engine.fit( handler, curr_thread= curr_thread)54 return self._engine.fit(q,handler, curr_thread= curr_thread) 55 55 except: 56 56 raise 57 57 58 58 59 def set_model(self,model,Uid,pars=[] ):59 def set_model(self,model,Uid,pars=[],constraints=[]): 60 60 """ 61 61 store a model model to fit at the position Uid of the fit engine 62 62 """ 63 self._engine.set_model(model,Uid,pars )63 self._engine.set_model(model,Uid,pars,constraints) 64 64 65 65 -
park_integration/ParkFitting.py
rd9dc518 rfd6b789 88 88 89 89 90 def fit(self, handler=None, curr_thread= None):90 def fit(self,q=None,handler=None, curr_thread= None): 91 91 """ 92 92 Performs fit with park.fit module.It can perform fit with one model … … 120 120 self.problem.all_results(result) 121 121 if result !=None: 122 if q !=None: 123 q.put(result) 124 return q 122 125 return result 123 126 else: -
park_integration/ScipyFitting.py
rd9dc518 rfd6b789 61 61 # return profile(self._fit, *args, **kw) 62 62 63 def fit(self , handler=None,curr_thread= None):63 def fit(self ,q=None,handler=None,curr_thread= None): 64 64 65 65 fitproblem=[] … … 81 81 data=listdata 82 82 self.curr_thread= curr_thread 83 84 #try: 85 functor= SansAssembly(self.paramList,model,data, curr_thread= self.curr_thread) 86 out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 83 87 84 try: 85 functor= SansAssembly(self.paramList,model,data, curr_thread= self.curr_thread) 86 out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 87 88 chisqr = functor.chisq(out) 89 90 if cov_x is not None and numpy.isfinite(cov_x).all(): 91 stderr = numpy.sqrt(numpy.diag(cov_x)) 92 else: 93 stderr=None 94 if not (numpy.isnan(out).any()) or ( cov_x !=None) : 95 result = fitresult() 96 result.fitness = chisqr 97 result.stderr = stderr 98 result.pvec = out 99 result.success = success 100 return result 101 else: 102 raise ValueError, "SVD did not converge"+str(success) 103 except FitAbort: 88 chisqr = functor.chisq(out) 89 90 if cov_x is not None and numpy.isfinite(cov_x).all(): 91 stderr = numpy.sqrt(numpy.diag(cov_x)) 92 else: 93 stderr=None 94 if not (numpy.isnan(out).any()) or ( cov_x !=None) : 95 result = fitresult() 96 result.fitness = chisqr 97 result.stderr = stderr 98 result.pvec = out 99 result.success = success 100 if q !=None: 101 print "went here" 102 q.put(result) 103 print "get q scipy fit enfine",q.get() 104 return q 105 return result 106 else: 107 raise ValueError, "SVD did not converge"+str(success) 108 #except FitAbort: 104 109 ## fit engine is stop 105 return None110 # return None 106 111 107 except:108 raise112 #except: 113 # raise 109 114 110 115 -
park_integration/test/small_test.py
r1e3169c rfd6b789 3 3 """ 4 4 import unittest 5 from sans.fit.AbstractFitEngine import Model6 5 import math 7 6 from sans.fit.Fitting import Fit … … 18 17 # Receives the type of model for the fitting 19 18 from sans.models.CylinderModel import CylinderModel 20 model1 = CylinderModel() 21 model1.setParam('contrast', 1) 22 model = Model(model1) 23 19 model = CylinderModel() 20 model.setParam('contrast', 1) 21 24 22 pars1 =['length','radius','scale'] 25 23 fitter.set_data(out,1) 26 model.set ( scale=1e-10)27 fitter.set_model(model,1,pars1 )24 model.setParam('scale', 1e-10) 25 fitter.set_model(model,1,pars1, constraints=()) 28 26 fitter.select_problem_for_fit(Uid=1,value=1) 29 27 result1 = fitter.fit() -
park_integration/test/test_fit_cylinder.py
r1e3169c rfd6b789 17 17 # Create model that fitting engine understands 18 18 from sans.models.CylinderModel import CylinderModel 19 model1 = CylinderModel() 20 model1.setParam("scale", 1.0) 21 model1.setParam("radius",18) 22 model1.setParam("length", 397) 23 model1.setParam("contrast",3e-006 ) 24 model1.setParam("background", 0.0) 25 26 self.model = Model(model1) 27 19 self.model = CylinderModel() 20 self.model.setParam("scale", 1.0) 21 self.model.setParam("radius",18) 22 self.model.setParam("length", 397) 23 self.model.setParam("contrast",3e-006 ) 24 self.model.setParam("background", 0.0) 25 #select parameters to fit 28 26 self.pars1 =['length','radius','scale'] 29 27 … … 32 30 fitter = Fit(name) 33 31 fitter.set_data(self.data,1) 34 35 32 fitter.set_model(self.model,1,self.pars1) 36 33 fitter.select_problem_for_fit(Uid=1,value=1) -
park_integration/test/test_fit_line.py
r1e3169c rfd6b789 29 29 try:fitter.set_model(model,1,pars1) 30 30 except ValueError,msg: 31 assert str(msg)=="wrong paramter %s used to set model %s. Choose\ 32 parameter name within %s"%('param1', model.model.name,str(model.model.getParamList())) 31 print "ValueError was raised: "+str(msg) 32 #assert str(msg)=="wrong paramter %s used to set model %s. Choose\ 33 # parameter name within %s"%('param1', model.model.name,str(model.model.getParamList())) 33 34 else: raise AssertError,"No error raised for scipy fitting with wrong parameters name to fit" 34 35 pars1= ['A','B']
Note: See TracChangeset
for help on using the changeset viewer.