Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

least_squares fit using migrad is broken #51

Closed
s-kuberski opened this issue Feb 1, 2022 · 2 comments · Fixed by #52
Closed

least_squares fit using migrad is broken #51

s-kuberski opened this issue Feb 1, 2022 · 2 comments · Fixed by #52
Labels
bug Something isn't working

Comments

@s-kuberski
Copy link
Collaborator

import pyerrors as pe
import numpy as np
x = np.arange(10)
y = [pe.pseudo_Obs(i+1, i*.2+.01, 'test') for i in x]
[o.gamma_method() for o in y]
def func(a, x):
    return a[0] + a[1] * x
pe.fits.least_squares(x, y, func)
pe.fits.least_squares(x, y, func, method='migrad')

results in

KeyError                                  Traceback (most recent call last)
/opt/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in __getattr__(self, name)
    121         try:
--> 122             return self[name]
    123         except KeyError:

KeyError: 'nit'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-18-79beea198971> in <module>
      7     return a[0] + a[1] * x
      8 pe.fits.least_squares(x, y, func)
----> 9 pe.fits.least_squares(x, y, func, method='migrad')

~/phd/git/pyerrors_github/pyerrors/fits.py in least_squares(x, y, func, priors, silent, **kwargs)
    118         return _prior_fit(x, y, func, priors, silent=silent, **kwargs)
    119     else:
--> 120         return _standard_fit(x, y, func, silent=silent, **kwargs)
    121 
    122 

~/phd/git/pyerrors_github/pyerrors/fits.py in _standard_fit(x, y, func, silent, **kwargs)
    501         chisquare = fit_result.fun
    502 
--> 503         output.iterations = fit_result.nit
    504     else:
    505         output.method = 'Levenberg-Marquardt'

/opt/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in __getattr__(self, name)
    122             return self[name]
    123         except KeyError:
--> 124             raise AttributeError(name)
    125 
    126     __setattr__ = dict.__setitem__

AttributeError: nit

using python3.6 and migrad 2.8.4 (and 2.8.3)

@s-kuberski s-kuberski added the bug Something isn't working label Feb 1, 2022
@fjosw
Copy link
Owner

fjosw commented Feb 1, 2022

In the back of my head I was aware that the migration to iminuit 2.0 broke this routine. The question is whether we want to keep the option for several solver in the least_squares routine or just support the scipy one.

@s-kuberski
Copy link
Collaborator Author

I like the possibility to switch to migrad, just to see if everything is stable.

@fjosw fjosw closed this as completed in #52 Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants