fundamentals

Multivariate Gaussians

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.

In this codebase

End-to-end snippet

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))

Pitfalls

See also