samvaughan / PyStaff

Spectral Fitting with CvD stellar population models
MIT License
5 stars 2 forks source link

error message in fit_example.py with results_theta.add() #8

Open afeldmei opened 6 years ago

afeldmei commented 6 years ago

I run fit_example.py and get an error message. After running emcee, when the code makes a set of parameters with the results, I get the following error:


ValueError Traceback (most recent call last) /Users/afeldmei/software/PyStaff-master/fit_example.py in () 256 results_theta=LM.Parameters() 257 for v, r in zip(variables, best_results): --> 258 results_theta.add('{}'.format(v), value=r, vary=False) 259 #... and plot 260 SF.plot_fit(results_theta, fit.fit_settings)

/Users/afeldmei/anaconda/lib/python2.7/site-packages/lmfit/parameter.pyc in add(self, name, value, vary, min, max, expr, brute_step) 333 self.setitem(name, Parameter(value=value, name=name, vary=vary, 334 min=min, max=max, expr=expr, --> 335 brute_step=brute_step)) 336 337 def add_many(self, *parlist):

/Users/afeldmei/anaconda/lib/python2.7/site-packages/lmfit/parameter.pyc in init(self, name, value, vary, min, max, expr, brute_step, user_data) 556 self.correl = None 557 self.from_internal = lambda val: val --> 558 self._init_bounds() 559 560 def set(self, value=None, vary=None, min=None, max=None, expr=None,

/Users/afeldmei/anaconda/lib/python2.7/site-packages/lmfit/parameter.pyc in _init_bounds(self) 643 if isclose(self.min, self.max, atol=1e-13, rtol=1e-13): 644 raise ValueError("Parameter '%s' has min == max" % self.name) --> 645 if self._val > self.max: 646 self._val = self.max 647 if self._val < self.min:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I use lmfit 0.9.11, numpy 1.11.3, and python 2.7.15

afeldmei commented 6 years ago

I ran fit_example.py on another computer with python 2.7.8 and got an error at the same location:

Traceback (most recent call last): File "fit_example.py", line 260, in results_theta.add('{}'.format(v), value=r, vary=False) AttributeError: 'Parameter' object has no attribute 'add'

Any idea how to solve it?

samvaughan commented 6 years ago

I think your first error was a silly mistake on my part- you can just replace

results_theta=LM.Parameters()
for v, r in zip(variables, best_results):
    print(v, r)
    results_theta.add('{}'.format(v), value=r, vary=False)

with

results_theta=LM.Parameters()
for v, r in zip(variables, best_results):
    print(v, r)
    results_theta.add('{}'.format(v), value=r[0], vary=False)

i.e. only select the first element of the row of best_results. Your second comment I'm not too sure about and can't reproduce- but if you could try again with the updated code (commit c84ff5a11a5421ecd2ef0137826481f702562f94) and see how you get on?