Skip to content

Inference

polars_ts.bayesian_var.inference

Inference methods for Bayesian VAR — analytical posterior and Gibbs sampler.

_analytical_posterior(X, Y, B0, V0_inv_diag, S0, nu0)

Compute analytical Normal-Wishart posterior.

Returns

B_post Posterior mean for coefficients, shape (k, k*p+1). V_post_inv Posterior precision, shape (k*p+1, k*p+1). S_post Posterior scale matrix, shape (k, k). nu_post Posterior degrees of freedom.

_gibbs_sample(X, Y, B0, V0_inv_diag, S0, nu0, n_samples, burn_in, seed)

Draw posterior samples via Gibbs sampling.

Uses the matrix-normal / inverse-Wishart conjugacy:

  • B' | Sigma ~ MN(B_post', V_post, Sigma) where V_post = (V0 + X'X)^{-1} and B_post' = V_post (V0 B0' + X'Y)
  • Sample via B' = B_post' + chol(V_post) Z chol(Sigma)' where Z is a (dim, k) standard normal matrix.
Returns

B_samples Shape (n_samples, k, k*p+1). Sigma_samples Shape (n_samples, k, k).