Loop Lab The math of stuck patterns, and what it would take to break them

A two-state active-inference toy where one dial — sensory precision γA — turns out to be upstream of every other intervention. Move the patient archetype, apply a treatment protocol, and watch where standard exposure therapy succeeds, where it stalls, and where it fails entirely.

Math basis: Polzin et al. 2026, DOI 10.5281/zenodo.19785799 Vanilla JS, zero dependencies Behavioural interpretations = hypothesis Not medical advice
Start here

Watch standard exposure fail. Then watch grounding-first succeed.

Both trajectories use the same patient archetype, the same maths, the same starting belief. Only the order of interventions changes. About 30 seconds; no math required to see the contrast.

The Five Phenomena —
What's happening
Press a phenomenon button above, or just press Step to begin.
Why it might matter interpretation
A computational metaphor for treatment sequencing. The agent's behaviour is interpretable as a stuck pattern; that is a hypothesis, not a diagnosis.
Under the hood
γ_A 0.70 · γ_B 0.70 · T 2.00 · C_trigger −1.20 · belief(Healing) 0.40
The agent's belief, and what it sees, and what it does
Trauma
50%
belief in trauma state
Healing
50%
belief in healing state
Belief in healing — last 50 steps
Observations (red = trigger, green = safe)
Actions (↺ avoid, → engage; gold border = forced by protocol)
Patient archetype
Pick a starting point in the dial-space. Each archetype is a model preset, not a person.
Dials
Sensory precision · γA0.70
How much the agent trusts what it senses. Low = noisy returns; high = crisp readings.
Action efficacy · γB0.70
How much the agent expects its actions to do what they should.
Policy temperature · T2.00
Low = commits decisively. High = exploratory.
Trigger tolerance · Ctrigger−1.20
Negative = avoids triggers; positive = tolerates / engages.
Treatment protocol
No intervention. The untreated baseline — what happens if the model is left alone.
Run
0
Steps
0.50
q(Heal)
Last act

Bifurcation map — where this archetype lands

For each cell, 12 trajectories under argmax action selection. Colour = mean final belief in healing. Click a cell to load those dials and run a fresh trajectory above.

Zones

Reaches healing — high γA + tolerable C
Mixed / borderline
Stuck — the upstream-variable trap

Axes

x — Ctrigger: tolerance for triggers, −2 (highly avoidant) to +2 (engages with).
y — γA: sensory precision, 0.1 (cannot trust senses) to 4.0 (perfect localisation). Log-spaced.
Hover a cell for its values. Click to load.

What this is, what this is not

Loop Lab is a teaching toy. It is not a clinical tool, not a diagnostic instrument, and not a treatment plan.

1. What this is. A 2-state computational toy drawn from a peer-reviewed active-inference framework. Humans are not 2-state systems. The bifurcation map is exact mathematics about the model, not about people.

2. What the behavioural labels are. "Avoidance", "exposure response", "grounding", "trauma", "healing" are vocabulary words from the academic literature on computational psychiatry, applied here as analogy. They are interpretations of the math, not measurements of any patient.

3. What this is not. It is not a diagnostic tool. It is not a treatment plan. It is not a substitute for any standard of care. It is not a research instrument for evaluating individual patients. It has not been validated against any clinical outcome.

4. What it is for. A thinking tool for clinicians and researchers who want to argue with the math. The point is the argument, not the conclusion. If this lab makes you sceptical of the model's claims, that scepticism is the most useful thing this page can produce.

5. The thesis the lab is built to land. Under active inference, avoidance is a model attractor with a closed-form basin. Standard exposure therapy is mathematically incapable of moving certain agents out of that basin unless sensory precision (γA) is repaired first. This is a published interpretation from the cited literature; this lab makes it watchable. Disagree with the formulation, the parameter ranges, the action set, the world size, the inference scheme. Argue with what is on the screen.

Where to go for the real work:
Friston, K., Stephan, K. et al. (2014). Computational psychiatry: the brain as a phantastic organ. Lancet Psychiatry 1, 148–158.
Linson, A. & Friston, K. (2019). Reframing PTSD for computational psychiatry with the active inference framework. Cognitive Neuropsychiatry 24, 347–368.
Smith, R., Khalsa, S.S. & Paulus, M.P. (2021). An active inference approach to dissecting reasons for nonadherence to antidepressants. Biological Psychiatry: CNNI 6, 919–934.
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.
van der Kolk, B. (2014). The Body Keeps the Score. Viking.
Polzin et al. (2026). DOI 10.5281/zenodo.19785799 — the math basis paper.