Changeset 8d074d9 in sasview for src/sans/fit/ParkFitting.py
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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:
Note: See TracChangeset
for help on using the changeset viewer.