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

auto-regression: xarray wrapper for predict #151

Closed
Tracked by #149
mathause opened this issue Jun 10, 2022 · 2 comments · Fixed by #322
Closed
Tracked by #149

auto-regression: xarray wrapper for predict #151

mathause opened this issue Jun 10, 2022 · 2 comments · Fixed by #322
Milestone

Comments

@mathause
Copy link
Member

After #150 we should write a xarray wrapper for the numpy based auto regression prediction. It is not yet entirely clear to me how this should look, though.

@mathause
Copy link
Member Author

mathause commented Jun 21, 2022

_fit_auto_regression_xr and _draw_auto_regression_correlated_np don't work together super smoothly yet. This is how we can make it work:

import mesmer
import numpy as np
import xarray as xr

air = xr.tutorial.open_dataset("air_temperature")

# a 2D array is required - would be a flattened (unstructured) grid
# for simplicity use one row of longitudes 
data = air.air.isel(lat=0)

params = mesmer.stats.auto_regression._fit_auto_regression_xr(data, dim="time", lags=2)

mesmer.stats.auto_regression._draw_auto_regression_correlated_np(
    intercept=params.intercept.values,
    coeffs=params.coeffs.T.values, # unfortunate...
    covariance=np.diag(params.covariance), # diag to ensure cov is invertible 
    n_samples=3,
    n_ts=50,
    seed=0,
    buffer=20,
)

@mathause mathause added this to the v0.9.0 milestone Dec 13, 2022
@mathause
Copy link
Member Author

_fit_auto_regression_xr and _draw_auto_regression_correlated_np don't work together super smoothly yet.

This already works better after #306. Maybe we should also transform the coeffs?

What bugs me, though - how to we populate the resulting DataArray how can we pass dimension names and coordinates? This is further complicated by the fact that I expect coords for the time dim but not for the sample dim. Also is sample a good name?

Further (and related) ArmaProcess.generate_sample allows to generate nD arrays.

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.

1 participant