示例#1
0
    def prepare_fit(self):
        """prepare parameters for fit
        determine which parameters are actually variables
        and which are defined expressions.
        """
        if self.__prepared:
            return
        if not isgroup(self.paramgroup):
            return 'param group is not a Larch Group'
        self.nfev_calls = 0
        self.var_names = []
        self.defvars = []
        self.vars = []
        for name in dir(self.paramgroup):
            par = getattr(self.paramgroup, name)
            if not isinstance(par, Parameter):
                continue
            if par.expr is not None:
                par.defvar = DefinedVariable(par.expr, _larch=self._larch)
                par.vary = False
                self.defvars.append(name)
            elif par.vary:
                self.var_names.append(name)
                self.vars.append(par.value)
            if par.name is None:
                par.name = name

        self.nvarys = len(self.vars)
        # now evaluate make sure initial values are set
        # are used to set values of the defined expressions.
        # this also acts as a check of expression syntax.
        self.__prepared = True
示例#2
0
    def __init__(self,
                 name=None,
                 value=None,
                 vary=True,
                 min=None,
                 max=None,
                 expr=None,
                 _larch=None,
                 **kws):
        self.name = name
        self.value = value
        self.init_value = value
        self.min = min
        self.max = max
        self.vary = vary
        self.expr = expr

        self.stderr = None
        self.correl = None
        self.defvar = None
        if self.expr is not None and _larch is not None:
            self.defvar = DefinedVariable(self.expr, _larch=_larch)
            self.vary = False
            self.value = self.defvar.evaluate()