Chapter 8 extends generalized filtering by treating model parameters and precision parameters as hidden variables. The companion implements a compact linear version of this idea: hidden-state perception, first-order parameter learning, second-order log-precision learning, and two-layer hierarchical message passing are all driven by one variational free-energy objective.
| Step | Chapter 8 parameterization |
|---|---|
| 1. Generative process | Observations are generated by y = x* - theta* + noise; hierarchy examples use a lower sensory layer and an upper context layer. |
| 2. Generative model | LearningAttentionModel predicts observations from mu_x - mu_theta and regularizes mu_x toward a state attractor. |
| 3. Inference objective | learning_attention_free_energy sums precision-weighted errors for sensory data, hidden state, first-order parameter theta, and log precision zeta. |
| 4. Update rule | simulate_learning_attention uses fast state descent and damped slow flows for mu_theta and mu_zeta. |
| 5. Diagnostics | Figures show state tracking, parameter convergence, learned positive variance, prediction errors, and hierarchical message terms. |
| Script | Question it answers | Library symbols |
|---|---|---|
example_8_1_learning_attention.py |
Can one sensory stream identify hidden state, a model parameter, and a precision parameter? | LearningAttentionModel, LearningAttentionState, simulate_learning_attention, plot_learning_attention |
example_8_2_hierarchical_continuous.py |
How does an upper context provide a top-down prior for a lower continuous state? | HierarchicalContinuousModel, ContinuousHierarchyLayer, hierarchical_continuous_free_energy, hierarchical_continuous_grad |
visualize_message_passing.py |
What are the forward and backward messages in the hierarchy? | plot_hierarchical_message_passing, hierarchical_message_terms |
animation_learning_attention.py |
How do perception, learning, attention, and VFE evolve over time? | animate_learning_attention, save_animation |
Chapter 9 switches from continuous generalized filtering to discrete POMDP active inference, where policies are selected by expected free energy.