Changeset 393f0f3 in sasview
- Timestamp:
- Jan 26, 2010 11:09:19 AM (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:
- 693500a
- Parents:
- 3c67340
- Location:
- park_integration
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r6d20b46 r393f0f3 1 1 import logging, sys 2 import copy3 from copy import deepcopy4 2 import park,numpy,math, copy 5 3 from DataLoader.data_info import Data1D … … 81 79 self.pars=[] 82 80 83 def clone(self): 84 model = self.model.clone() 85 model.name = self.model.name 86 return Model(model) 81 87 82 def getParams(self,fitparams): 88 83 """ … … 120 115 """ 121 116 try: 122 117 return self.model.evalDistribution(x) 123 118 except: 124 119 raise 125 120 126 121 … … 342 337 Sans Assembly class a class wrapper to be call in optimizer.leastsq method 343 338 """ 344 def __init__(self,paramlist, model=None , data=None, curr_thread= None):345 """ 346 @param model: the model wrapper forsans -model347 @param data: the data wrapper for sans data348 """ 349 self.model = model.clone()350 self.data = deepcopy(data)351 self.paramlist = deepcopy(paramlist)339 def __init__(self,paramlist,Model=None , Data=None, curr_thread= None): 340 """ 341 @param Model: the model wrapper fro sans -model 342 @param Data: the data wrapper for sans data 343 """ 344 self.model = Model 345 self.data = Data 346 self.paramlist=paramlist 352 347 self.curr_thread= curr_thread 353 348 self.res=[] … … 462 457 if model == None: 463 458 raise ValueError, "AbstractFitEngine: Need to set model to fit" 464 #print "set_model",model.name 465 #new_model= deepcopy(model) 466 new_model = model.clone() 467 new_model.name = model.name 468 if not issubclass(new_model.__class__, Model): 469 new_model= Model(new_model) 459 460 new_model= model 461 if not issubclass(model.__class__, Model): 462 new_model= Model(model) 470 463 471 464 if len(constraints)>0: … … 513 506 @param Uid: unique key corresponding to a fitArrange object with data 514 507 """ 515 #print "set_data",data.__class__.__name__516 508 if data.__class__.__name__=='Data2D': 517 509 fitdata=FitData2D(sans_data2d=data, data=data.data, err_data= data.err_data) 518 510 else: 519 511 fitdata=FitData1D(x=data.x, y=data.y , dx= data.dx,dy=data.dy,smearer=smearer) 520 512 521 513 fitdata.setFitRange(qmin=qmin,qmax=qmax) 522 514 #A fitArrange is already created but contains model only at Uid … … 586 578 """ 587 579 self.model = model 588 self.model.name = model.name589 580 590 581 def add_data(self,data): -
park_integration/Fitting.py
r6d20b46 r393f0f3 22 22 engine.set_param( model,model.name, pars) 23 23 engine.set_model(model,Uid) 24 engine.select_problem_for_fit(Uid,value)24 25 25 chisqr1, out1, cov1=engine.fit(pars,qmin,qmax) 26 26 """ -
park_integration/ScipyFitting.py
r6d20b46 r393f0f3 56 56 with Uid as keys 57 57 """ 58 self.fitArrangeDict ={}59 self.paramList =[]58 self.fitArrangeDict={} 59 self.paramList=[] 60 60 #def fit(self, *args, **kw): 61 61 # return profile(self._fit, *args, **kw) 62 def createFunctor(self): 63 fitproblem=None 64 fit_count = 0 65 #print " self.fitArrangeDict", self.fitArrangeDict 66 for id, fproblem in self.fitArrangeDict.iteritems(): 67 if fproblem.get_to_fit() == 1: 68 fitproblem = fproblem 69 fit_count += 1 70 if fit_count > 1 : 62 63 def fit(self ,q=None,handler=None,curr_thread= None): 64 65 fitproblem=[] 66 for id ,fproblem in self.fitArrangeDict.iteritems(): 67 if fproblem.get_to_fit()==1: 68 fitproblem.append(fproblem) 69 if len(fitproblem)>1 : 71 70 raise RuntimeError, "Scipy can't fit more than a single fit problem at a time." 72 71 return 73 elif fit_count ==0 :72 elif len(fitproblem)==0 : 74 73 raise RuntimeError, "No Assembly scheduled for Scipy fitting." 75 74 return 76 75 77 listdata = [] 78 model = fitproblem.get_model().clone() 79 data = fitproblem.get_data() 80 76 listdata=[] 77 model = fitproblem[0].get_model() 78 listdata = fitproblem[0].get_data() 81 79 # Concatenate dList set (contains one or more data)before fitting 82 80 #data=self._concatenateData( listdata) 83 #data =listdata84 #self.curr_thread= curr_thread81 data=listdata 82 self.curr_thread= curr_thread 85 83 86 84 #try: 87 functor = SansAssembly(self.paramList, model, data)#, curr_thread= curr_thread) 88 return functor , model 89 90 def fit(self, q=None, handler=None, curr_thread=None): 91 92 functor , model = self.createFunctor() 93 94 out, cov_x, info, mesg, success = optimize.leastsq(functor, 95 model.getParams(self.paramList), 96 full_output=1, warning=True) 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) 97 87 98 88 chisqr = functor.chisq(out) … … 108 98 result.pvec = out 109 99 result.success = success 110 if q is notNone:100 if q !=None: 111 101 print "went here" 112 102 q.put(result) … … 115 105 return result 116 106 else: 117 raise ValueError, "SVD did not converge" +str(success)107 raise ValueError, "SVD did not converge"+str(success) 118 108 #except FitAbort: 119 109 ## fit engine is stop
Note: See TracChangeset
for help on using the changeset viewer.