Changeset 8d074d9 in sasview for src/sans/fit/ParkFitting.py


Ignore:
Timestamp:
May 8, 2014 4:19:04 PM (11 years ago)
Author:
pkienzle
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
Message:

refactor fit internals, enabling disperser parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sans/fit/ParkFitting.py

    rfb7180c r8d074d9  
    3737        """ 
    3838        park.Parameter.__init__(self, name) 
    39         self._model, self._name = model, name 
     39        #self._model, self._name = model, name 
    4040        self.data = data 
    4141        self.model = model 
     
    4343        self.set(model.getParam(name)) 
    4444 
     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 
    4550    def _getvalue(self): 
    4651        """ 
     
    5055 
    5156        """ 
    52         return self._model.getParam(self.name) 
     57        return self.model.getParam(self.name) 
    5358 
    5459    def _setvalue(self, value): 
     
    5964 
    6065        """ 
    61         self._model.setParam(self.name, value) 
     66        self.model.setParam(self.name, value) 
    6267 
    6368    value = property(_getvalue, _setvalue) 
     
    6974        """ 
    7075        #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] 
    7277        if lo is None: lo = -numpy.inf 
    7378        if hi is None: hi = numpy.inf 
     
    8994 
    9095        """ 
    91         self._model.details[self.name][1:3] = r 
     96        self.model.details[self.name][1:3] = r 
    9297    range = property(_getrange, _setrange) 
    9398 
     
    505510            model = item.get_model() 
    506511            parkmodel = ParkModel(model.model, model.data) 
     512            parkmodel.pars = item.pars 
    507513            if reset_flag: 
    508514                # reset the initial value; useful for batch 
     
    512518 
    513519            # set the constraints into the model 
    514             for p,v in model.constraints: 
     520            for p,v in item.constraints: 
    515521                parkmodel.parameterset[str(p)].set(str(v)) 
    516522             
     
    571577        except LinAlgError: 
    572578            raise ValueError, "SVD did not converge" 
     579 
     580        if result is None: 
     581            raise RuntimeError("park did not return a fit result") 
    573582     
    574583        for m in self.problem.parts: 
     
    578587            small_result.theory = theory 
    579588            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 
    600611            result_list.append(small_result)     
    601612        if q != None: 
Note: See TracChangeset for help on using the changeset viewer.