def test_set_nested_symbol(self): """set nested symbol in table""" self.s.set_symbol("_main.foo.bar.baz", value=1) self.assert_(hasattr(self.s._main, "foo")) self.assert_(isgroup(getattr(self.s._main, "foo"))) self.assert_(hasattr(self.s._main.foo, "bar")) self.assert_(isgroup(getattr(self.s._main.foo, "bar"))) self.assert_(hasattr(self.s._main.foo.bar, "baz")) self.assert_(self.s._main.foo.bar.baz == 1)
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
def minimize(fcn, group, args=None, kws=None, scale_covar=True, iter_cb=None, _larch=None, **fit_kws): """simple minimization function, finding the values for the params which give the minimal sum-of-squares of the array return by fcn """ if not isgroup(group): return 'param group is not a Larch Group' fitter = Minimizer(fcn, group, fcn_args=args, fcn_kws=kws, iter_cb=iter_cb, scale_covar=scale_covar, _larch=_larch, **fit_kws) return fitter.leastsq()
def test_group(self): '''group builtin''' self.eval('g = group()') self.assert_(isgroup(self.li.symtable.g))