from lmfit import Model, fit_report, Parameters, Parameter
def ln_model(M:float,B:float,sequence=None): model_data = [] alter_dict: {'a':M*3+B,'d':2*M*3+2*B,'c':3*M*3+3*B} for seq in sequence: alteration = alter_dict['seq'] model_data.append(alteration) return np.array(model_data)
class LinearModel(Model): def __init__(self, *args, **kwargs): super(LinearModel, self).__init__(ln_model, *args, **kwargs) m = Model(ln_model,independent_vars=['a','c','d'])pars = Parameters() #2-parameter fit modelpars.add(name='M',value=1,vary=True)pars.add(name='B',value=0,vary=True)original_sequence = ['a','c','d'] #Array with ordering to conform the data tokeys = ['c','d','a'] #Data keys, with altered ordering data_list = [-1,0,1] data_dict = {key: val for key,val in zip(keys,data_list)}
#perform the fit on data_dict.values() to try and find best fit values for our parameters (M,B) fit = m.fit( np.array(data_dict.values()), params=pars, sequence=list(data_dict.keys()))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-a34f5dd3c58f> in <module>
14 super(LinearModel, self).__init__(ln_model, *args, **kwargs)
15
---> 16 m = Model(ln_model,independent_vars=['a','c'])
17 pars = Parameters() #2-parameter fit model
18 pars.add(name='M',value=1,vary=True)
~/miniconda3/envs/v6.0.0/lib/python3.6/site-packages/lmfit/model.py in __init__(self, func, independent_vars, param_names, nan_policy, missing, prefix, name, **kws)
153 # the following has been changed from OrderedSet for the time being
154 self._param_names = []
--> 155 self._parse_params()
156 if self.independent_vars is None:
157 self.independent_vars = []
~/miniconda3/envs/v6.0.0/lib/python3.6/site-packages/lmfit/model.py in _parse_params(self)
408 for arg in self.independent_vars:
409 if arg not in allargs or arg in self._forbidden_args:
--> 410 raise ValueError(self._invalid_ivar % (arg, fname))
411 for arg in names:
412 if (self._strip_prefix(arg) not in allargs or
ValueError: Invalid independent variable name ('a') for function ln_model
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/e657bd33-beb3-4df1-9c3a-71d5388925dc%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbqeeTCnw2tmnMvHB8vnEbub44QPLrA4pRBzsRB--AYGNA%40mail.gmail.com.
I'm also interested in an answer to this question if someone knows how to do it.
Also fwiw I think this post is adhering to the rules of this forum and deserves a better response.
Result [[Model]] Model(myfunction) [[Fit Statistics]] # fitting method = leastsq # function evals = 5 # data points = 100 # variables = 1 chi-square = 0.00000000 reduced chi-square = 0.00000000 Akaike info crit = -inf Bayesian info crit = -inf ## Warning: uncertainties could not be estimated: [[Variables]] amplitude: 2.00000000 +/- 0.00000000 (0.00%) (init = 1) Different result [[Model]] Model(myfunction) [[Fit Statistics]] # fitting method = leastsq # function evals = 5 # data points = 100 # variables = 1 chi-square = 0.00000000 reduced chi-square = 0.00000000 Akaike info crit = -inf Bayesian info crit = -inf ## Warning: uncertainties could not be estimated: [[Variables]] amplitude: 3.00000000 +/- 0.00000000 (0.00%) (init = 1)
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/9f8dc342-7692-48a6-912e-ef3494c1b1d4%40googlegroups.com.