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: return co-variance instead of standard deviation #306

Closed
mathause opened this issue Sep 25, 2023 · 2 comments · Fixed by #309
Closed

auto_regression: return co-variance instead of standard deviation #306

mathause opened this issue Sep 25, 2023 · 2 comments · Fixed by #309
Labels
good first issue Good for newcomers
Milestone

Comments

@mathause
Copy link
Member

Our functions _fit_auto_regression_xr returns the "standard deviation of the residuals". But _draw_auto_regression_correlated_np requires the (co-)variance.

This was done because the two functions were extracted in separate PRs (#161 and #161) and the original code did the same. It's a bit wasteful if we constantly convert there and back. We should change this before we release v0.9.

std = np.sqrt(AR_result.sigma2)

def _draw_auto_regression_correlated_np(
*, intercept, coefs, covariance, n_samples, n_ts, seed, buffer

params_gv["AR_std_innovs"] = np.float64(params_scen.standard_deviation.values)

params_lv["AR1_std_innovs"][targ_name] = params_scen.standard_deviation.values

@mathause mathause added the good first issue Good for newcomers label Sep 25, 2023
@mathause mathause added this to the v0.9.0 milestone Sep 25, 2023
@mathause
Copy link
Member Author

mathause commented Sep 25, 2023

What I want to say fit_auto_regression should return var but the old code path will keep using std - i.e. the place of the sqrt and **2 should change. Should not be too difficult but may (should) need some code test changes.

@mathause
Copy link
Member Author

This is a bit less trivial than I thought - in train_gv_AR we take the average over the AR params - including the standard deviation. However, this is wrong: you have to average the covariances (or even take care of the size of the samples: https://stats.stackexchange.com/q/25848)

params_scen = list()
for scen in gv.keys():
data = gv[scen]
# create temporary DataArray
data = xr.DataArray(data, dims=("run", "time"))
params = _fit_auto_regression_xr(data, dim="time", lags=AR_order_sel)
params = params.mean("run")
params_scen.append(params)
params_scen = xr.concat(params_scen, dim="scen")
params_scen = params_scen.mean("scen")

These are used here:

covariance=AR_std_innovs**2, # pass the (co-)variance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant