Chapter 2BeginnerNew edition
Apple or frog? Perception as inference
Something green sits among the apples. You expect an apple; then it jumps. What you see next is not read off the eye: it is worked out, from what you expected and from how well each explanation predicts the jump. Press It jumps again and watch the belief move.
Free energy of any belief
Hold a belief Q of your own. The curve is its variational free energy. It touches the surprise line at one point only: the exact posterior.
Look again, or look away
Each new observation uses the last posterior as its prior. The other route is action: look at a different tree, where what is seen is likely to fit what is expected.
| Choice | Expects a jump | Expected surprise | Chosen with |
|---|---|---|---|
| Keep looking here | |||
| Look at another tree |
Expected surprise is how badly the outcomes each choice predicts fit the outcomes the observer prefers, in nats. Lower is better.
AII: EduActive · Watch, then do
Three short clips, three things to try
These three passages come from the Institute’s study groups, where members read the textbooks aloud and talk them through. Each is one to two minutes. Watch one, then press its button and look for the same thing in the orchard above.
- The ideaA few plain sentences. Enough on its own.
- Listen for, then tryOne line from the clip, and one thing to do on the stage.
- In the modelWhich matrix, term or rate carries the idea, and how this page differs from what is said.
-
Plays here, from 43:00. Nothing loads from YouTube until you press play.Open on YouTube at 43:00
1Before you start
Bayes’ rule in plain words
Bayes’ rule is the exact way to change a belief when new evidence arrives. It has four parts: what you believed before, how well each explanation predicts what you saw, how likely that sight was overall, and what you believe afterwards. You do not need the algebra to follow the idea.
Listen forThen tryThe observer is 90% sure of an apple. Say how sure of a frog it should be after one jump. Then press the button, and press “It jumps” under the picture.In the model equation 1
The four parts are the four terms of equation 1: the prior P(x), the likelihood P(y | x), the evidence P(y) and the posterior P(x | y). In the square on the stage the evidence is the lit area, and the posterior is each lit rectangle as a share of it.
The speaker is reading a different textbook, and its equation 1.2 is the same rule as this page’s equation 1. The speaker adds that the rule is too hard to apply in most models of interest, because of the evidence term. That is not the case here. With two states the evidence is a sum of two products, and the page computes it exactly.
-
Plays here, from 2:43. Nothing loads from YouTube until you press play.Open on YouTube at 2:43
2While it runs
The frog, the apple and the jump
The textbook returns to one small example again and again. A thing is either a frog or an apple, and it either jumps or does not. Each time you look, you adjust your belief about which it is. That adjusting is the core of this whole family of models.
Listen forThen tryA frog really is on the bough. It jumps on most looks, but not on all. Predict what one still moment does to a belief built on several jumps. Then press the button, and press “Watch again” a few times.In the model equation 4
Looking again is equation 4: the posterior after one observation is the prior for the next. The numbers on the sliders are the textbook’s, a prior of 0.9 on apple and likelihoods of jumping of 0.81 and 0.01.
The speaker has the object held in the hand; this page puts it on a bough, which changes nothing in the model. The passage also mentions surprise and says that large problems need approximations. Here nothing is approximated, and the two kinds of surprise are kept apart in equation 2.
-
Plays here, from 7:32. Nothing loads from YouTube until you press play.Open on YouTube at 7:32
3Afterwards
An upper bound on surprise
Surprise measures how badly your model predicted what you saw. In most models it is too hard to work out exactly. Free energy is a number that can be worked out, and it is never lower than surprise. So pushing free energy down brings it towards surprise from above.
Listen forThen tryThe belief is now yours to hold. Predict where the curve is lowest. Then press the button, drag “Your belief Q(frog)” and try to bring free energy below the dashed surprise line.In the model equation 3
The last line of equation 3 writes free energy as a divergence plus surprise. A divergence is never negative, so F sits on or above −ln P(y), and the two meet only when Q is the exact posterior. The curve under the stage is F as a function of Q(frog), and the dashed line is the surprise.
The speaker’s reason for using the bound is that surprise cannot be computed in large models, and mentions Jensen’s inequality and other approximations. None of that is needed on this page. With two states the surprise is computed exactly, which is why both it and the bound can be drawn.
Equation 3, variational free energy
Further viewing: why an upper bound is used, and textbook equation 2.5, 20:04 · a toy example in which F is lowered step by step until it equals surprise, 42:28 · surprise and Bayesian surprise as two distinct ideas, 3:43
The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. The speakers are working through the textbooks, not this page; where the two differ, the notes say so. Each clip stops at the end of the passage. The full recordings are listed under Sources.
Learn by doing
Try this
- Predict the posterior before you see it.
The observer is 90% sure of an apple. Frogs jump 81% of the time, apples 1%. If the thing jumps, how sure of a frog should the observer be? Set your guess, then press It jumps. In the square, the answer is the share of the lit area that lies in the frog column.
- Make the prior stubborn.
Now the observer is 99% sure of an apple. Guess how many jumps it takes before a frog is the better explanation, then press It jumps and count. Afterwards drag the prior to exactly 0: the frog column has no width, so no amount of jumping can ever fill it.
- Try to get free energy below surprise.
The belief Q is now yours to hold. Drag Your belief Q(frog) anywhere you like and watch the dot ride the curve. Predict where it is lowest. The gap above the dashed line is the divergence between your belief and the exact posterior, and it is never negative.
- Make the observation useless, then impossible.
Both likelihoods are set to 0.30, so a jump says nothing about what jumped. Predict the posterior. It equals the prior, and the Bayesian surprise is 0, although the surprise is not. Then drag both likelihoods to 0: the model now says a jump cannot happen, and the page reports that instead of a number.
- Keep watching a real frog.
A frog is really there, and the textbook’s numbers are back. Press Watch again many times. Each outcome is drawn with the frog’s own probabilities, so it sometimes sits still. Predict what one still moment does to a belief built on several jumps, and watch the accumulated log evidence fall with every look.
- Take the other route: act.
The thing has jumped and the observer could change its mind. Instead, press Look at another tree. Compare the surprise of what is seen there with the surprise of the jump. Then weaken the preference to 0.50 and see the two choices become equally good.
The mathematics
What is being computed
The notation is that of chapter 2 of the textbook: x is the hidden state (frog or apple) and y is the observation (jumps or does not jump). Later chapters write s and o for the same things. Every value below is recomputed from the sliders and the latest observation.
The prior P(x) is the belief before looking. The likelihood P(y | x) says how probable each observation is under each explanation. Their product is a joint probability: one rectangle of the square. The evidence P(y) is the lit area, and the posterior P(x | y) is each lit rectangle as a share of it.
Surprise ℑ scores how poorly the model predicted the observation. Bayesian surprise is a Kullback–Leibler divergence: it scores how far the belief had to move. They are different things. An observer certain of apples has zero Bayesian surprise when the thing jumps, because it does not update at all, yet its surprise is large.
Q(x) is any belief at all about the hidden state; EQ is an average taken under it. A divergence is never negative, so the last line gives F ≥ −ln P(y): free energy is an upper bound on surprise, and the bound is exact when Q is the exact posterior. Perception lowers F by moving Q. With Let perception run pressed, the log-odds of Q move at a rate proportional to −∂F/∂Q(frog), which carries Q to the posterior.
The thing on the bough does not change between looks, so the posterior after one observation is the prior for the next. The log evidence of the whole run is the sum of the log evidence of each look, which is minus the sum of the surprises. After Look at another tree the thing is a new one, so the prior starts again from the slider.
Here u is an action: keep looking here, or look at another tree. Q(x | u) is what the observer expects to be there: its current belief if it stays, its original prior if it looks at something new. C(y) is the distribution of outcomes it prefers, and σ is the softmax, which turns scores into probabilities. S is the expected surprise of the outcomes under those preferences. This is only half of the quantity used in active inference. The full score, expected free energy G, also subtracts the information a look is expected to yield; it is shown in the live line for comparison and taught in later simulations.
Reading
Where this comes from
By acting on the world to change the way in which data are generated, we can ensure a model is fit for purpose by choosing those data that are least surprising under our model.Parr, Pezzulo & Friston (2022), Active Inference, chapter 2, p. 24
What is established
The example, its numbers and its equations are those of chapter 2 of Parr, Pezzulo and Friston (2022): a prior of 0.9 on apple, likelihoods of jumping of 0.81 for a frog and 0.01 for an apple, a posterior of 0.9 on frog after a jump, a surprise of about 2.4 nats and a Bayesian surprise of about 1.8 nats. Bayes’ rule and the identity F = divergence + surprise are mathematics, true of any probabilistic model.
That free energy bounds surprise, and that it can be lowered either by changing beliefs (perception) or by changing what is sampled (action), is the central construction of the free energy principle (Friston 2010) and of active inference (Friston et al. 2017). The term Bayesian surprise for the divergence between posterior and prior follows Itti and Baldi (2009).
The free energy principle is a principle and a modelling framework. This page illustrates it; it is not evidence that brains work this way.
What this model leaves out
With two states the exact posterior is easy to compute, so nothing here needs to be approximated. Free energy earns its place in models where the evidence P(y) cannot be computed and Q must come from a restricted family. That is the subject of chapter 4.
The choice between looking here and looking away uses expected surprise only, one step ahead, with a preference you set by hand. Active inference scores policies by expected free energy, which adds the value of information, plans over several steps, and includes habits and a precision on policy beliefs (chapters 4 and 7; Da Costa et al. 2020; Smith, Friston & Whyte 2022).
The world here is the simplest possible. The thing never changes between looks, and the other tree holds a frog with the same probability as the prior slider says. The observer’s model and the process that generates its observations share the same likelihoods, which the textbook is careful to say need not be true. Nothing is learned: the likelihoods stay where you put them. The picture of the frog and apple is a drawing of the belief Q, not a model of vision.
- Active Inference Institute (2026). Fundamentals of Active Inference, Chapter 1 and Appendix A: Hypothesis-Testing Brain, Session 6. Recording. youtube.com/watch?v=7XrONg4dBrI
- Active Inference Institute. Active Inference (Parr, Pezzulo, Friston), Chapter 2, BookStream #002.01. Recording. youtube.com/watch?v=U0rdFwflr4M
- Active Inference Institute (2025). ActInf Textbook Group, Cohort 8, Session 4 (Chapter 2). Recording. youtube.com/watch?v=1sYOrZqbGZ8
- Parr, T., Pezzulo, G., & Friston, K. J. (2022). Active Inference: The Free Energy Principle in Mind, Brain, and Behavior. MIT Press. Chapter 2, “The Low Road to Active Inference”. doi:10.7551/mitpress/12441.001.0001
- Friston, K. (2010). The free-energy principle: a unified brain theory? Nature Reviews Neuroscience, 11, 127–138. doi:10.1038/nrn2787
- Friston, K., FitzGerald, T., Rigoli, F., Schwartenbeck, P., & Pezzulo, G. (2017). Active inference: a process theory. Neural Computation, 29(1), 1–49. doi:10.1162/NECO_a_00912
- Da Costa, L., Parr, T., Sajid, N., Veselic, S., Neacsu, V., & Friston, K. (2020). Active inference on discrete state-spaces: a synthesis. Journal of Mathematical Psychology, 99, 102447. doi:10.1016/j.jmp.2020.102447
- Smith, R., Friston, K. J., & Whyte, C. J. (2022). A step-by-step tutorial on active inference and its application to empirical data. Journal of Mathematical Psychology, 107, 102632. doi:10.1016/j.jmp.2021.102632
- Itti, L., & Baldi, P. (2009). Bayesian surprise attracts human attention. Vision Research, 49(10), 1295–1306. doi:10.1016/j.visres.2008.09.007