← SciSim / Neuroscience
· · SciSim ·

Bayesian Brain — Predictive Coding

Prior-Likelihood · Kalman Filter · Free Energy Principle

🧠 Tier: Graduate · Computational Neuroscience
Version:
§ 01
Interactive Simulation
Variable 1
Variable 2
Input
Output
Count
0
State
Time
0
ms
Playback
Preset
Parameters
Parameter 15.0
Parameter 25.0
Input I5.0
T sim (ms)500
Overlays
§ 02
The Idea, Step by Step
▸ From a hunch, to Bayes' rule, to predictive coding
START — your brain is a guesser
Walk into your own dark bedroom and you don't grope around — you already know roughly where the bed is, so you barely glance. Your brain runs on expectations: it predicts what the world will throw at it, then mostly just checks whether the prediction was right. You usually "see" what you expect, and you really only notice the moments when reality disagrees — a chair someone moved, a step that wasn't there. Perception is less like a camera and more like a constantly-corrected guess.
BUILD — combine a guess with the evidence
Two ingredients decide what you perceive: a prior (what you expected, from past experience) and the likelihood (what your senses report right now). Bayes' rule blends them, $p(\text{cause}\mid\text{obs})\propto p(\text{obs}\mid\text{cause})\,p(\text{cause})$, and the trick is that the more reliable source gets more say — this is called precision weighting. Worked number: your memory says a sound is 10° to your left and you're fairly sure (spread ±5°); your ears say 20°, but they are noisy (±15°). The brain doesn't pick one or simply average them — it weights each by 1/variance, so the tight prior counts about nine times as much as the noisy ears, landing near 11°: it hugs the trustworthy prior while still nudging toward what you heard.
DEEPEN — predictions flow down, errors flow up
Predictive coding makes this dynamic and hierarchical. Each cortical level sends a prediction $\hat{y}$ down to the level below; that level computes a prediction error $\epsilon=y-\hat{y}$ and passes only the surprising part back up. The optimal running version is the Kalman filter, $\hat{x}_{t}=\hat{x}_{t\mid t-1}+K_t\,(y_t-H\hat{x}_{t\mid t-1})$, where the gain $K_t$ sets how far you move toward fresh data: high gain means "trust the senses" (attention turned up), low gain means "trust the model." Friston's free-energy principle frames the whole cortex as minimising this surprise. In the sim, Parameter 1 stands for prior precision, Parameter 2 for sensory (likelihood) precision, and Input I for the incoming observation.
TRY THIS in the sim above
Push Parameter 2 (sensory precision) to its maximum and change Input I: the estimate snaps straight to the input — "believe your eyes." Now drop Parameter 2 low and raise Parameter 1 (prior precision): the estimate barely budges when the input moves — a strong prior, like recognising a friend in a blurry photo. Finally sweep Input I and watch the prediction error jump and then settle as the model catches up — a miniature version of repetition suppression and the mismatch negativity (MMN).
§ 03
Equation Derivation
▸ Bayesian Brain & Predictive Coding
$$p(\text{cause}|\text{obs})\propto p(\text{obs}|\text{cause})\times p(\text{cause})$$ $$\epsilon_\ell=y_\ell-\hat{y}_\ell, \quad \hat{y}_\ell=f_\ell(\mu_{\ell+1}) \;\text{(prediction from above)}$$ $$\hat{x}_{t|t}=\hat{x}_{t|t-1}+K_t(y_t-H\hat{x}_{t|t-1}), \quad K_t=P_{t|t-1}H^T(HP_{t|t-1}H^T+R)^{-1}$$
STEP 1 — Hierarchical Predictive Coding
Rao & Ballard (1999): each cortical level predicts the level below (top-down) and sends prediction errors up (bottom-up). Representation units minimise prediction error. V1 error units fire when retinal input ≠ V2 prediction. Explains: repetition suppression, mismatch negativity (MMN), end-stopping, extra-classical RF suppression.
STEP 2 — Free Energy Principle
Friston (2005): all cortical processing minimises variational free energy F = KL[q||p] - log p(o). Simultaneously: makes posterior q accurate AND drives action to match expected sensory states. Subsumes Bayesian perception, motor control, and RL under one framework. Applications: autism (excess precision of sensory input), psychosis (abnormal prior beliefs).
STEP 3 — Kalman Filter as Neural Model
Kalman gain K_t balances prior vs likelihood (precision weighting). Neural implementation: K_t = attention (high attention = high likelihood weighting). Cerebellum implements forward model (Kalman predictor) for motor commands. Disrupting precision → attenuation of self-generated sensations (why you can't tickle yourself).
▸ Primary References

Rao & Ballard (1999) Nat Neurosci 2:79; Friston (2005) Philos Trans R Soc B

Gerstner et al. — Neuronal Dynamics (neuronaldynamics.epfl.ch, free) · Dayan & Abbott — Theoretical Neuroscience (MIT Press) · Izhikevich — DSN (dynamicalsystems.org, free)

§ 04
Frequently Asked Questions
🧠 ConceptualWhat is the core mathematical insight of Bayesian Brain — Predictive Coding?
The Bayesian Brain — Predictive Coding framework provides a rigorous bridge between microscopic neural parameters and macroscopic observables. The key insight is that complex emergent behaviours — oscillations, memory, coding precision — can be derived from simple mathematical rules governing individual neurons and their connections. The quantitative framework enables testable predictions about circuit function from experimentally measurable quantities.
Key: Mathematical rigour connects single-neuron parameters to network behaviour. Every emergent property (oscillation, attractor, code) is derivable from the microscopic rules.
🌍 AppliedHow is Bayesian Brain — Predictive Coding used in neurotechnology?
The Bayesian Brain — Predictive Coding framework is directly applied in brain-computer interfaces and computational medicine. Mathematical models derived from these principles optimise stimulation parameters for DBS, predict drug effects on network dynamics, decode neural signals for BCI applications, and guide the design of neuromorphic hardware. The quantitative framework enables model-based optimisation rather than empirical trial-and-error approaches in clinical settings.
Key: Direct applications in BCI design, DBS parameter optimisation, pharmacological modelling, and neuromorphic chip architecture.
🔬 SimulationHow do I use the simulation for Bayesian Brain — Predictive Coding?
Configure the parameter sliders on the right panel, select a preset to set up a canonical example, then press Play. The Main View shows the primary mathematical relationship; the Phase Plane shows geometric structure; the Time Series shows temporal evolution; the Parameter Sweep reveals sensitivity to inputs. All displayed quantities correspond directly to terms in the equations in Section 2. Export the data as CSV for further analysis.
Key: Each tab maps to a specific aspect of the mathematics. Use Parameter Sweep to find bifurcation points and Phase Plane to understand stability.
💡 Non-ObviousWhat is counterintuitive about Bayesian Brain — Predictive Coding?
The most surprising result in Bayesian Brain — Predictive Coding research is that small parameter changes can produce qualitatively different dynamics (bifurcations). A system that is stable for one parameter value can suddenly oscillate, burst, or become chaotic with a tiny perturbation. This sensitivity to parameters is the hallmark of nonlinear systems and has profound implications: the same neural circuit can perform completely different computations depending on its neuromodulatory state, which shifts parameters near bifurcation boundaries.
Key: Bifurcations: tiny parameter changes → qualitative behavioural change. Neuromodulators exploit this by operating near bifurcation points to switch neural circuit function.
📐 ComputationalWhat numerical methods and pitfalls apply to Bayesian Brain — Predictive Coding?
The appropriate numerical method depends on stiffness: for near-spike dynamics (HH, AdEx) use RK4 with dt ≤ 0.025 ms or implicit methods; for mean-field equations (WC, Amari) use Euler or RK4 with dt ≤ 0.5–1 ms. Always verify accuracy by halving dt and checking solution convergence. The most common errors: wrong units (mixing mV, ms, nS), missing initial conditions (not setting w₀=b×v₀ in Izhikevich), and incorrect boundary conditions in Fokker-Planck or cable equation simulations.
Key: Verify stability by halving dt. Most errors: wrong units, incorrect initial conditions, violated model assumptions. Check the model validity range before trusting any result.
§ 04 Resources
§ 05
Misconceptions & Common Errors
Sub-block A — Conceptual
"The Bayesian Brain — Predictive Coding model is only theoretical with no experimental support."
The Bayesian Brain — Predictive Coding framework has been extensively validated. Key predictions have been confirmed in electrophysiology, imaging, and pharmacological experiments. Modern neuroscience uses these models as quantitative tools integrated with the experimental cycle — for prediction, interpretation, and guidance of experiments.
📖 Rao & Ballard (1999) Nat Neurosci 2:79; Friston (2005) Philos Trans R Soc B
Sub-block B — Numerical
Applying Bayesian Brain — Predictive Coding equations outside their range of validity (wrong N, dt, or approximation regime).
Every model has a validity regime. Always check: (1) Is N large enough for mean-field? (2) Is dt small enough (halve dt and verify solution converges)? (3) Are units consistent (mV, ms, nS throughout)? (4) Are initial conditions correct? When in doubt, compare to direct simulation of the full system.
🔍 Why: Violating assumptions gives quantitatively or qualitatively wrong results — and the error is often invisible without explicit validation.
§ 05 References