Changeset fd5ac0d in sasview for src/sas/fit
- Timestamp:
- Feb 13, 2015 3:26:52 AM (10 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:
- 7a04dbb
- Parents:
- b9a5f0e
- Location:
- src/sas/fit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/fit/AbstractFitEngine.py
r79492222 rfd5ac0d 65 65 class Model: 66 66 """ 67 Fit wrapper for SA NS models.68 """ 69 def __init__(self, sa ns_model, sans_data=None, **kw):70 """ 71 :param sa ns_model: the sas model to wrap using park interface72 73 """ 74 self.model = sa ns_model75 self.name = sa ns_model.name76 self.data = sa ns_data67 Fit wrapper for SAS models. 68 """ 69 def __init__(self, sas_model, sas_data=None, **kw): 70 """ 71 :param sas_model: the sas model to wrap using park interface 72 73 """ 74 self.model = sas_model 75 self.name = sas_model.name 76 self.data = sas_data 77 77 78 78 def get_params(self, fitparams): … … 128 128 class FitData1D(Data1D): 129 129 """ 130 Wrapper class for SA NS data130 Wrapper class for SAS data 131 131 FitData1D inherits from DataLoader.data_info.Data1D. Implements 132 132 a way to get residuals from data. … … 155 155 Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 156 156 self.num_points = len(x) 157 self.sa ns_data = data157 self.sas_data = data 158 158 self.smearer = smearer 159 159 self._first_unsmeared_bin = None … … 265 265 class FitData2D(Data2D): 266 266 """ 267 Wrapper class for SA NS data268 """ 269 def __init__(self, sa ns_data2d, data=None, err_data=None):267 Wrapper class for SAS data 268 """ 269 def __init__(self, sas_data2d, data=None, err_data=None): 270 270 Data2D.__init__(self, data=data, err_data=err_data) 271 271 # Data can be initialized with a sas plottable or with vectors. … … 278 278 self.radius = 0 279 279 self.res_err_data = [] 280 self.sa ns_data = sans_data2d281 self.set_data(sa ns_data2d)282 283 def set_data(self, sa ns_data2d, qmin=None, qmax=None):280 self.sas_data = sas_data2d 281 self.set_data(sas_data2d) 282 283 def set_data(self, sas_data2d, qmin=None, qmax=None): 284 284 """ 285 285 Determine the correct qx_data and qy_data within range to fit 286 286 """ 287 self.data = sa ns_data2d.data288 self.err_data = sa ns_data2d.err_data289 self.qx_data = sa ns_data2d.qx_data290 self.qy_data = sa ns_data2d.qy_data291 self.mask = sa ns_data2d.mask292 293 x_max = max(math.fabs(sa ns_data2d.xmin), math.fabs(sans_data2d.xmax))294 y_max = max(math.fabs(sa ns_data2d.ymin), math.fabs(sans_data2d.ymax))287 self.data = sas_data2d.data 288 self.err_data = sas_data2d.err_data 289 self.qx_data = sas_data2d.qx_data 290 self.qy_data = sas_data2d.qy_data 291 self.mask = sas_data2d.mask 292 293 x_max = max(math.fabs(sas_data2d.xmin), math.fabs(sas_data2d.xmax)) 294 y_max = max(math.fabs(sas_data2d.ymin), math.fabs(sas_data2d.ymax)) 295 295 296 296 ## fitting range … … 453 453 """ 454 454 if data.__class__.__name__ == 'Data2D': 455 fitdata = FitData2D(sa ns_data2d=data, data=data.data,455 fitdata = FitData2D(sas_data2d=data, data=data.data, 456 456 err_data=data.err_data) 457 457 else: 458 458 fitdata = FitData1D(x=data.x, y=data.y, 459 459 dx=data.dx, dy=data.dy, smearer=smearer) 460 fitdata.sa ns_data = data460 fitdata.sas_data = data 461 461 462 462 fitdata.set_fit_range(qmin=qmin, qmax=qmax) -
src/sas/fit/BumpsFitting.py
r79492222 rfd5ac0d 12 12 from bumps.fitproblem import FitProblem 13 13 14 from sas import FitEngine15 from sas import FResult16 from sas import compile_constraints14 from sas.fit.AbstractFitEngine import FitEngine 15 from sas.fit.AbstractFitEngine import FResult 16 from sas.fit.expression import compile_constraints 17 17 18 18 class Progress(object): … … 91 91 # The disadvantage of this technique is that we need to copy every parameter 92 92 # back into the model each time the function is evaluated. We could instead 93 # define reference parameters for each sa ns parameter, but then we would not93 # define reference parameters for each sas parameter, but then we would not 94 94 # be able to express constraints using python expressions in the usual way 95 95 # from bumps, and would instead need to use string expressions. -
src/sas/fit/ParkFitting.py
r79492222 rfd5ac0d 3 3 4 4 """ 5 ParkFitting module contains Sa nsParameter,Model,Data5 ParkFitting module contains SasParameter,Model,Data 6 6 FitArrange, ParkFit,Parameter classes.All listed classes work together 7 7 to perform a simple fit with park optimizer. … … 25 25 from sas.fit.AbstractFitEngine import FResult 26 26 27 class Sa nsParameter(park.Parameter):28 """ 29 SA NS model parameters for use in the PARK fitting service.27 class SasParameter(park.Parameter): 28 """ 29 SAS model parameters for use in the PARK fitting service. 30 30 The parameter attribute value is redirected to the underlying 31 parameter value in the SA NS model.31 parameter value in the SAS model. 32 32 """ 33 33 def __init__(self, name, model, data): … … 100 100 class ParkModel(park.Model): 101 101 """ 102 PARK wrapper for SA NS models.103 """ 104 def __init__(self, sa ns_model, sans_data=None, **kw):105 """ 106 :param sa ns_model: the sas model to wrap using park interface102 PARK wrapper for SAS models. 103 """ 104 def __init__(self, sas_model, sas_data=None, **kw): 105 """ 106 :param sas_model: the sas model to wrap using park interface 107 107 108 108 """ 109 109 park.Model.__init__(self, **kw) 110 self.model = sa ns_model111 self.name = sa ns_model.name112 self.data = sa ns_data110 self.model = sas_model 111 self.name = sas_model.name 112 self.data = sas_data 113 113 #list of parameters names 114 self.sa nsp = sans_model.getParamList()114 self.sasp = sas_model.getParamList() 115 115 #list of park parameter 116 self.parkp = [Sa nsParameter(p, sans_model, sans_data) for p in self.sansp]116 self.parkp = [SasParameter(p, sas_model, sas_data) for p in self.sasp] 117 117 #list of parameter set 118 self.parameterset = park.ParameterSet(sa ns_model.name, pars=self.parkp)118 self.parameterset = park.ParameterSet(sas_model.name, pars=self.parkp) 119 119 self.pars = [] 120 120 … … 176 176 177 177 178 class Sa nsFitResult(fitresult.FitResult):178 class SasFitResult(fitresult.FitResult): 179 179 def __init__(self, *args, **kwrds): 180 180 fitresult.FitResult.__init__(self, *args, **kwrds) … … 182 182 self.inputs = [] 183 183 184 class Sa nsFitSimplex(FitSimplex):184 class SasFitSimplex(FitSimplex): 185 185 """ 186 186 Local minimizer using Nelder-Mead simplex algorithm. … … 216 216 # Need to make our own copy of the fit results so that the 217 217 # values don't get stomped on by the next fit iteration. 218 fitpars = [Sa nsFitParameter(pars[i].name,pars[i].range,v, pars[i].model, pars[i].data)218 fitpars = [SasFitParameter(pars[i].name,pars[i].range,v, pars[i].model, pars[i].data) 219 219 for i,v in enumerate(result.x)] 220 res = Sa nsFitResult(fitpars, result.calls, result.fx)220 res = SasFitResult(fitpars, result.calls, result.fx) 221 221 res.inputs = [(pars[i].model, pars[i].data) for i,v in enumerate(result.x)] 222 222 # Compute the parameter uncertainties from the jacobian … … 224 224 return res 225 225 226 class Sa nsFitter(Fitter):226 class SasFitter(Fitter): 227 227 """ 228 228 """ … … 243 243 handler.done = False 244 244 self.handler = handler 245 fitpars = [Sa nsFitParameter(pars[i].name, pars[i].range, v,245 fitpars = [SasFitParameter(pars[i].name, pars[i].range, v, 246 246 pars[i].model, pars[i].data) 247 247 for i,v in enumerate(x0)] … … 252 252 self._fit(fitness, x0, bounds) 253 253 254 class Sa nsFitMC(SansFitter):254 class SasFitMC(SasFitter): 255 255 """ 256 256 Monte Carlo optimizer. … … 258 258 This implements `park.fit.Fitter`. 259 259 """ 260 localfit = Sa nsFitSimplex()260 localfit = SasFitSimplex() 261 261 start_points = 10 262 262 def __init__(self, localfit, start_points=10): … … 276 276 raise ValueError, "Fit did not converge.\n" 277 277 278 class Sa nsPart(Part):278 class SasPart(Part): 279 279 """ 280 280 Part of a fitting assembly. Part holds the model itself and … … 318 318 self.model, self.data = fitness[0], fitness[1] 319 319 320 class Sa nsFitParameter(FitParameter):320 class SasFitParameter(FitParameter): 321 321 """ 322 322 Fit result for an individual parameter. … … 363 363 self.parts = [] 364 364 for m in models: 365 self.parts.append(Sa nsPart(m))365 self.parts.append(SasPart(m)) 366 366 self.curr_thread = curr_thread 367 367 self.chisq = None … … 390 390 # Convert to fitparameter a object 391 391 392 fitpars = [Sa nsFitParameter(p.path,p.range,p.value, p.model, p.data)392 fitpars = [SasFitParameter(p.path,p.range,p.value, p.model, p.data) 393 393 for p in self._fitparameters] 394 394 #print "fitpars", fitpars … … 399 399 Extend result from the fit with the calculated parameters. 400 400 """ 401 calcpars = [Sa nsFitParameter(p.path,p.range,p.value, p.model, p.data)401 calcpars = [SasFitParameter(p.path,p.range,p.value, p.model, p.data) 402 402 for p in self.parameterset.computed] 403 403 result.parameters += calcpars … … 493 493 def create_assembly(self, curr_thread, reset_flag=False): 494 494 """ 495 Extract sa nsmodel and sansdata from495 Extract sasmodel and sasdata from 496 496 self.FitArrangelist ={Uid:FitArrange} 497 497 Create parkmodel and park data ,form a list couple of parkmodel … … 562 562 """ 563 563 self.create_assembly(curr_thread=curr_thread, reset_flag=reset_flag) 564 localfit = Sa nsFitSimplex()564 localfit = SasFitSimplex() 565 565 localfit.ftol = ftol 566 566 localfit.xtol = 1e-6 567 567 568 568 # See `park.fitresult.FitHandler` for details. 569 fitter = Sa nsFitMC(localfit=localfit, start_points=1)569 fitter = SasFitMC(localfit=localfit, start_points=1) 570 570 if handler == None: 571 571 handler = fitresult.ConsoleUpdate(improvement_delta=0.1) … … 584 584 for m in self.problem.parts: 585 585 residuals, theory = m.fitness.residuals() 586 small_result = FResult(model=m.model, data=m.data.sa ns_data)586 small_result = FResult(model=m.model, data=m.data.sas_data) 587 587 small_result.fitter_id = self.fitter_id 588 588 small_result.theory = theory -
src/sas/fit/ScipyFitting.py
r79492222 rfd5ac0d 14 14 _SMALLVALUE = 1.0e-10 15 15 16 class Sa nsAssembly:17 """ 18 Sa ns Assembly class a class wrapper to be call in optimizer.leastsq method16 class SasAssembly: 17 """ 18 Sas Assembly class a class wrapper to be call in optimizer.leastsq method 19 19 """ 20 20 def __init__(self, paramlist, model=None, data=None, fitresult=None, … … 212 212 if handler is not None: 213 213 handler.set_result(result=result) 214 functor = Sa nsAssembly(paramlist=pars,214 functor = SasAssembly(paramlist=pars, 215 215 model=model, 216 216 data=data,
Note: See TracChangeset
for help on using the changeset viewer.