-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Supplying multidimensional initial guess to curvefit
#7768
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
This should be doable. I think we would have to rework the |
I implemented this for I can also do this for the bounds, just didn't have time to do it yet. How do you think the multidimensional bounds should be passed? As a tuple of arrays, or as an array of tuples, or something else? To me, it would make most sense to pass them as tuples of "things that can be broadcast", so that e.g. the lower bound of can be a scalar 0, but the upper bound could vary. |
Hello, Was this also implemented for bounds at the end? Thanks |
Hi, yes, it was implemented for bounds as well. |
Is your feature request related to a problem?
Hi, I'm trying to use
DataArray.curvefit
to fit a bunch of data. Let's say the data dimensions are(x, experiment_index)
, and I'm trying to fitm * x + b
, wherem
will be different for eachexperiment_index
. I would like to supply an initial guessp0
tocurvefit
that depends onexperiment_index
, but it seems like this is not supported. Here's a minimal example:Describe the solution you'd like
I would like to be able to provide arrays as the values of
p0
, so that I can have different initial guesses for different slices of the data.I suppose this could also be implemented for bounds.
Describe alternatives you've considered
I could wrap
curvefit
in a for-loop, for exampleBut this is quite cumbersome, especially for multidimensional data.
Additional context
The above example gives the error
because
curve_fit
tries to donp.atleast_1d([m_guess, 1])
, but it should benp.atleast_1d([m_guess[0], 1])
.The above example gives the errorwhich comes from- this applies for scipy 1.7.scipy.curve_fit
tying to computem * x
, wherem
is the DataArraym_guess
, butx
is a plain Numpy array, basicallyx.data
.This toy example of course works with just a scalar guess like
p0={"m": 2}
, but in my case the function is more complicated and fit might fail if the initial guess is too far off.The initial guess is inserted into
kwargs
passed tocurve_fit
here:xarray/xarray/core/dataset.py
Line 8659 in c75ac8b
The text was updated successfully, but these errors were encountered: