The ArcadeBeliefs and curiosityA game
Forage: look before you leap
A hedge maze at night. You have a map and a lantern, but you see the hunters only where you are looking. Everywhere else you have a belief about where they are, drawn as blue haze. The haze spreads when you look away and is wiped clean where you look.
While the agent plays, SCORE is your own best on this seed. Move with the arrow keys or W A S D, a swipe on the screen, the pad, or a gamepad. Space stops you where you are. P pauses.
The game
How it works
You
You are a beetle with a lantern. Collect every seed to clear the level. You know the hedges and where the seeds are. You see a hunter only if it is in a lit cell: along the straight corridors from where you stand, as far as your light reaches. You see nothing round a corner, so a hunter two steps away can be invisible.
Three cells in each maze are lookouts, marked with a diamond. From a lookout you see over the hedges nearby. A lookout gives no points. It gives only information.
You have three lives. After a catch the hunters scatter far from the start, and for steps you cannot be caught. Each level adds a hunter (up to four), makes them pause less, shortens your light and quickens the pace.
The hunters' rule
The hunters are owls. Their rule is simple and is known to the agent. It is the agent's transition model.
- Each step a hunter pauses with probability (this level).
- Otherwise it moves one cell. It prefers to keep going straight (weight eλ, λ = ) and dislikes turning back (weight e−ρ, ρ = ).
- Within steps of you it leans towards you: an exit that brings it one step closer is eκ times as likely, κ = .
- You are caught if a hunter ends a step in your cell, or the two of you cross.
These numbers are settings of the game, not results.
Learn by doing
Try this
- Play a level yourself. Before you start, guess: how many steps does a hunter stay out of sight before it surprises you? Play with the beliefs hidden, as the game is meant to be played. After each catch the line under the screen tells you how long that hunter had been unseen.
- Watch the agent, with its beliefs shown. Predict what the haze will do when the agent turns into a long corridor, and what it will do behind the agent's back. Then watch. The haze is not decoration: it is the probability the agent gives to a hunter being in each cell.
- Switch the agent's curiosity off. Will it still visit the lookouts? Will it live as long? Watch for a while, then run the measurement below and compare your guess with the count.
- Set the planning depth to 1. The agent now weighs only its next step. Predict how it will meet a hunter that is two cells away round a corner. Then restore the depth and watch the same seed again.
- Play with the coach. You play; the haze and a small gold chevron show what the agent believes and which move it would make. Notice where you and it disagree, and who was right.
A fair test
What curiosity is worth here: count it
Watching one game proves little, because luck is large. This runs whole games in the background, the same seeded mazes for an agent with curiosity and an agent without, at the planning depth and precision you have set. Each game stops at game over or after steps.
A longer count, made once for this page with a script and not by the button: 200 seeded games each at depth 5 and γ = 4, mean ± standard error. With curiosity the agent survived 742 ± 25 steps and without it 667 ± 24, a difference of 75 ± 34 on the same seeds, about two standard errors. Catches per 1,000 steps were 3.9 with and 4.4 without, a difference within the noise game by game (−0.4 ± 0.5). The score was 1,884 ± 45 with and 1,965 ± 55 without, also within the noise (−81 ± 69). So at these settings curiosity lengthens survival a little and does not raise the score.
Nothing measured yet.
| With curiosity | Without |
|---|
The mathematics
What is being computed
The agent keeps one belief per hunter. A hunter's hidden state s is its cell and its heading. The outcome o is what the forager sees of that hunter from its own cell p: the hunter's state if it is in a lit cell, otherwise "not seen". Because the hunters move independently of each other and can be told apart, the belief about all of them is exactly the product of these separate beliefs.
B is the hunters' rule above: it spreads the belief one step along the corridors (this is why the haze creeps round corners). A is sight. If the hunter is seen, the belief becomes certain. If it is not seen, every lit cell is ruled out and the rest is rescaled to sum to one. Seeing nothing is evidence too.
V is the set of states in cells that would be lit from a cell on the plan, and m is the probability that the hunter is among them. Epistemic value is the expected information gain: the entropy of the predicted outcome minus the expected ambiguity. Sight here is deterministic, so the ambiguity is zero and the information gain is simply the entropy of what would be seen. It is largest where the agent is unsure whether a look will find a hunter, and zero where it already knows.
A plan π is a sequence of moves; τ counts its steps; i counts hunters. C holds the preferences, as log-preferences up to a constant: . The expected log-preference at a step is therefore − × (probability of being caught there) + × (seed) + × (nearer). The probability of being caught is the belief mass that the hunters' rule carries into your cell, or across your path, at that step. The same number can be written as risk plus ambiguity, G = Στ KL[Q(oτ|π) ‖ C] + 0. Collecting and looking are not two motives added together afterwards: they are two parts of one quantity. G is a cost; lower is better.
σ is the softmax and γ is the precision of beliefs about plans. The agent takes the first move u with the largest summed probability, then plans again from the next cell. With curiosity switched off the epistemic term is left out of G; nothing else changes.
Plans are all move sequences of the chosen depth that do not walk into a hedge and do not turn straight back on themselves (except in a dead end). The first move may be a turn back. The agent's plans never wait: a plan that waits first scores better only because it pushes a bad step beyond the horizon. Beliefs along a plan are carried forward with B alone, the standard predictive belief Q(sτ|π); the agent does not imagine how its future looks would change its future plans.
Reading
Where this comes from
What is established
In active inference, plans are scored by expected free energy, which separates into a pragmatic part (reaching preferred outcomes) and an epistemic part (expected information gain). Friston and colleagues (2015) set this out and showed that it produces information-seeking first and goal-seeking after; the textbook treats it in chapters 2, 4 and 7. Exact Bayesian filtering over a discrete state space, used here for the haze, is the same belief updating described there for discrete-time models.
Games have long served as test beds for these agents. Friston, Daunizeau and Kiebel (2009) used a car on a hill; Tschantz and colleagues (2020) and Fountas and colleagues (2020) scaled expected free energy to learned models in control and game-like tasks.
This page is an illustration of the framework. It is not evidence about brains or animals.
What this model leaves out
The agent is given the hunters' true rule and the true map. It learns nothing: there are no Dirichlet counts and no novelty term. Its plans are short and it does not reason about how what it sees later will change what it does later (sophisticated inference, Friston and colleagues 2021, would). Information is counted for its own sake, whether or not it would change a decision, so the measured benefit of curiosity can be small or negative; the page reports whatever the count is.
The size of that benefit, and even its sign, depend on the preferences and on how far the lantern reaches. These comparisons were each made over 200 seeded games. With the settings of this page (lantern reach 1 cell, log-preference −45 for being caught) curiosity added 75 ± 34 steps of survival. With a lantern reach of 2 cells and the same preferences it took away 53 ± 34 steps and 493 ± 72 points. With a much weaker aversion to capture (−10) it shortened survival at either reach (282 ± 11 steps against 443 ± 13 at reach 1).
The preferences and the hunters' weights were chosen by hand to make a playable game. The forager's own position is assumed to be known exactly. Waiting is a move for you but not for the agent. The owls and the beetle are characters, not models of any animal.
- Parr, T., Pezzulo, G. & Friston, K. J. (2022). Active Inference: The Free Energy Principle in Mind, Brain, and Behavior. MIT Press. doi:10.7551/mitpress/12441.001.0001
- Friston, K., Rigoli, F., Ognibene, D., Mathys, C., FitzGerald, T. & Pezzulo, G. (2015). Active inference and epistemic value. Cognitive Neuroscience 6(4), 187–214. doi:10.1080/17588928.2015.1020053
- 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
- Friston, K. J., Daunizeau, J. & Kiebel, S. J. (2009). Reinforcement learning or active inference? PLoS ONE 4(7), e6421. doi:10.1371/journal.pone.0006421
- Friston, K., Da Costa, L., Hafner, D., Hesp, C. & Parr, T. (2021). Sophisticated inference. Neural Computation 33(3), 713–763. doi:10.1162/neco_a_01351
- Tschantz, A., Millidge, B., Seth, A. K. & Buckley, C. L. (2020). Reinforcement learning through active inference. arXiv:2002.12636
- Fountas, Z., Sajid, N., Mediano, P. A. M. & Friston, K. (2020). Deep active inference agents using Monte-Carlo methods. Advances in Neural Information Processing Systems 33.