fundamentals

Generative models

A generative model is a joint distribution p(x, y) = p(y | x) p(x) that the agent uses to invert observations and recover the hidden state that produced them. The package keeps a strict split between the generative process (the environment, sample-only) and the generative model (the agent’s beliefs, density-aware).

In this codebase

The model side never samples observations; the process side never evaluates densities. This keeps the abstraction sharp and prevents chapter scripts from accidentally computing posteriors against samples they actually meant to be ground truth.

End-to-end snippet

import numpy as np
from active_inference import (
    LinearGaussianProcess, LinearGaussianModel,
    GridBayesianInference, make_grid,
)

# 1. Environment (sample-only)
process = LinearGaussianProcess(beta0=3.0, beta1=2.0, sigma2_y=0.25,
                                rng=np.random.default_rng(0))
y = process.sample(x_star=2.0, n=30).flatten()

# 2. Agent (density-aware)
model = LinearGaussianModel(
    beta0=3.0, beta1=2.0, sigma2_y=0.25,
    m_x=4.0, s2_x=0.25, prior_kind="gaussian",
)

# 3. Inference
result = GridBayesianInference(model, make_grid(0, 5, 500)).infer(y)
print(result.summary())

Pitfalls

See also