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: add numpy-based 'predict' function #150

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

auto regression: add numpy-based 'predict' function #150

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

Comments

@mathause
Copy link
Member

mathause commented Jun 10, 2022

Extract the code to 'predict' auto regression and write a numpy-based function. This is used in two places:

The two approaches are slightly different - one is based on a multivariate gaussian and the other on a univariate. However, it should be possible to unify them. My idea would be to do both using multivariate_normal and then squeeze the 1D case.

import numpy as np

np.random.seed(1)
a = np.random.normal(loc=0, scale=1, size=3)

np.random.seed(1)
b = np.random.multivariate_normal([0], [[1]], size=3)

np.testing.assert_allclose(a, b.squeeze())
@mathause
Copy link
Member Author

As far as I can see it is not possible to get rid of the for loop, but this computation could potentially be optimized using numba.jit.

@mathause
Copy link
Member Author

Argh - the relation between normal and multivariate_normal is not exactly 1:1. normal needs the standard deviation while mulitvariate_normal wants the (co-) variance.

import numpy as np

c = 0.5

np.random.seed(1)
a = np.random.normal(loc=0, scale=c, size=3)

np.random.seed(1)
b = np.random.multivariate_normal([0], [[c]], size=3)

np.random.seed(1)
b = np.random.multivariate_normal([0], [[c ** 2]], size=3)


np.testing.assert_allclose(a, c.squeeze())

np.testing.assert_allclose(a, b.squeeze()) # failst

@mathause mathause added this to the v0.9.0 milestone Dec 13, 2022
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