fundamentals

Bayesian inference

Bayes’ theorem turns a prior belief about a hidden state into a posterior belief after observing data. The four ingredients are the prior p(x), the likelihood p(y|x), the posterior p(x|y), and the evidence p(y) that normalizes the product. In this codebase the posterior is computed exactly on a 1-D grid (GridBayesianInference) or in closed form for multivariate Gaussian setups (LinearGaussianSystem).

In this codebase

End-to-end snippet

from active_inference import (
    LinearGaussianModel, GridBayesianInference, make_grid,
)

model = LinearGaussianModel(
    beta0=3.0, beta1=2.0, sigma2_y=0.25,
    m_x=4.0, s2_x=0.25, prior_kind="gaussian",
)
result = GridBayesianInference(model, make_grid(0, 5, 500)).infer(y=7.0)
print(result.summary())
print("95% CI:", result.credible_interval(0.95))
print("KL[post||prior]:", result.kl_from_prior())

Pitfalls

See also