DEV Community

ORCHESTRATE
ORCHESTRATE

Posted on

Active Inference, The Learn Arc — Part 10: Chapter 9 — Model-Based Data Analysis, Free Energy as Log Evidence

Chapter 9 — Model-Based Data Analysis

Series: The Learn Arc — 50 posts teaching Active Inference through a live BEAM-native workbench. ← Part 9: Continuous Time. This is Part 10.

The hero line

Fit an Active Inference model to real data — and know when to trust it.

Chapter 9 does a quiet but enormous flip. Up through Chapter 8, Active Inference was a theory of how agents work. In Chapter 9 it becomes a statistical tool for studying agents you didn't build.

You have behavioral data from a human in a decision task. You have a candidate Active Inference model. How do you fit it? How do you know if a different model fits better? How confident can you be? Chapter 9 answers all three in a way that makes Active Inference a first-class citizen in the computational-psychiatry and cognitive-science toolkit.

Beat 1: free energy IS log evidence (minus a constant)

Return to Chapter 2 for one line. The variational free energy F upper-bounds the negative log evidence:

F[Q] ≥ − log P(observations | model)
Enter fullscreen mode Exit fullscreen mode

And the gap closes when Q hits the true posterior. So minimizing F with respect to Q, then scoring the minimum, gives you a tight lower bound on log model evidence — which is exactly the quantity Bayesian model comparison needs.

This is the chapter's first power tool. The same functional you've been using to do perception is also the functional you use to score models against data. One quantity, three jobs: perception, planning, and now model evaluation.

Beat 2: the fitting loop

The fitting loop for a given candidate model:

  1. Write the model as A, B, C, D (Chapter 6's template).
  2. Run it against the subject's observation sequence, letting it perceive + plan + act.
  3. Compare the model's action posterior at each step to what the subject actually did.
  4. Minimize free energy over the model's parameters (not just over Q) until the action-match likelihood is maximized.
  5. Record the minimum F — that's −log P(data | model) + const.

Repeat for each candidate model. Subtract Fs: the difference is the log Bayes factor comparing the models.

Because you're minimizing the same functional at every step, this fits directly into the Workbench's existing runtime. The Perceive → Plan → Act loop becomes the forward step of a variational fit; you add a parameter-gradient step that descends F in the A/B/C/D themselves. The Dirichlet learners from Chapter 7 are a special case.

Beat 3: Bayesian model comparison

Two models fit your data. Which do you pick?

Chapter 9's move: don't. Use Bayesian model comparison. Compute the log evidence for each (via its minimized F), form the log Bayes factor, and report a posterior distribution over models. If the data prefers model A with log BF = 4, you report that; you don't pretend model B is eliminated.

This is the chapter that connects Active Inference to computational psychiatry — fit different Active Inference models to ADHD patients vs controls, see which parameters (precision on observation vs transition, for example) differ systematically, report that as evidence that specific mechanisms differ between groups.

The Workbench surfaces

Chapter 9 doesn't have runnable recipes yet (fitting is the next planned workstream), but three surfaces already lay the groundwork:

Models — model-family taxonomy

/models — the model-family taxonomy. The fitting loop compares models within a family (and across families with enough care). Knowing what "family" a model belongs to — Bayesian, VFE, EFE, HMM, POMDP, Dirichlet-learning, continuous-time, hybrid — is the first step.

Glass — signal river with per-equation provenance

/glass — the per-agent signal river. When you fit an Active Inference model to subject data, you need to audit which step contributed which amount of log evidence. The Glass provenance tags (equation_id, world_run_id, bundle_id, trace_id, span_id) let you slice the total F into per-equation contributions. That's the debugging story every model-fit paper should include and almost none do.

/equations — the equation registry, filterable by verification_status. When you fit a model that uses Eq. 7.10's Dirichlet update, you want to know that equation is verified_against_source_and_appendix. Honest provenance matters most when you're publishing a result that depends on it.

The three sessions

Chapter 9 has three sessions under /learn/chapter/9:

  1. Fit to data — the fitting loop, start to end.
  2. Comparing models — Bayesian model comparison, log Bayes factors, reporting honest uncertainty.
  3. A worked case study — the book's example from the computational-psychiatry literature, applied step by step.

Why the provenance pipeline matters

The Workbench was built with this chapter in mind. The reason every signal carries an equation_id, the reason every event lands in a Mnesia-backed append-only log, the reason Glass renders the signal river with per-agent filters — all of that exists because you cannot trust a model fit you can't audit.

When the next person asks you "why did your Active Inference model say this subject has atypical observation precision?", you want an answer that cites:

  • The subject's observation sequence (tick-by-tick, in the log).
  • The agent's action posterior at each tick (rendered in Glass).
  • The log-likelihood term that contributed to the final F (traceable by equation_id).
  • The alternative models you compared against and their log Bayes factors.

The Workbench is built to produce all four. Chapter 9 is the theoretical frame for why that matters.

The verification honesty here

This is the chapter where the Workbench's honest verification matters most. A verified_against_source_and_appendix equation means the author traced every derivation step and implementation line. A scaffolded equation means the registry is present but the full path hasn't been audited.

If you're fitting a model whose computation depends on a scaffolded equation, you say so. You don't pretend. Chapter 9 teaches the discipline; the Workbench enforces it at the metadata layer.

Run it yourself

  • /models — model-family taxonomy.
  • /glass — signal river across all running agents.
  • /equations — equation registry with verification status badges.
  • /learn/chapter/9 — three sessions.
  • The model-fitting workstream itself: coming in the next workbench tranche. Follow the repo for updates.

The mental move

Chapter 9 is the pivot where a theorist hands Active Inference off to a scientist. The theory made predictions. The scientist wants to check them. Chapter 9 is how.

If you're a software engineer: this is the chapter that most resembles your day job. Fit the model. Log everything. Audit before trusting. Compare candidates honestly. Report uncertainty.

Next

Part 11: Chapter 10 — Active Inference as a Unified Theory of Sentient Behavior. The book's closer. Where does the theory go? What's it for? What's next? The series' final chapter-overview post; after this we go back to the first session and start the 38-post deep-dive arc.


⭐ Repo: github.com/TMDLRG/TheORCHESTRATEActiveInferenceWorkbench · MIT license

📖 Active Inference, Parr, Pezzulo, Friston — MIT Press 2022, CC BY-NC-ND: mitpress.mit.edu/9780262045353/active-inference

Part 9: Continuous Time · Part 10: Model-Based Data Analysis (this post) · Part 11: Unified Theory → coming soon

Top comments (0)