Skip to content

Instantly share code, notes, and snippets.

@zyansheep
Created June 29, 2025 04:18
Show Gist options
  • Select an option

  • Save zyansheep/1b9dd1b6e4d4186ab4a67250a48e5c3a to your computer and use it in GitHub Desktop.

Select an option

Save zyansheep/1b9dd1b6e4d4186ab4a67250a48e5c3a to your computer and use it in GitHub Desktop.

The Physics of Agency: A Unified Theory of Brains and Markets?

We often use the metaphor of the market as a "collective brain" or "super-organism." We talk about the "market's beliefs" or how it "panics." This is usually just a poetic shorthand. But what if it's not? What if the mathematics that describes a single, goal-directed agent (like a brain) is genuinely the same mathematics that describes a collection of agents (like a market), just with different settings?

This post sketches a framework called the Typed Free Energy Game (TFEG) that attempts to make this claim mathematically precise. The goal is to build a single formal object that sees a brain as a "game with one player" and a market as a "game with many players," all following the exact same underlying rules.

This isn't just for philosophical kicks. If true, it would give us a powerful new tool: a single "potential function" that we could, in principle, measure for the entire economy—a kind of economic "potential energy" whose gradients could predict market movements and volatility.


Part 1: The Core Engine — A Single Brain

Let's start with one agent. Modern theories in neuroscience, particularly Karl Friston's Active Inference, model the brain as a prediction machine. The core idea is simple:

  1. You have an internal generative model of how the world works ($p_\theta$). This model generates predictions about what you expect to see and feel.
  2. You constantly receive sensory data ($s$) from the world.
  3. You want to minimize surprise (or "prediction error"). Surprise is the gap between what you expected and what you got.

You can minimize surprise in two ways:

  • Perception (Update your beliefs): If you see something unexpected, you can change your mind about what's causing it. "I thought that noise was the wind, but it was a cat. I'll update my beliefs."
  • Action (Change the world): If you see something unexpected, you can act to make the world match your predictions. "My hand feels cold, which is surprising. I'll move it into the sunlight to make it warm, fulfilling my prediction of being warm."

This entire process is driven by minimizing a quantity called Variational Free Energy ($F$). You can think of it as a mathematical formalization of "surprise." For a given agent $i$:

$$ F_i(\text{beliefs}, \text{action}) = \underbrace{\mathbb{E}[\ln(\text{my beliefs}) - \ln(\text{my model of the world})]}_{\text{Surprise + Model Complexity}} $$

Minimizing this free energy makes your beliefs a better explanation of reality, and makes your actions shape reality to fit your beliefs. The entire brain, under this view, is an engine built to do one thing: slide downhill on the landscape of its own free energy.


Part 2: The Crowd — A Financial Market

Now, let's look at a market. We have many agents ($i \in {1, \dots, N}$). Each agent $i$ has their own:

  • Beliefs: A private model of a stock's future cash flows.
  • Goals: A desire to make money, balanced by their risk aversion.
  • Actions: Placing buy or sell orders.

The standard way to model this is with Mean-Field Games. The core insight is that an agent in a massive crowd doesn't track every other person. They react to the average behavior of the crowd—the "mean field." You make your best move based on the current price, which is an aggregate of everyone else's actions.

The key tension is that there's no single "market belief." There are millions of conflicting beliefs. The market price is not an opinion; it's the equilibrium point where all these conflicting ambitions and actions temporarily balance out.


Part 3: The Unification — The Free Energy Game

Here's the central claim. We can describe the entire market using a single, global free energy function. We construct it by simply taking a weighted sum of the individual free energies of all agents.

Let's define the Population Free Energy $\mathcal{F}$:

$$ \mathcal{F}(\text{all beliefs}, \text{all actions}) = \sum_{i \in \text{Agents}} \mathbf{W}(i) \cdot F_i $$

Here, $F_i$ is the individual free energy (surprise) of agent $i$, and $\mathbf{W}(i)$ is a weighting function. This weight represents the "influence" or "power" of that agent.

  • For a single brain: We can think of it as one agent, so $I = {1}$ and $\mathbf{W}(1)=1$. The population free energy $\mathcal{F}$ is just the individual free energy $F$. The math reduces perfectly.
  • For a market: This is where it gets interesting. What is an agent's "power" in a market? It's their capital. We can propose that the weighting function $\mathbf{W}(i)$ is proportional to an agent's wealth.

This gives us the "money = power" principle in a precise, mathematical form. The market's collective objective function $\mathcal{F}$ is a sum of individual objectives, but the agents with more capital get a bigger vote.

The Dynamics are Automatic

Once we have this global $\mathcal{F}$, the behavior of the entire system is described by one simple rule: everything flows downhill on the $\mathcal{F}$ landscape.

  1. Belief Updates (Perception): Each agent updates their beliefs to reduce the global $\mathcal{F}$.

    $\dot{\mu}_i \propto -\nabla_{\mu_i} \mathcal{F}$

    (My beliefs flow down the gradient of collective free energy.)

  2. Order Placement (Action): Each agent chooses actions (orders) to reduce the global $\mathcal{F}$.

    $\dot{a}_i \propto -\nabla_{a_i} \mathcal{F}$

    (My actions flow down the gradient of collective free energy.)

Remarkably, these simple gradient flows on our proposed $\mathcal{F}$ appear to recover the complex forward-backward equations used in state-of-the-art Mean-Field Game models of markets. The same principle—minimize free energy—drives both individual cognition and collective market dynamics.


Part 4: So What? The Practical Payoffs

This unification isn't just an elegant mathematical curiosity. It solves several long-standing problems and offers new, testable predictions.

Old Problem / Fuzzy Analogy TFEG Resolution: A Concrete Mechanism
"The market has no single mind or belief." Correct. We don't merge beliefs. Each agent $i$ keeps their own private belief $q_{\mu_i}$. They are only linked through their weighted contribution to the global objective function $\mathcal{F}$.
"What's the difference between exploring and exploiting?" We can give actions a type. A limit order is an inspect action: you're placing a cheap bet to gather information about market sentiment. A market order is an enact action: you're paying a premium to force a change. Both serve to minimize the same $\mathcal{F}$.
"There is no 'potential energy' for market prices." We claim there is: it's $\mathcal{F}$. Prices themselves don't have a simple potential, but the underlying system of agents does. $\mathcal{F}$ is a Lyapunov functional: the system will always move to decrease it. This is a very strong and testable claim.

The most exciting payoff is the last one. If $\mathcal{F}$ is a true Lyapunov function for the market, we could potentially:

  1. Estimate $\mathcal{F}$ online from high-frequency order book data.
  2. Measure its gradient $|\nabla \mathcal{F}|$. This value would represent how "out of equilibrium" or "tense" the market is.
  3. Use this as an early-warning signal. A sharp increase in the "tension" metric could predict an imminent volatility spike or market correction, long before prices themselves show a clear signal.

The Road Ahead

This is a proposal, not a finished theory. The immediate next steps are to prove its core claims:

  1. Build a Toy Model: Show that for a classic, simple market model (like the Kyle model), the standard equations really do emerge from our global $\mathcal{F}$.
  2. Prove It: Formally mechanize the proof in a system like Coq to certify that $\mathcal{F}$ is a true Lyapunov function.
  3. Test It: Apply this to real financial data. Does the gradient of our estimated $\mathcal{F}$ actually predict volatility?

By lifting brains and markets into this shared mathematical framework, we get more than just a better metaphor. We get a single optimization principle, a single potential function to measure, and a single framework for building and testing models of complex adaptive systems.

@zyansheep
Copy link
Copy Markdown
Author

Idea generation w/ o4-mini-high, rewriteup with Gemini 2.5. Looks like an interesting idea but needs more investigation to confirm it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment