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

Crash in visualization #966

Closed
claudiocc1 opened this issue Feb 8, 2024 · 4 comments · Fixed by #968
Closed

Crash in visualization #966

claudiocc1 opened this issue Feb 8, 2024 · 4 comments · Fixed by #968

Comments

@claudiocc1
Copy link

hi,

I went back to an old project. It used to work with the then-current version of iminuit. Sorry, cannnot remember the exact version. Now it crashes with iminuit 2.25 (python 3.11.5, Intel Mac.).

The fit actually works, and gives the exact same result now as it used to. I think the crash is in the visualization part, which I guess has been added since?

Here you can find my jupyter notebook, stripped down to the bare minimum (html and ipynb versions)
http://hep.ucsb.edu/people/claudio/minuit/

Thanks.

Claudio

PS is there a way to turn off the visualization?

@HDembinski
Copy link
Member

Thanks for reporting, that is indeed a bug. I will see how this can be fixed. A temporary workaround for you is

# Minuit fit
p0 = np.array([2., 2., 0., -1., -1.5])
mFit = LeastSquares(x, y, ey, fitFun)
mFit.visualize = lambda x, *args: None
m = Minuit(mFit, p0)  # pass starting values
m.migrad()
# m.hesse()

HDembinski added a commit that referenced this issue Feb 8, 2024
Closes #966 

`LeastSquares.model` can now be used to uniformly call models which
accept parameter values and parameter arrays in the same way, as already
indicated by the docstring.
@HDembinski
Copy link
Member

HDembinski commented Feb 8, 2024

If you want to fit a smooth function $f(x)$ through your data points under the condition $f(x) \ge 0$, you can also use Bernstein polynomials. They are guaranteed to be positive inside the domain, if all the parameters are positive. You cannot safely extrapolate Bernstein polynomials outside their domain, though. If you need to query the function outside the fitted range, make the domain of the polynomial as large as you need to query it.

from numba_stats import bernstein

def model(x, p):
    domain_of_polynomial = (-0.4, 0.4)
    return bernstein.density(x, p, *domain_of_polynomial)

start = np.ones(4)  # increase this to increase flexibility of Bernstein polynomial
m = Minuit(LeastSquares(x, y, ey, model), start) 
m.limits = (0, None)  # ensure positiveness
m.migrad()

@claudiocc1
Copy link
Author

Yes I know :)
We are working with people that like splines (I dont), so here we are....
C.

@HDembinski
Copy link
Member

I like splines, too :). Bernstein polynomials are a special case of splines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants