Changeset 4bd557d in sasview
- Timestamp:
- Apr 24, 2009 4:34:48 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:
- ad6dd4c
- Parents:
- 813334e
- Location:
- park_integration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r09975cbb r4bd557d 211 211 212 212 ## Min Q-value 213 #Skip the Q=0 point .214 if min (self.data.x) ==0.0 :213 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 214 if min (self.data.x) ==0.0 and self.data.x[0]==0 and not numpy.isfinite(self.data.y[0]): 215 215 self.qmin = min(self.data.x[self.data.x!=0]) 216 216 else: … … 352 352 return [] 353 353 354 class FitAbort(Exception): 355 """ 356 Exception raise to stop the fit 357 """ 358 print"Creating fit abort Exception" 359 360 354 361 class sansAssembly: 355 362 """ 356 363 Sans Assembly class a class wrapper to be call in optimizer.leastsq method 357 364 """ 358 def __init__(self,paramlist,Model=None , Data=None ):365 def __init__(self,paramlist,Model=None , Data=None, curr_thread= None): 359 366 """ 360 367 @param Model: the model wrapper fro sans -model … … 364 371 self.data = Data 365 372 self.paramlist=paramlist 373 self.curr_thread= curr_thread 366 374 self.res=[] 375 self.func_name="Functor" 367 376 def chisq(self, params): 368 377 """ … … 374 383 for item in self.res: 375 384 sum += item*item 376 385 if len(self.res)==0: 386 return None 377 387 return sum/ len(self.res) 378 388 … … 385 395 self.model.setParams(self.paramlist,params) 386 396 self.res= self.data.residuals(self.model.eval) 387 #print "residuals",thread.get_ident() 397 if self.curr_thread != None : 398 try: 399 self.curr_thread.isquit() 400 except: 401 raise FitAbort,"stop leastsqr optimizer" 402 388 403 return self.res 389 404 -
park_integration/Fitting.py
r20d30e9 r4bd557d 51 51 52 52 53 def fit(self,handler=None ):53 def fit(self,handler=None, curr_thread=None): 54 54 """Perform the fit """ 55 55 56 return self._engine.fit(handler )56 return self._engine.fit(handler, curr_thread= curr_thread) 57 57 58 58 -
park_integration/ParkFitting.py
rfe886ee r4bd557d 88 88 89 89 90 def fit(self,handler=None ):90 def fit(self,handler=None, curr_thread= None): 91 91 """ 92 92 Performs fit with park.fit module.It can perform fit with one model -
park_integration/ScipyFitting.py
reef2e0ed r4bd557d 10 10 from scipy import optimize 11 11 12 from AbstractFitEngine import FitEngine, sansAssembly 12 from AbstractFitEngine import FitEngine, sansAssembly,FitAbort 13 print "in ScipyFitting fitabort",id(FitAbort),FitAbort.__class__.__module__ 13 14 14 15 class fitresult: … … 27 28 parameters= None 28 29 30 class old_FitAbort(Exception): 31 """ 32 Exception raise to stop the fit 33 """ 29 34 class ScipyFit(FitEngine): 30 35 """ … … 62 67 # return profile(self._fit, *args, **kw) 63 68 64 def fit(self ,handler=None ):69 def fit(self ,handler=None,curr_thread= None): 65 70 66 71 fitproblem=[] … … 81 86 #data=self._concatenateData( listdata) 82 87 data=listdata 83 functor= sansAssembly(self.paramList,model,data)88 self.curr_thread= curr_thread 84 89 85 out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 86 chisqr = functor.chisq(out) 90 try: 91 functor= sansAssembly(self.paramList,model,data, curr_thread= self.curr_thread) 92 out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 93 94 chisqr = functor.chisq(out) 95 96 if cov_x is not None and numpy.isfinite(cov_x).all(): 97 stderr = numpy.sqrt(numpy.diag(cov_x)) 98 else: 99 stderr=None 100 if not (numpy.isnan(out).any()) or ( cov_x !=None) : 101 result = fitresult() 102 result.fitness = chisqr 103 result.stderr = stderr 104 result.pvec = out 105 result.success =success 106 return result 107 else: 108 raise ValueError, "SVD did not converge"+str(success) 109 except FitAbort: 110 ## fit engine is stop 111 print "fitabort====>" 112 return None 87 113 88 if cov_x is not None and numpy.isfinite(cov_x).all(): 89 stderr = numpy.sqrt(numpy.diag(cov_x)) 90 else: 91 stderr=None 92 if not (numpy.isnan(out).any()) or ( cov_x !=None) : 93 result = fitresult() 94 result.fitness = chisqr 95 result.stderr = stderr 96 result.pvec = out 97 result.success =success 98 99 return result 100 else: 101 raise ValueError, "SVD did not converge"+str(success) 102 114 except: 115 return Fitresult() 103 116 104 117 def profile(fn, *args, **kw):
Note: See TracChangeset
for help on using the changeset viewer.