Home▸Articles▸Cognitive Science

Predictive Coding 2D: Free-Energy Minimization in Hierarchical Networks

A powerful framework for understanding how brains process information efficiently by predicting sensory inputs.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What Predictive Coding Is

Predictive coding is a theoretical framework in cognitive neuroscience that posits the brain continuously generates predictions about sensory inputs and then compares these predictions with actual sensory data. The difference between prediction and perception, known as 'surprise', drives learning and adaptation.

In this 2D model, each layer of the network represents different levels of abstraction or complexity in processing sensory information, from raw input to higher-level concepts.

Free-Energy Principle

The free-energy principle suggests that biological systems minimize their free energy by predicting future states and adjusting their actions accordingly. In the context of neural networks, this means minimizing the discrepancy between predicted and actual sensory inputs.

By doing so, the network can efficiently process information and adapt to changes in its environment without expending unnecessary resources.

live demo · related simulation● LIVE

How It Works

In the 2D predictive-coding model, nodes represent different levels of processing. The network minimizes variational free energy by adjusting beliefs about sensory inputs based on prior expectations and current sensory data.

The Inject Surprise button introduces unexpected stimuli to test how the network updates its predictions, while the Reset Beliefs button allows resetting the initial state for further experimentation.

Applications and Real-World Examples

Predictive coding has been applied in various fields, including machine learning and artificial intelligence, to create more efficient algorithms that can learn from limited data.

In neuroscience, it helps explain how the brain processes sensory information and learns new skills by predicting outcomes based on past experiences.

Frequently asked questions

What is variational free energy in predictive coding?

Variational free energy is a measure of the difference between predictions made by the network and actual sensory inputs. Minimizing this energy helps the network adapt to new information efficiently.

How does injecting surprise affect the model's behavior?

Injecting surprise disrupts the current prediction, causing the network to update its beliefs and predictions. This process is crucial for learning and adapting to unexpected changes in the environment.

Why use a 2D model instead of a more complex one?

A 2D model simplifies the visualization while still capturing essential aspects of predictive coding, making it easier to understand the underlying principles without overwhelming complexity.

Can this model be applied outside of neuroscience?

Yes, the free-energy principle and predictive coding have applications in various fields such as machine learning, robotics, and even economics, where efficient prediction and adaptation are key.

Try it live

Everything above runs in your browser — open Predictive Coding 2D: Free-Energy Network & Error Console and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Predictive Coding 2D: Free-Energy Network & Error Console simulation

What did you find?

Add reproduction steps (optional)