Changeset e0072082 in sasview
- Timestamp:
- Apr 13, 2010 5:47:26 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:
- e54d2c32
- Parents:
- 6345640
- Location:
- park_integration
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r83195f7 re0072082 341 341 Sans Assembly class a class wrapper to be call in optimizer.leastsq method 342 342 """ 343 def __init__(self,paramlist,Model=None , Data=None, curr_thread= None): 343 def __init__(self, paramlist, model=None , data=None, fitresult=None, 344 handler=None, curr_thread=None): 344 345 """ 345 346 @param Model: the model wrapper fro sans -model 346 347 @param Data: the data wrapper for sans data 347 348 """ 348 self.model = Model 349 self.data = Data 350 self.paramlist=paramlist 351 self.curr_thread= curr_thread 352 self.res=[] 353 self.func_name="Functor" 349 self.model = model 350 self.data = data 351 self.paramlist = paramlist 352 self.curr_thread = curr_thread 353 self.handler = handler 354 self.fitresult = fitresult 355 self.res = [] 356 self.func_name = "Functor" 357 354 358 def chisq(self, params): 355 359 """ … … 373 377 self.model.setParams(self.paramlist,params) 374 378 self.res= self.data.residuals(self.model.eval) 379 if self.fitresult is not None and self.handler is not None: 380 self.fitresult.set_model(model=self.model) 381 self.handler.set_result(result=self.fitresult) 382 self.handler.update_fit() 383 375 384 #if self.curr_thread != None : 376 385 # try: -
park_integration/ScipyFitting.py
r393f0f3 re0072082 10 10 from AbstractFitEngine import FitEngine, SansAssembly,FitAbort 11 11 12 class fitresult :12 class fitresult(object): 13 13 """ 14 14 Storing fit result 15 15 """ 16 calls = None 17 fitness = None 18 chisqr = None 19 pvec = None 20 cov = None 21 info = None 22 mesg = None 23 success = None 24 stderr = None 25 parameters= None 16 def __init__(self, model=None, paramList=None): 17 self.calls = None 18 self.fitness = None 19 self.chisqr = None 20 self.pvec = None 21 self.cov = None 22 self.info = None 23 self.mesg = None 24 self.success = None 25 self.stderr = None 26 self.parameters = None 27 self.model = model 28 self.paramList = paramList 29 30 def set_model(self, model): 31 self.model = model 32 33 def __str__(self): 34 if self.pvec == None and self.model is None and self.paramList is None: 35 return "No results" 36 n = len(self.model.parameterset) 37 38 result_param = zip(xrange(n), self.model.parameterset) 39 L = ["P%-3d %s......|.....%s"%(p[0], p[1], p[1].value) for p in result_param if p[1].name in self.paramList ] 40 L.append("=== goodness of fit: %s"%(str(self.fitness))) 41 return "\n".join(L) 26 42 43 def print_summary(self): 44 print self 27 45 28 46 class ScipyFit(FitEngine): … … 61 79 # return profile(self._fit, *args, **kw) 62 80 63 def fit(self ,q=None,handler=None,curr_thread=None):81 def fit(self, q=None, handler=None, curr_thread=None): 64 82 65 83 fitproblem=[] … … 68 86 fitproblem.append(fproblem) 69 87 if len(fitproblem)>1 : 70 raise RuntimeError, "Scipy can't fit more than a single fit problem at a time." 88 msg = "Scipy can't fit more than a single fit problem at a time." 89 raise RuntimeError, msg 71 90 return 72 91 elif len(fitproblem)==0 : … … 78 97 listdata = fitproblem[0].get_data() 79 98 # Concatenate dList set (contains one or more data)before fitting 80 #data=self._concatenateData( listdata) 81 data=listdata 99 data = listdata 82 100 self.curr_thread= curr_thread 83 101 result = fitresult(model=model, paramList=self.paramList) 102 if handler is not None: 103 handler.set_result(result=result) 84 104 #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) 105 functor = SansAssembly(self.paramList, model, data, handler=handler, 106 fitresult=result,curr_thread= self.curr_thread) 107 108 109 out, cov_x, info, mesg, success = optimize.leastsq(functor, 110 model.getParams(self.paramList), 111 full_output=1, warning=True) 87 112 88 113 chisqr = functor.chisq(out) … … 91 116 stderr = numpy.sqrt(numpy.diag(cov_x)) 92 117 else: 93 stderr =None118 stderr = None 94 119 if not (numpy.isnan(out).any()) or ( cov_x !=None) : 95 result = fitresult()96 120 result.fitness = chisqr 97 121 result.stderr = stderr 98 122 result.pvec = out 99 123 result.success = success 100 if q !=None: 101 print "went here" 124 print result 125 if q is not None: 126 #print "went here" 102 127 q.put(result) 103 print "get q scipy fit enfine",q.get()128 #print "get q scipy fit enfine",q.get() 104 129 return q 105 130 return result 106 131 else: 107 132 raise ValueError, "SVD did not converge"+str(success) 108 #except FitAbort: 109 ## fit engine is stop 110 # return None 111 112 #except: 113 # raise 114 133 115 134 116 135
Note: See TracChangeset
for help on using the changeset viewer.