issues: 671609109
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
671609109 | MDU6SXNzdWU2NzE2MDkxMDk= | 4300 | General curve fitting method | 35968931 | closed | 0 | 9 | 2020-08-02T12:35:49Z | 2021-03-31T16:55:53Z | 2021-03-31T16:55:53Z | MEMBER | Xarray should have a general curve-fitting function as part of its main API. MotivationYesterday I wanted to fit a simple decaying exponential function to the data in a DataArray and realised there currently isn't an immediate way to do this in xarray. You have to either pull out the This is an incredibly common, domain-agnostic task, so although I don't think we should support various kinds of unusual optimisation procedures (which could always go in an extension package instead), I think a basic fitting method is within scope for the main library. There are SO questions asking how to achieve this. We already have Proposed syntaxI want something like this to work: ```python def exponential_decay(xdata, A=10, L=5): return A*np.exp(-xdata/L) returns a dataset containing the optimised values of each parameterfitted_params = da.fit(exponential_decay) fitted_line = exponential_decay(da.x, A=fitted_params['A'], L=fitted_params['L']) Compareda.plot(ax) fitted_line.plot(ax) ``` It would also be nice to be able to fit in multiple dimensions. That means both for example fitting a 2D function to 2D data: ```python def hat(xdata, ydata, h=2, r0=1): r = xdata2 + ydata2 return h*np.exp(-r/r0) fitted_params = da.fit(hat) fitted_hat = hat(da.x, da.y, h=fitted_params['h'], r0=fitted_params['r0']) ``` but also repeatedly fitting a 1D function to 2D data: ```python da now has a y dimension toofitted_params = da.fit(exponential_decay, fit_along=['x']) As fitted_params now has y-dependence, broadcasting means fitted_lines does toofitted_lines = exponential_decay(da.x, A=fitted_params.A, L=fitted_params.L)
So the method docstring would end up like ```python def fit(self, f, fit_along=None, skipna=None, full=False, cov=False): """ Fits the function f to the DataArray.
``` Questions1) Should it wrap
2) What form should we expect the curve-defining function to come in?
3) Is it okay to inspect parameters of the curve-defining function?
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/4300/reactions", "total_count": 4, "+1": 3, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 1 } |
completed | 13221727 | issue |