Changeset dfd3577 in sasview
- Timestamp:
- Mar 24, 2011 1:52:25 PM (14 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:
- 0806def
- Parents:
- 91bdf87
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/ParkFitting.py
rb2f25dc5 rdfd3577 8 8 """ 9 9 #import time 10 #import numpy10 import numpy 11 11 #import park 12 12 from park import fit … … 14 14 from park.assembly import Assembly 15 15 from park.fitmc import FitSimplex 16 import park.fitmc 16 17 from park.fitmc import FitMC 17 18 … … 20 21 21 22 23 24 class MyAssembly(Assembly): 25 def __init__(self, models, curr_thread=None): 26 Assembly.__init__(self, models) 27 self.curr_thread = curr_thread 28 29 def eval(self): 30 """ 31 Recalculate the theory functions, and from them, the 32 residuals and chisq. 33 34 :note: Call this after the parameters have been updated. 35 """ 36 # Handle abort from a separate thread. 37 self._cancel = False 38 if self.curr_thread != None: 39 try: 40 self.curr_thread.isquit() 41 except: 42 self._cancel = True 43 44 # Evaluate the computed parameters 45 self._fitexpression() 46 47 # Check that the resulting parameters are in a feasible region. 48 if not self.isfeasible(): return numpy.inf 49 50 resid = [] 51 k = len(self._fitparameters) 52 for m in self.parts: 53 # In order to support abort, need to be able to propagate an 54 # external abort signal from self.abort() into an abort signal 55 # for the particular model. Can't see a way to do this which 56 # doesn't involve setting a state variable. 57 self._current_model = m 58 if self._cancel: return numpy.inf 59 if m.isfitted and m.weight != 0: 60 m.residuals = m.fitness.residuals() 61 N = len(m.residuals) 62 m.degrees_of_freedom = N-k if N>k else 1 63 m.chisq = numpy.sum(m.residuals**2) 64 resid.append(m.weight*m.residuals) 65 self.residuals = numpy.hstack(resid) 66 N = len(self.residuals) 67 self.degrees_of_freedom = N-k if N>k else 1 68 self.chisq = numpy.sum(self.residuals**2) 69 return self.chisq 70 22 71 class ParkFit(FitEngine): 23 72 """ … … 59 108 self.param_list = [] 60 109 61 def create_assembly(self ):110 def create_assembly(self, curr_thread): 62 111 """ 63 112 Extract sansmodel and sansdata from … … 88 137 else: 89 138 p.status = 'fixed' 90 #i += 191 139 data_list = item.get_data() 92 #parkdata=self._concatenateData(Ldata)93 140 parkdata = data_list 94 141 fitness = (parkmodel, parkdata) 95 142 mylist.append(fitness) 96 self.problem = Assembly(mylist)143 self.problem = MyAssembly(models=mylist, curr_thread=curr_thread) 97 144 145 146 98 147 def fit(self, q=None, handler=None, curr_thread=None): 99 148 """ … … 117 166 118 167 """ 119 self.create_assembly( )168 self.create_assembly(curr_thread=curr_thread) 120 169 localfit = FitSimplex() 121 170 localfit.ftol = 1e-8 … … 125 174 if handler == None: 126 175 handler = fitresult.ConsoleUpdate(improvement_delta=0.1) 127 result = fit.fit(self.problem, 128 fitter=fitter, 129 handler=handler) 176 result = fit.fit(self.problem, fitter=fitter, handler=handler) 130 177 self.problem.all_results(result) 131 178 if result != None:
Note: See TracChangeset
for help on using the changeset viewer.