API for function fitting #121
Replies: 2 comments
-
Concerning the generic API, the order seem good. We should however be able to get par, err systematically while retaining yerr optional. Of course, the absence of yerr should be handled adequately for each case since setting an array of 0 results in unwanted behaviours. par, err = fit_gaus(x,y) #fit without errors
par, err = fit_gaus(x,y, yerr) #fit with errors or:
par, err = fit_gaus(x, y, yerr=yerr) #Op Everything else proposed seem to be work. Should we however try to find a way to pass any function easily from python as in scipy.optimize.curve_fit? curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False, check_finite=None, bounds=(-inf, inf), method=None, jac=None, *, full_output=False, nan_policy=None, **kwargs) |
Beta Was this translation helpful? Give feedback.
-
API Passing x and then y I guess makes sense. However when having a multiple pixels somehow fit_gaus(data, x) comes more natural. But let's be consistent. par = fit_gaus(x,y) #fit without errors (no errors returned)
#I would allow both:
par, err = fit_gaus(x,y, yerr) #fit with errors or:
par, err = fit_gaus(x, y, yerr=yerr) #Op I'll make the changes in the lmfit branch Generic interface Regarding a generic interface I'm not so sure... the main advantage with integrating the fitting in the library is that we call a C function from C. Passing a generic function from Python would be orders of magnitude slower, and we still have less features than scipy or PyROOT. |
Beta Was this translation helpful? Give feedback.
-
In the branch lmfit we started to add function fitting. Thanks to @JulianHeymes for adding the function calls with error estimates.
I have a few comments/questions that I wanted to discuss:
Generic API:
We should try to keep the API general enough that we could switch out the fitting library if needed. This means exposing as little as possible to the user.
Does this look reasonable?
Function naming
Currently we have:
Do we keep it or rename it to pol1? Note that parameters are switched compared to ROOT, which might surprise users.
Namespace
I guess we will have few enough functions that we can make them accessible from the top level namespace? Maybe also add a func or similar to be able to list functions?
Beta Was this translation helpful? Give feedback.
All reactions