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

Add Bayesian VAR(2) example script #1658 #1915

Merged
merged 11 commits into from
Dec 4, 2024

Conversation

aibit0111
Copy link
Contributor

VAR(2) examples:
Reference - https://otexts.com/fpp2/VAR.html
fix #1658

@tillahoffmann
Copy link
Contributor

This looks interesting! As of #1904, there is a Gaussian state space model distribution. Would that be suitable for the VAR here?

@fehiepsi
Copy link
Member

fehiepsi commented Nov 23, 2024

In addition, could you add the example to docs index together with thumbnails (like in #1429)?

@aibit0111
Copy link
Contributor Author

Hi @fehiepsi, added the index and thumbnails.

@aibit0111
Copy link
Contributor Author

This looks interesting! As of #1904, there is a Gaussian state space model distribution. Would that be suitable for the VAR here?

Hi @tillahoffmann, awesome work on SSM, do you want me to create example using SSM?

@aibit0111
Copy link
Contributor Author

@fehiepsi , Lint has failed, when I am fixing with ruff, it is changing some more files other that var2.py
I have been working on some econometric models with numpyro, will be adding more models.

@tillahoffmann
Copy link
Contributor

Hi @tillahoffmann, awesome work on SSM, do you want me to create example using SSM?

I think using the current implementation in this PR or SSM could both work. The latter might be a bit more concise because you wouldn't have to implement the transition function.

@fehiepsi
Copy link
Member

@aibit0111 Could you merge with master? lint issues are fixed upstream.

@aibit0111
Copy link
Contributor Author

@fehiepsi Done

@fehiepsi
Copy link
Member

fehiepsi commented Nov 29, 2024

Could you add some docstring like other examples to give the readers a take on the content?
There is a lint issue in the new example.

@aibit0111 aibit0111 force-pushed the bayesian-var-tutorial branch from ed19c33 to c0cf4c4 Compare December 4, 2024 15:06
@aibit0111
Copy link
Contributor Author

aibit0111 commented Dec 4, 2024

Hi @fehiepsi, i was on holiday, updated the code with proper doc and passed all the test.

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @aibit0111! The implementation looks great to me. Just have minor comments.

Could you also mention [Forecasting](https://num.pyro.ai/en/stable/tutorials/time_series_forecasting.html#Forecasting) in the description so that users have a pointer?

examples/var2.py Outdated
L_omega = numpyro.sample(
"L_omega", dist.LKJCholesky(dimension=K, concentration=1.0)
)
L_Sigma = jnp.matmul(jnp.diag(sigma), L_omega)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe jnp.einsum("...i,...ij->...ij", sigma, L_omega) or sigma[..., None] * L_omega to improve the performance

examples/var2.py Outdated
# Priors for constants and coefficients
c = numpyro.sample("c", dist.Normal(0, 1).expand([K])) # Constants vector of size K
Phi1 = numpyro.sample(
"Phi1", dist.Normal(0, 1).expand([K, K])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add .to_event(2) at the end to make sure that no batch dimension appears here?

examples/var2.py Outdated
"Phi1", dist.Normal(0, 1).expand([K, K])
) # Coefficients for lag 1
Phi2 = numpyro.sample(
"Phi2", dist.Normal(0, 1).expand([K, K])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

examples/var2.py Outdated

# Priors for error terms
with numpyro.plate("K", K):
sigma = numpyro.sample("sigma", dist.HalfNormal(1.0)) # Standard deviations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like above, prefer .expand([K]).to_event(1) than using plate

@fehiepsi fehiepsi mentioned this pull request Dec 4, 2024
@aibit0111
Copy link
Contributor Author

Thanks @fehiepsi for generous review, I am new to num pyro, learning a lot. Please review once again

@fehiepsi fehiepsi merged commit 244ff38 into pyro-ppl:master Dec 4, 2024
9 checks passed
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 this pull request may close these issues.

A application tutorial about Baysian Vector Autoregression?
3 participants