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

Replace scipy.optimize.curve_fit / uncertaintes with iminuit? #273

Open
maxnoe opened this issue Sep 2, 2021 · 1 comment
Open

Replace scipy.optimize.curve_fit / uncertaintes with iminuit? #273

maxnoe opened this issue Sep 2, 2021 · 1 comment

Comments

@maxnoe
Copy link
Member

maxnoe commented Sep 2, 2021

Brought up by @HDembinski in the E5 chat, we should evaluate if we want to switch from teaching the curve_fit / uncertainties combination to using iminuit (iminuit.utils.propagate for uncertainty propagation).

@maxnoe maxnoe changed the title Replace scipy.optimize.curve_fit / uncertaintes with iminuit Replace scipy.optimize.curve_fit / uncertaintes with iminuit? Sep 2, 2021
@HDembinski
Copy link

HDembinski commented Jan 11, 2022

My main argument is that we should teach people tools that are simple to use for simple things, but which also scale to complex scenarios when the need arises later.

  • curve_fit is great but limited to non-linear least-squares. It does not generalize like iminuit, which can be used with least-squares cost functions and maximum likelihood, further with robust least-squares, etc. By learning iminuit, even if you we do not teach the advanced functionality, we already point people to a tool they will likely use again later and that is able to grow with their needs. curve_fit cannot do that.

  • iminuit.utils.propagate vs. uncertainties: The popular uncertainties package is similarly a dead end. It works for simple stuff, but it does not scale to complex situations. uncertainties is invasive, it requires you to replace ordinary numpy arrays with its own special arrays. You cannot pass these arrays to code that expects numpy arrays, for example, a C++ function that you wrapped to Python with pybind11. uncertainties behind the scenes introduces couplings between arrays that appear to be separate. This goes against a fundamental design principle that objects in object oriented programming should behave independently from each other. Violating this principle makes the code difficult to reason about. All these problems do not exist for iminuit.utils.propagate. It works with any function that accepts and returns numpy arrays (whether plain Python, numba-jitted, or implemented in C++ and wrapped to Python) and it keeps the values (a vector) and their covariance matrix (a matrix) as two separate objects. It is not invasive since it does not require you to change your code at all. It is also quite natural to use the parameter vector and the covariance matrix as separate objects, since that is what you get from fitting tools, be it curve_fit or iminuit.

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

No branches or pull requests

2 participants