Active Inference InstituteSimulations

Chapters 2 and 4BeginnerNew

The cube that flips

Keep looking at the cube. It is one drawing, but you will see it in two ways, and it will switch from one to the other while the drawing stays the same. Press a button each time it flips. Then meet a small model that flips for the reason active inference gives: a percept is a hypothesis, and the evidence it leaves unexplained adds up.

Your key presses are timed in this page only. Nothing is sent anywhere and nothing is stored; reload the page and they are gone.

AII: EduActive · Watch, then do

Two short clips, two things to try

These two passages come from the Institute’s study sessions on the first chapter of Fundamentals of Active Inference, where the idea of the brain as a tester of hypotheses is introduced. One is under two minutes, the other under four. Watch one, then press its button and look for the same idea in the cube above.

  1. Plays here, from 13:34. Nothing loads from YouTube until you press play.Open on YouTube at 13:34

    Before you start

    Perceptions are hypotheses

    An old view says the world prints itself on a blank mind. The view taken here is the reverse. The mind proposes an explanation of what is out there, and the senses are used to check it.

    Listen for
    The mind is actively coming up with explanations as to what might be out there on the basis of the sensory data.
    Then try
    Guess how many seconds the cube will stay one way before it turns. Then report your own flips for a minute and a half. The drawing never changes, so whatever changes at a flip is not on the screen.
    In the model free energy of a hypothesis

    The page takes the phrase literally. There are two hypotheses, “from above” and “from below”. Each has a free energy Fh, its improbability beforehand plus its failure to predict the image, and the percept is the one with the lower F.

    The speaker is setting out three views of what a model is, and names Helmholtz and Richard Gregory for this one. The Necker cube is not mentioned, and nothing is said about why a percept should switch. The page’s account of switching, an error that accumulates and wears down the prior, comes from the papers under Sources and not from this passage.

    The percept is the hypothesis with the lower free energy

  2. Plays here, from 11:53. Nothing loads from YouTube until you press play.Open on YouTube at 11:53

    While it runs

    Duck or rabbit

    One picture can have two possible causes. The picture alone cannot say which, so what you believed beforehand has to help decide. A belief brought from before also keeps your view steady when the evidence wobbles for a moment.

    Listen for
    Given this one piece of sensory information that we received, which is this one picture, why does it look like that? Is it because it’s a duck, or is it because it’s a rabbit?
    Then try
    The model’s prior is that the scene is what it was a moment ago. Predict what happens to the time between flips when that prior is made a little stronger: slightly longer, or much longer. Then set it up and read the dwell times.
    In the model stability prior w₀

    Step 2 of the walk-through is the speaker’s point in numbers. Both solids cast exactly the same image, so the likelihoods are equal, ℓ = 0, and the posterior is the prior. What is left to decide the percept is the stability prior w0 in z = (w0 − e) + ℓc. The button raises w0 from 3 to 4 nats.

    The speaker’s figure is the duck-rabbit, not the Necker cube, and the passage does not discuss a percept changing over time. Its prior is knowledge brought to the picture, as with the person who has never seen a rabbit. The page’s w0 is narrower: a prior that the scene has not changed since a moment ago. The example of a passing cloud, near the end, is the closer match. The accumulated error e that makes the model flip is not in the passage.

    The belief: prior log-odds plus evidence · Accumulating the unexplained evidence

The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. Neither speaker mentions the Necker cube; the notes say how each passage differs from this page. Each clip stops at the end of the passage. The full recordings are listed under Sources.

Learn by doing

Try this

  1. Time your own flips. Before you start, guess how long the cube will stay one way: two seconds, five, ten? Then report for a minute and a half and read your mean.
  2. Take the noise away. Predict what the model's dwell times will look like with no randomness at all. Then look at the chart: every dwell is the same length, and it is the length the formula for T(θ) gives.
  3. Trust the past more. Raise the stability prior from 3 to 4 nats. Predict: a third longer, or much more than that? The wait grows roughly as eθ, so one more nat makes the dwells about three times as long.
  4. Let the evidence leak away. With a strong leak and no noise, the error settles below the threshold and the model never flips again. Watch it stall. Then press the second button to give it noise, and it flips again, at irregular intervals: the switches are now caused by chance alone.
  5. Tilt the picture. Add one nat of depth cue for “from above”. The model spends most of its time there; then return the cue to zero and watch the two percepts share the time again.

The mathematics

What is being computed

There are two hidden states s: the cube is seen from above, or seen from below. There is one outcome o: the image. Write c for the percept in force and r for its rival. Logarithms are natural, so quantities are in nats.

The belief: prior log-odds plus evidence z=ln⁡Q(c)Q(r)=(w0−e)⏟stability prior+ℓc⏟evidence,ε=Q(r)=11+ez

This is Bayes' rule for two hypotheses, written as log-odds, which add. w₀ is the strength of the stability prior; e is the accumulated error, which is subtracted from it; ℓc is the log-likelihood ratio of the image in favour of the current percept (zero for the plain cube). ε, the posterior probability of the rival, is the part of the evidence the current percept does not account for: the prediction error of Weilnhammer et al. (2017). Code: FLIP.infer.

Accumulating the unexplained evidence de=(αε−λe)dt+σdW,e≥0;when z<0: c↔r,e←0

α is the rate at which the error is added up, λ the leak, σ the size of the noise and dW a random step with variance dt. The model takes steps of 0.01 s. The switch rule z < 0 is the same as Q(r) > ½, and the same as e > θ with θ = w₀ + ℓc. Code: sim.step.

The percept is the hypothesis with the lower free energy Fh=−ln⁡P(s=h)⏟complexity−ln⁡P(o|s=h)⏟accuracy,Fr−Fc=z,Q(h)=e−Fh∑ke−Fk

Variational free energy is F = EQ[ln Q(s) − ln P(o, s)]. For a belief that commits wholly to one hypothesis h it reduces to the line above. The belief that is free to spread over both hypotheses reaches the lowest value F can take, the surprise −ln P(o), and it is the posterior Q. Code: AIF.vfe, called from FLIP.infer.

How long a percept lasts when there is no noise T(θ)=∫0θdeασ(e−θ)−λe,and for λ=0: T(θ)=θ+eθ−1α

Here σ(x) = 1/(1 + e−x) is the logistic function (not the noise). The integral follows from the accumulation equation with the noise removed; the page evaluates it by Simpson's rule (FLIP.dwellQuadrature) and the tests compare it with the stepped model. If the denominator reaches zero before e reaches θ, the error stalls and T is infinite.

Where to look: expected free energy of a fixation point u G(u)=−EQ(o|u)DKL[Q(s|o,u)‖Q(s)]⏟epistemic value−EQ(o|u)ln⁡P(o)⏟pragmatic value,Q(u)=σ(ln⁡E−γG)

Here σ is the softmax. The model prefers no outcome over another, so the pragmatic value is the same for every place to look, and the choice is made by epistemic value against a habit E of keeping the gaze on the centre (0.8) with precision γ = 16; both are settings. Code: AIF.efe and AIF.policyPosterior, called from FLIP.lookPolicy.

“It is a constructive inside-out process—in which sensations are used to confirm or disconfirm hypotheses about how they were generated”Parr, Pezzulo & Friston (2022), Active Inference, chapter 2, p. 16, on perception. The sentence goes on to give its references.

Reading

Where this comes from

What is established

The reversing cube was described by L. A. Necker in 1832. That the two readings alternate, and that an observer cannot hold one indefinitely, is among the oldest findings in the study of perception.

Dwell times in bistable perception have a skewed, single-peaked distribution that a gamma distribution describes well, and successive dwells are close to independent (Levelt 1967; Fox & Herrmann 1967). Brascamp, Klink & Levelt (2015) review fifty years of such measurements and restate Levelt's four propositions about stimulus strength in a form that also holds for bistable figures other than rivalry.

The account given here, that the percept in force leaves the evidence for the other unexplained and that this prediction error destabilises it, is the proposal of Hohwy, Roepstorff & Friston (2008). Weilnhammer and colleagues (2017) made it a quantitative model, fitted it to the reports of twenty observers, and found that its prediction-error time course correlated with activity in the inferior frontal gyri and anterior insulae. Parr, Corcoran, Friston & Hohwy (2019) treat looking and attending as actions that gather evidence for or against perceptual hypotheses.

These are models and interpretations. This page illustrates the idea; it is not evidence that the brain works this way.

What this model leaves out

It is a reconstruction, not a copy. Weilnhammer et al. use a Gaussian stability prior over a continuous variable, a two-peaked likelihood, one update each time their rotating figure overlaps itself, and a probabilistic response rule; their mathematical appendix was not available when this page was written. Here there are two discrete hypotheses, continuous time, an added leak, and noise placed on the accumulated error. Those four choices are this page's.

The complete reset of e at each flip makes successive dwells independent by construction. The near-independence of real dwells is therefore built into this model, not explained by it. The small correlations and slow drifts found in long recordings are absent.

Other accounts of the same alternation exist, in which the two percepts inhibit each other and the dominant one tires; Weilnhammer et al. compared their model with three of them. This page does not.

The effect of fixation is put in by hand as an assumption, with a strength κ that is not measured. Attention, blinks, eye movements proper, the effect of trying to hold a percept, and mixed or unclear percepts are all left out. The fit in step 4 matches two numbers with two settings, holding w₀ and λ fixed. With those at their defaults and a mean dwell near four seconds the model's CV has a ceiling of about 0.85; a more irregular observer cannot be fitted, and close to the ceiling quite different pairs of α and σ fit equally well. Your own timings include your reaction time and are too few to pin down a distribution: with twenty flips a CV is uncertain by about a fifth of its value.