fundamentals

Chapter 3 — concept map

Chapter 3 stitches learning and inference together. The previous chapter treated the agent’s parameters as already known; here we look at how they get estimated in the first place, and what happens when both the parameters and the hidden state are unknown at the same time.

The five recipes

Each is exposed as a configurable building block in active_inference and demonstrated by a thin orchestrator in chapters/chapter_03/.

Recipe Key API Orchestrator
Closed-form linear regression (MLE) mle_linear_regression(X, y) example_3_1_linear_regression_mle.py
Gradient descent over the squared loss gd_linear_regression(X, y, learning_rate=...) example_3_2_linear_regression_gd.py
Multiple regression (vectorized) mle_linear_regression(X, y) (batched) example_3_3_multiple_regression.py
Multivariate normal anatomy mvn_pdf, mvn_sample, confidence_ellipse example_3_4_multivariate_gaussian.py
Bayesian linear regression BayesianLinearRegression(...).fit(X, y) example_3_5_bayesian_linear_regression.py
Linear Gaussian System (sensor fusion) LinearGaussianSystem(...).posterior_batch(Y) example_3_6_lgs_food_localization.py
Factor analysis via EM fit_factor_analysis(Y, n_factors=...) example_3_7_factor_analysis_em.py

Script inventory

File Role
animation_bimodal_emergence.py Non-injective generator animation.
animation_blr_predictive_band.py Bayesian linear-regression predictive-band animation.
animation_blr_tightening.py Parameter posterior tightening animation.
animation_em_convergence.py EM log-likelihood and loadings animation.
animation_em_steps.py E-step / M-step factor-analysis animation.
animation_lgs_online.py Online Linear Gaussian System posterior animation.
animation_precision_sweep.py Prior/likelihood precision sweep animation.
animation_sufficient_statistics.py Running sufficient-statistics animation.
visualize_calibration.py Calibration reliability diagram.
visualize_coverage.py Empirical coverage of a fixed 95% LGS credible region across a sample-size (N) sweep.
visualize_posterior_predictive.py Posterior-predictive diagnostic figure.
interactive_bayesian_regression.py GUI / web-launchable BLR explorer: N and prior-precision sliders tighten the ±2σ predictive band; readout reports recovered β0/β1 ± posterior std.
interactive_lgs_localization.py GUI / web-launchable 2-D LGS explorer: (y1, y2) observation sliders slide the posterior mean ellipse toward the fixed prior; readout reports posterior mean/std and distance from prior/observation.

Reusable building blocks

See also

Where the book takes this next

Chapter 4 generalizes the closed-form posteriors here to settings where the posterior is no longer Gaussian and replaces the EM machinery with variational Bayesian inference. The classes here are designed so that those upgrades plug in naturally — LinearGaussianMVModel already exposes log_likelihood and log_prior, which is the interface a variational scheme needs.