The multivariate normal (MVN) is the workhorse for vector-valued
hidden-state inference, sensor fusion, and parameter posteriors. Every
MVN routine in this codebase solves a linear system against the
covariance matrix — Cholesky decomposition for mvn_log_pdf and
mvn_sample, np.linalg.solve for mahalanobis_squared — rather
than forming an explicit covariance inverse, so the math stays
numerically stable even when the covariance is ill-conditioned.
core.distributions.mvn_pdf (linear),
mvn_log_pdf (log space, batched).core.distributions.mvn_sample(mu, cov, n=...) — uses
the same Cholesky factor as the density routines.core.distributions.mahalanobis_squared(x, mu, cov)
computes (x − μ)ᵀ Σ⁻¹ (x − μ) via np.linalg.solve against the
covariance matrix directly (not a Cholesky factor), returning a
scalar for a vector input or a length-N array for a batch.isotropic_cov(d, var) (spherical) and
diagonal_cov(variances) (axis-aligned).visualizations.plotting.confidence_ellipse(mean, cov, n_std=2.0).LinearGaussianMVProcess,
LinearGaussianMVModel, LinearGaussianSystem, LGSPosterior.import numpy as np
from active_inference import (
isotropic_cov, mvn_pdf, mvn_sample, mahalanobis_squared,
)
rng = np.random.default_rng(0)
mu = np.array([1.0, -1.0])
cov = np.array([[1.0, 0.4], [0.4, 0.5]])
samples = mvn_sample(mu, cov, n=20_000, rng=rng)
print("empirical mean :", samples.mean(axis=0))
print("empirical cov :", np.cov(samples, rowvar=False))
print("density at mu :", mvn_pdf(mu, mu, cov))
print("Mahalanobis(0):", mahalanobis_squared(np.zeros(2), mu, cov))
ValueError if it isn’t.(D,) or a batch
(N, D). The output shape mirrors the input.c corresponds to a
χ²_d-quantile credible region — for d = 2 and 95 % coverage
use chi2_95 = -2 * np.log(0.05) ≈ 5.991.diagonal_cov over np.diag(...) —
the helper validates positivity and is clearer at the call site.generative_models.md — where MVN slots in.bayesian_inference.md — closed-form MVN
posteriors.../chapters/chapter_03.md — Example 3.4
(MVN anatomy) and Example 3.6 (the LGS posterior over a 2-D hidden
state).../statistics/divergences.md — KL
between MVNs.../reference/core.md — full API.