- Timestamp:
- May 8, 2014 4:19:04 PM (11 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:
- 76f132a
- Parents:
- 4de1fed
- Location:
- src/sans/fit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/fit/AbstractFitEngine.py
rfb7180c r8d074d9 421 421 422 422 """ 423 if model == None: 424 raise ValueError, "AbstractFitEngine: Need to set model to fit" 425 423 if not pars: 424 raise ValueError("no fitting parameters") 425 426 if model is None: 427 raise ValueError("no model to fit") 428 426 429 if not issubclass(model.__class__, Model): 427 430 model = Model(model, data) 428 431 429 432 sasmodel = model.model 430 model.constraints = constraints 431 432 if len(pars) > 0: 433 temp = [] 434 for item in pars: 435 if item in sasmodel.getParamList(): 436 temp.append(item) 437 self.param_list.append(item) 438 else: 439 440 msg = "wrong parameter %s used " % str(item) 441 msg += "to set model %s. Choose " % str(sasmodel.name) 442 msg += "parameter name within %s" % \ 443 str(sasmodel.getParamList()) 444 raise ValueError, msg 445 446 #A fitArrange is already created but contains data_list only at id 447 if self.fit_arrange_dict.has_key(id): 448 self.fit_arrange_dict[id].set_model(model) 449 self.fit_arrange_dict[id].pars = pars 450 else: 451 #no fitArrange object has been create with this id 452 fitproblem = FitArrange() 453 fitproblem.set_model(model) 454 fitproblem.pars = pars 455 self.fit_arrange_dict[id] = fitproblem 456 vals = [] 457 for name in pars: 458 vals.append(sasmodel.getParam(name)) 459 self.fit_arrange_dict[id].vals = vals 460 else: 461 raise ValueError, "park_integration:missing parameters" 462 433 available_parameters = sasmodel.getParamList() 434 for p in pars: 435 if p not in available_parameters: 436 raise ValueError("parameter %s not available in model %s; use one of [%s] instead" 437 %(p, sasmodel.name, ", ".join(available_parameters))) 438 439 if id not in self.fit_arrange_dict: 440 self.fit_arrange_dict[id] = FitArrange() 441 442 self.fit_arrange_dict[id].set_model(model) 443 self.fit_arrange_dict[id].pars = pars 444 self.fit_arrange_dict[id].vals = [sasmodel.getParam(name) for name in pars] 445 self.fit_arrange_dict[id].constraints = constraints 446 447 self.param_list.extend(pars) 448 463 449 def set_data(self, data, id, smearer=None, qmin=None, qmax=None): 464 450 """ … … 542 528 self.vals = [] 543 529 self.selected = 0 544 530 545 531 def set_model(self, model): 546 532 """ … … 594 580 """ 595 581 return self.selected 596 597 582 598 583 class FResult(object): 599 584 """ -
src/sans/fit/BumpsFitting.py
rfb7180c r8d074d9 121 121 return the range of parameter 122 122 """ 123 lo, hi = self.model.details [p][1:3]123 lo, hi = self.model.details.get(p,["",None,None])[1:3] 124 124 if lo is None: lo = -numpy.inf 125 125 if hi is None: hi = numpy.inf -
src/sans/fit/ParkFitting.py
rfb7180c r8d074d9 37 37 """ 38 38 park.Parameter.__init__(self, name) 39 self._model, self._name = model, name39 #self._model, self._name = model, name 40 40 self.data = data 41 41 self.model = model … … 43 43 self.set(model.getParam(name)) 44 44 45 # TODO: model is missing parameter ranges for dispersion parameters 46 if name not in model.details: 47 #print "setting details for",name 48 model.details[name] = ["", None, None] 49 45 50 def _getvalue(self): 46 51 """ … … 50 55 51 56 """ 52 return self. _model.getParam(self.name)57 return self.model.getParam(self.name) 53 58 54 59 def _setvalue(self, value): … … 59 64 60 65 """ 61 self. _model.setParam(self.name, value)66 self.model.setParam(self.name, value) 62 67 63 68 value = property(_getvalue, _setvalue) … … 69 74 """ 70 75 #if not self.name in self._model.getDispParamList(): 71 lo, hi = self. _model.details[self.name][1:3]76 lo, hi = self.model.details[self.name][1:3] 72 77 if lo is None: lo = -numpy.inf 73 78 if hi is None: hi = numpy.inf … … 89 94 90 95 """ 91 self. _model.details[self.name][1:3] = r96 self.model.details[self.name][1:3] = r 92 97 range = property(_getrange, _setrange) 93 98 … … 505 510 model = item.get_model() 506 511 parkmodel = ParkModel(model.model, model.data) 512 parkmodel.pars = item.pars 507 513 if reset_flag: 508 514 # reset the initial value; useful for batch … … 512 518 513 519 # set the constraints into the model 514 for p,v in model.constraints:520 for p,v in item.constraints: 515 521 parkmodel.parameterset[str(p)].set(str(v)) 516 522 … … 571 577 except LinAlgError: 572 578 raise ValueError, "SVD did not converge" 579 580 if result is None: 581 raise RuntimeError("park did not return a fit result") 573 582 574 583 for m in self.problem.parts: … … 578 587 small_result.theory = theory 579 588 small_result.residuals = residuals 580 small_result.pvec = [] 581 small_result.cov = [] 582 small_result.stderr = [] 583 small_result.param_list = [] 584 small_result.residuals = m.residuals 585 if result is not None: 586 for p in result.parameters: 587 #if p.data.name == small_result.data.name and 588 if p.model.name == small_result.model.name: 589 small_result.index = m.data.idx 590 small_result.fitness = result.fitness 591 small_result.pvec.append(p.value) 592 small_result.stderr.append(p.stderr) 593 name_split = p.name.split('.') 594 name = name_split[1].strip() 595 if len(name_split) > 2: 596 name += '.' + name_split[2].strip() 597 small_result.param_list.append(name) 598 # normalize chisq by degrees of freedom 599 small_result.fitness /= len(small_result.residuals)-len(small_result.pvec) 589 small_result.index = m.data.idx 590 small_result.fitness = result.fitness 591 592 # Extract the parameters that are part of this model; make sure 593 # they match the fitted parameters for this model, and place them 594 # in the same order as they occur in the model. 595 pars = {} 596 for p in result.parameters: 597 #if p.data.name == small_result.data.name and 598 if p.model.name == small_result.model.name: 599 model_name, par_name = p.name.split('.', 1) 600 pars[par_name] = (p.value, p.stderr) 601 #assert len(pars.keys()) == len(m.model.pars) 602 v,dv = zip(*[pars[p] for p in m.model.pars]) 603 small_result.pvec = v 604 small_result.stderr = dv 605 small_result.param_list = m.model.pars 606 607 # normalize chisq by degrees of freedom 608 dof = len(small_result.residuals)-len(small_result.pvec) 609 small_result.fitness = numpy.sum(residuals**2)/dof 610 600 611 result_list.append(small_result) 601 612 if q != None: -
src/sans/fit/ScipyFitting.py
r042f065 r8d074d9 206 206 207 207 result = FResult(model=model.model, data=data, param_list=self.param_list) 208 result.pars = fitproblem[0].pars209 208 result.fitter_id = self.fitter_id 210 209 if handler is not None: … … 268 267 for p in param_list: 269 268 value = model.getParam(p) 270 low,high = model.details [p][1:3]269 low,high = model.details.setdefault(p,["",None,None])[1:3] 271 270 # if the range was defined, check the range 272 271 if low is not None and value <= low:
Note: See TracChangeset
for help on using the changeset viewer.