# Distilling the Internal Model Principle part II

*This post was written during the* [*agent foundations fellowship*](/posts/WiMnhMXu9CM5ytu3t/work-with-me-on-agent-foundations-independent-fellowship) *with* [*Alex Altair*](https://www.lesswrong.com/users/alex_altair) *funded by the* [*LTFF*](https://funds.effectivealtruism.org/funds/far-future).

Introduction
============

This is the second part of a two posts series explaining the Internal Model Principle and how it might relate to AI Safety, particularly to Agent Foundations research. In the [first post](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle), we constructed a simplified version of IMP that was easier to understand and focused on building intuition about the theorem's assumptions. In this second post, we explain the general version of the theorem as stated by Cai&Wonham[^0j5c5ysh2yvm] and discuss how it relates to alignment-relevant questions such as [agent-structure problem](https://www.lesswrong.com/posts/oxsBpx9v3bgxraiPj/towards-a-formalization-of-the-agent-structure-problem) and [selection theorems](https://www.lesswrong.com/posts/G2Lne2Fi7Qra5Lbuf/selection-theorems-a-program-for-understanding-agents). 

We present the more general setup and explain Feedback and Regulation conditions. With those, we prove a first result. Then, we discuss the meaning of this first result and add another condition called "Observability" to derive another result. After this, we provide a worked out example and discuss possible extensions of the theorem.

Setup
=====

The IMP from Cai&Wonham[^0j5c5ysh2yvm] originally models the following control theory situation:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/d4fd185a4513a2633e9e847ad7a11a3ee436eef6467e95eb.png)

Suppose there's, for example, a chemical powerplant in a given environment. The temperature of the plant should be constant and the plant's temperature is affected by the environment's temperature, since they exchange heat, so there is a temperature system made of heaters and air conditioning systems inside the plant, controlled by a controller. This controller controls this systems: it receives information from the environment's temperature and passes a signal to the temperature inside the plant to counter-act the effect of the environment:

*   If the environment is hot, air conditionings are turned on.
*   If the environment is cold, heaters are turned on.

Naturally, one thing that could happen is that the controller could receive information from the environment and then, after that, control the temperature system. The theorem shows that, under specific circumstances, the controller actually "foresee" the environment's temperature and control the plant temperature concurrently to the environment's temperature changing. We use "foresee" because what the theorem really shows is that, under some circumstances, the controller is autonomous (i.e, it doesn't use outside information to decide how to control the temperature system) and it controls the temperature system in a way that counter-acts the environment's effect (even without using information from the environment). 

In Cai&Wonham's[^0j5c5ysh2yvm] book, 

> "Environment (E), Controller (C) and Plant (P) are dynamic systems which generate, via suitable output maps, the reference, control and output signals respectively. The objective of regulation is to ensure that the output signal coincides (eventually) with the reference, namely the system ‘tracks’. To this end the output is ‘fed back’ and compared (via $\otimes$) to the reference, and the resulting tracking error signal used to ‘drive’ the controller. The latter in turn controls the plant, causing its output to approach the reference, so that the tracking error eventually (perhaps as $t \to \infty$) approaches ‘zero’. Our aim is to show that this setup implies, when suitably formalized, that the controller incorporates a model of the Environment: this statement is the Internal Model Principle."

We model the world as any set $X$. For example, we could consider the whole world as $X = E \times C \times P$, comprised of environment, controller and plant. We assume there's a discrete and deterministic world dynamics $\alpha : X \to X$ that specifies how the world evolves. 

We could also consider $P$ and $C$ as a single joint system called internal system (or just controller), and then we'd have $X = E \times C$ (we're calling $C \times P$ just $C$).

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/cfc0275425f7fcb1c52d2ab54e3d49962aadf67cbf7ce01d.png)

We could consider, for example, $X = E \times C \times P$ (left) or $X = E \times C$ (right)

We say a system is autonomous if its next state depends only on the previous state. For example, if $A$ and $B$ are sets, then the function $f : A \to A$ is autonomous and the function $g: A \times B \to A$ is not. We'll just say "A is autonomous" as a slight abuse of terminology. We'll usually write $X_S \subset S$ to denote that $X_S$ is an autonomous system inside $S$ \- while $S$ don't need necessarily to be autonomous, for $S = E,C,P$. We assume the environment is autonomous (intuitively, because we can't control the environment, it's a given) with update rule $\alpha_E : X_E \to X_E$, where $X_E \subseteq E$. We assume, however, the environment is always autonomous, so $E = X_E$.

We'll denote by $K \subset X$ the set of good states (that is, the set we want our system to be in after a large number of time-steps). It could be, for example, states where the plant's temperature is constant, for any environment state. A important thing to notice is that $K$ is not necessarily the set of states such that the system converges to, because it need not be $\alpha$-invariant - that is, we usually say a system converges to a part of it if it remains in that part after convergence - and it may not be the case that for $x \in K, \alpha(x) \in K$ \- we haven't added any specific condition ensuring that. We don't care about what happened "prior to convergence", so all the states and assumptions we care about will be true on $K$.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/711ee8496f9cb31d353b45033ce2a35c7d6922d17e062224.png)

When we consider $X = E \times C$, the set of good states $K \subseteq X$ is a region on the $E \times C$-plane. Note that $K$ is not necessarily a rectangle and it can be any region of the plane. 

Since $K \subset X$, we can project states out of $K$. For example, if $X = E \times C \times P$, we can write the canonical projection $\pi_C : E \times C \times P \to C$ given by $\pi_C((x_E,x_C,x_P)) = x_C$. More generally, we could have any function $\gamma : X \to C$ acting as "projection". We define $X_C := \gamma(X) \subseteq C$, that is, $X_C$'s elements are controller states that we get from projecting good states to controller states. Recall that earlier we said we would use the "$X_S$" notation to denote autonomous systems, and one of the conclusions of the theorem is that $X_C$ will be autonomous - i.e, we will be able to define a function $\alpha_C : X_C \to X_C$ that is also interesting to us. At last, note that, by definition, $\gamma : X \to X_C$ is surjective.

So until now in our setup we have:

*   $X$ world, $\alpha : X \to X$
*   $X_E$ environment, $\alpha_E : X_E \to X_E$
*   $K \subseteq X$ set of good states
*   $\gamma : X \to X_C$ , $X_C$ denoting all the controller states we're interested in

At this point, the reader might be tempted to ask two things:

1.  Ok, the controller states are obtained through the world via a "projection" $\gamma$, but what about the environment states?
2.  Is it always true that the environment and world dynamics are consistent with each other? For example, if $X = X_E \times X_C$, it could be that $\pi_E(\alpha(x_E, x_C)) \neq \alpha_E(\pi_E(x_E, x_C))$

To answer these questions, we'll first play around with the $X = X_E \times X_C$ setup, and then arrive at a property that can be abstractly imposed to other setups.

If  $X = X_E \times X_C$, we have that $X_E =\pi_E(X)$. Here, it's not true that $X_E \subseteq X$, but it's obvious that $X_E$ is "a part" of $X$ or "like a subset" of $X$. We want a general property to relate $X_E$ and $X$ such that $X_E$ is "like a subset" of $X$. In mathematics, we use the notion of insertion to work with this. If $A \subset B$, one can trivially define an injection between $A$ and $B$ (the identity, for example). If $A \not \subseteq B$, we think of $A$ as "like a subset" of $B$ if one can define an injective function $i: A \to B$. So in general we can just ask for $X_E$ and $X$ to be such that there's an injective function $i_E : X_E \to X$. This partly answers question 1. Now, we'll look closer at insertions to understand if any insertion is allowed. 

(For the following, if you're not familiar with equivalence relations and partitions, go read this section of [my first post](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle))

Note that $\pi_E : X \to X_E$ is not necessarily invertible, but $\pi_E : X \mod \ker \pi_E \to X_E$ is a bijection (exercise for the reader), so invertible.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/e4a72850059c8d210b8f7dc0b71b0e2242f1a1fe7f1d2627.png)

Each $x_E$ point determines a line $[x_E] = \{(c,e) \in X; \pi_E(c,e)= x_E\}$. Then, we can define $\pi_E^{-1}(x_E) = [x_E]$

$X \mod \ker \pi_E$ is a set containing lines parallel to the $X_E$-axis, so while $\pi_E : X \to X_E$ maps points on $X$ to points on $X_E$, $\pi_E : X \mod \ker \pi_E \to X_E$ maps lines to points on $X_E$. The inverse $\pi_E^{-1} : X_E \to X \mod \ker \pi_E$ takes a point in $X_E$ and map it to the specific parallel line such that, when projected over $X_E$, it reaches $x_E$. Hence, if we want to define an insertion$i_E : X_E \to X$, we can do the following:

*   Given $x_E$, compute $\pi_E^{-1}(x_E)$, this is a line.
*   Choose any point in the line and define it to be $i_E(x_E)$.

By this procedure, if $X_E =\mathbb{R}$, for example, we can define an uncountable amount of insertions between $X_E$ and $X$. 

Note, however, that we want the environment to be part of the world, and thus to evolve consistently with the world. For a given $x_E \in X_E$, we have two ways of producing updates of the world now:

1.  Compute $i_E(x_E) \in X$, then compute $\alpha(i_E(x_E)) \in X$
2.  Compute $\alpha_E(x_E)$, and then $i_E(\alpha_E(x_E)) \in X$

They don't necessarily need to be the same.

Thus, to answer question 1, we ask that $X_E$ and $X$ are such that there's $i_E : X_E \to X$ injective.

To answer question 2, we ask that this injection $i_E$ is such that $i_E(\alpha_E(x_E)) = \alpha(i_E(x_E)), \forall x_E \in X_E$.

We define $\tilde{X}_E := i_E(X_E)$.

Note that, if $X_E \subseteq X$, this is the same as asking $\alpha \vert_{X_E} = \alpha_E$, so deep down we're asking something related to $X_E$ being $\alpha$-invariant. Indeed, $\tilde{X}_E$ is $\alpha$-invariant because:

*   if $x \in \tilde{X}_E$, then $x = i_E(x_E)$ and $\alpha(x) = \alpha(i_E(x_E)) = i_E(\alpha_E(x_E)) \in \tilde{X}_E$

Assumptions
===========

Feedback Condition
------------------

We want to state something that enables us to proof the controller is autonomous and it models the environment. In the [first post](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle), we argued that one way to ensure that is by asking the feedback condition:

$$
\ker \gamma \leq \ker \gamma \circ \alpha
$$

We want to be able to model a situation where the controller, prior to convergence, needs information from the environment to "learn" how the environment works. Then, after a large number of time-steps, the controller learns the environment's behaviour and becomes autonomous, so instead of asking full feedback, we only ask the controller to be autonomous on good states, that is,

$$
\ker \gamma \vert_{K} \leq \ker \gamma \circ \alpha \vert_{K}
$$

Regulation Condition
--------------------

We want all environment states to be good states, i.e, to have reached convergence. Since $X_E$ is not necessarily a subset of $X$, we ask 

$$
\tilde{X}_E \subseteq K
$$

The Controller Models the Environment
=====================================

With this assumptions and setup, we're already able to prove the first part of the theorem, that states that the controller models/tracks the environment 

Conclusion (1)
--------------

There exists a unique mapping $\alpha_C : X_C \to X_C$ determined by $\alpha_C \circ \gamma \vert_{K} = \gamma \circ \alpha \vert_{K}$

Proof: 

Let $x_C \in X_C$, then $x_C = \gamma(x)$, for $x \in K$. Define $\alpha_C(x_C) = \gamma \circ \alpha(x)$. $\alpha_C$ is well defined because if $x_C = \gamma(x) = \gamma(x')$, then$(x, x') \in \ker \gamma \vert_{K} \implies (x,x') \in \ker \gamma \alpha \vert_{K}  \implies \gamma(\alpha(x)) = \gamma(\alpha(x'))$.

The mapping $\alpha_C$ is uniquely determined by $\alpha_C \circ \gamma \vert_{K} = \gamma \circ \alpha \vert_{K}$: let $\alpha_{C,1}$ and $\alpha_{C,2}$ satisfying $\alpha_{C,i} \circ \gamma \vert_{K} = \gamma \circ \alpha \vert_{K}$. Then, for any $x_C =\in X_C, x_C = \gamma(x)$ for some $x \in K$, since $\gamma$ is surjective and thus $\alpha_{C,1}(x_C) = \alpha_{C,1}(\gamma(x)) = \gamma(\alpha(x)) = \alpha_{C,2}(\gamma(x)) = \alpha_{C,2}(x_C)$

This point guarantees that we have an autonomous $\alpha_C : X_C \to X_C$ and that it

Conclusion (2)
--------------

It's true that $\alpha_C \circ \gamma \vert_{\tilde{X}_E} = \gamma \circ \alpha \vert_{\tilde{X}_E}$

Proof: Let $x \in \tilde{X}_E$, since $\tilde{X}_E \subset K$ by the **regulation condition, **$x \in K$ and hence $\alpha_C \circ \gamma(x) = \gamma \circ \alpha(x) = \gamma \circ \alpha \vert_{\tilde{X}_E}(x)$, since $x \in \tilde{X}_E$.

Note that if $X_E \subseteq X$, we have $\alpha \vert_{X_E} = \alpha_E$, so this states that $\alpha_C \circ \gamma \vert_{X_E} = \gamma \circ \alpha_E$, that is, the controller tracks the environment. For more comments on why $\alpha_C \circ \gamma \vert_{X_E} = \gamma \circ \alpha_E$ means the controller tracks/models the environment, check out my [first post](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle) and the section below. 

Note that $\alpha \vert_{\tilde{X}_E}$ can be thought of as the environment dynamics inserted into the world.

We say the "internal model" in the controller is the pair consisting of the set $X_M := \gamma\vert_{\tilde{X}_E}(\tilde{X}_E)$ and the rule $\alpha_C \vert_{X_M}$

In what sense is this a 'model'?
================================

We now digress about the meaning of the theorem above. 

On this session, it's helpful to think that $X_E \subseteq X$, thus $\alpha_E =\alpha \vert_{X_E}$. The second conclusion of the theorem is $\alpha_C \circ \gamma \vert_{X_E} = \gamma \vert_{X_E} \circ \alpha_E$, that is, $\alpha_C$ evolves according to $\alpha_E$ autonomously: Consider the environment is in state $x_E \in X_E$ at time-step $t$, its next state is $\alpha_E(x_E)$ and the internal system state (which can be calculated via $\gamma$) is $\gamma \vert_{X_E}(\alpha_E(x_E))$ in time-step $t+1$. On the other hand, $\gamma(x_E)$ is the system’s state in time-step $t$, and in time-step $t+1$ it is $\alpha_C(\gamma(x_E))$. The theorem ensures those two expressions for the internal system’s state in time-step $t+1$ are **equal. **

This is qualitatively different from the internal system receiving information about the environment and one time-step later updating to track the environment. The internal system is updating accordingly to the environment in the **same** time-step. 

To clarify this, consider an analogy of a dog running after a beetle. The dog is initially in the position $d_0$ and the beetle in the position $b_0$. One thing that might happen is that the dog see the beetle's position and starts to move there. When the dog arrives, the beetle already left that position, and is now in a new position. So the dog starts moving to this new beetle position, and when he arrives, the beetle already left again, and so on. 

Another qualitatively different thing that can happen is that the dog actually understands (i.e, "models") how the beetle will move. So instead of moving to the beetle's current position, it moves to where it predicts the beetle will be in the future, so that it can catch it.

The theorem also states $\alpha_C$ is unique, so it can’t be the case that there’s other dynamics in a system that satisfies perfect regulation and feedback structure. Hence, the dynamics on the internal model will necessarily be the one that models the environment.

In the dog-beetle analogy, the theorem guarantees that the second scenario will **necessarily happen** if the dog behavior satisfyies our hypothesis.

The Controller Faithfully Models the Environment
================================================

To understand this session better, we recommend the reading of the first post. There, we explain more intuitively the key ideas used here.

In our first post, we were able to prove an analogous result with only feedback structure condition. There, we didn't need to worry about the difference between environment and world and good states. The last theorem is a particular scenario of this post's theorem when we have $X_E = K = X$ and $\alpha_E = \alpha \vert_{X_E}$. 

Analogous to the first post, the results proved above includes [pathological cases](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle#Example_1__even_odd_integer_walking), where, for example, the controller could be $X_C = \{x_{C,1}, x_{C,2}\}$ and the environment $\tilde{X}_E = \mathbb{N}$. Even if we had that $\alpha_C \circ \gamma \vert_{\tilde{X}_E} = \gamma \circ \alpha \vert_{\tilde{X}_E}$, the controller wouldn't have the "expressivity" to faithfully model the environment: it doesn't have enough states to do so. We'll now introduce the observability condition and prove a lemma to conclude the controller faithfully models the environment if, additionally to the prior assumptions, observability is also satisfied. 

Observability can be stated as

$$
\inf \{\ker \gamma \circ \alpha^n \vert_{\tilde{X}_E}; n = 0,1,2,\ldots\} = \bot
$$

For intuition on what does this mean and why we ask this, check out [this section](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle#Equivalence_relations_as_information) of the first post

Generalized Feedback Lemma
--------------------------

We'll prove a generalization of the feedback structure condition in an analogous way we did in the [first post](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle#Lemma__Generalized_Feedback_Condition), we'll use that together with observability to conclude the controller faithfully models the environment. 

The result we want to prove is

$$
\ker \gamma \vert_{\tilde{X}_E} \leq \ker \gamma \circ \alpha\vert_{\tilde{X}_E} \leq \ker \gamma \circ \alpha^ 2\vert_{\tilde{X}_E} \leq \ker \gamma \circ \alpha^ 3\vert_{\tilde{X}_E} \leq \ldots \leq \ker \gamma \circ \alpha^k\vert_{\tilde{X}_E} \leq \ldots
$$

We'll prove it by induction on $k$. 

(Base case): If $k = 1$, by feedback condition, we know$\ker \gamma \vert_K \leq \ker \gamma \circ \alpha \vert_{K}$. Since $\tilde{X}_E \subseteq K$ by regulation condition, $(x,y) \in \ker \gamma \vert_{\tilde{X}_E} \implies (x,y) \in \ker \gamma \vert_K \implies (x,y) \in \ker \gamma \circ \alpha \vert_{K}$, but since $\tilde{X}_E$* is *$\alpha$-invariant, and $(x,y) \in \tilde{X}_E$, then $\alpha(x), \alpha(y) \in \tilde{X}_E$, so $(x,y) \in \ker \gamma \circ \alpha \vert_{\tilde{X}_E}$. 

(Induction Hypothesis):  Suppose now the theorem holds up until $n$.

 (Inductive step) Let  $x,y \in \tilde{X}_E$, then, by definition of kernel of a function, $(x,y) \in \ker \gamma \circ \alpha^{n} \vert_{\tilde{X}_E} \iff (\alpha^n(x), \alpha^n(y)) \in \ker \gamma \vert_{\tilde{X}_E}$ 

Let $s := \alpha^n(x), t := \alpha^n(y)$. Since $\tilde{X}_E$* is *$\alpha$-invariant, we know $ s,t \in \tilde{X}_E$. So the equivalence above gives us $(s, t) \in \ker \gamma \vert_{\tilde{X}_E}$. By the base case, we have that $(\alpha(s), \alpha(t)) \in \ker \gamma \circ \alpha \vert_{\tilde{X}_E}$, but $(\alpha(s), \alpha(t)) = (\alpha^{n+1}(x), \alpha^{n+1}(y))$, so the result follows by induction. 

Conclusion (3)
--------------

$\gamma \vert_{\tilde{X}_E}$ is injective

Proof:

1.  By generalized feedback lemma, $\inf \{\ker \gamma \circ \alpha^n \vert_{\tilde{X}_E}; n = 0,1,2,\ldots\} = \ker \gamma \vert_{\tilde{X}_E}$
2.  By observability, $\inf \{\ker \gamma \circ \alpha^n \vert_{K}; n = 0,1,2,\ldots\} = \bot$, but since $\tilde{X}_E \subset K$, $\ker \gamma \circ \alpha^n \vert_{K} \leq \ker \gamma \circ \alpha^n \vert_{\tilde{X}_E}$, for any $n$. Hence, $\inf \{\ker \gamma \circ \alpha^n \vert_{\tilde{X}_E}; n = 0,1,2,\ldots\} \leq \inf \{\ker \gamma \circ \alpha^n \vert_{K}; n = 0,1,2,\ldots\} = \bot$ 
3.  So $\ker \gamma \vert_{\tilde{X}_E} = \bot$, so $\gamma \vert_{\tilde{X}_E}$ injective

In the next section, we explain why $\gamma \vert_{\tilde{X}_E}$  being an injection provides us the meaning of faiyhfully modeling. 

Cardinality and expressivity
============================

In the first post, we concluded $\gamma : X \to X_C$ satisfying the theorem's hypothesis is necessarily a bijection. In terms of cardinality, this means, by definition, that $|X_C| = |X|$. 

In this post, we concluded $\gamma : X_E \to X_C$ injection. In cardinality terms, $|X_E| \leq |X_C|$. 

Note that the elements of $X_E$ fully represents the description of each environment state.  Say the environment is the outside of a chemical plant and say the chemical reactions being done there depends on the temperature and pressure of the plant, which in turns depends on the temperature and pressure of the environment. Then, elements $x_E \in X_E$ could be ordered pairs $x_E =(T_E, P_E)$ comprising the external temperature and pressure. On the other hand, if there's an additional relevant environment feature, say, the water delivered from the environment need to be treated (for example, because otherwise the water used in the reactions will be contaminated), one would want to consider an environment state as $x_E =(T_E, P_E, W_E)$, where $W_E$ stands for "quality of water". In other words, $W_E$ is a relevant feature and if we don't include it in the environment, it's as if the environment is not "expressive" enough to model the whole system, and thus even if the theorem applies and the controller of the plant develops an internal model, it could be that it runs poorly, i.e, have bad performance overall (note, though, that we haven't discussed what it means for an internal model to have good performance in reality).

The point here is that the elements of $X_E$ are the only piece of our framework that encompasses the notion of "expressivity".  All the notion of "expressivity" in our setup comes from the sets $X_E$ and $X_C$ (for the controller, you could also say the expressivity comes from $\gamma$, since $X_C$ is determined by $\gamma$, i.e, $\gamma(X) = X_C$). 

The example above illustrated *one way* the states can show *expressivity*, that is, by the *structure* of the set of states: If $X \subseteq \mathbb{R}^{14}$, we perhaps have 14 different relevant features, that could be independent or not. If $X \subseteq \mathbb{N}^{10}$, we have 10 features with natural values. 

Another way the states have expressivity is via the state set cardinality, as we talked in the beginning of this section: if $X$ has $|X| = 10$ (that is, 10 elements), it can only represent 10 different states.  If $|X| = |\mathbb{N}|$, then there's a countable quantity of different states. Recall that cardinality is defined via mappings:

*   $f: X \to Y$injection $\iff |X| \leq |Y|$
*   $f: X \to Y$surjection $\iff |X| \geq |Y|$
*   $f: X \to Y$ bijection $\iff |X| = |Y|$

Thus, a state set $X$ exhibits expressivity in two ways:

1.  Via $X$'s internal structure
2.  Via $X$'s cardinality 

Our theorem states that a necessary condition for the internal system to have an internal model of the environment is $|X_E| \leq |X_C|$, that is, in order for the internal system to *model* the environment, it must exhibit at least as much expressivity as the controller (in the second sense of expressivity). In other words, if the internal system isn't at least as expressive as the environment, the **internal system necessarily can't have an internal model of the environment.**

Summarizing the whole theorem-meaning discussion, 

*   The semantics of the world "model" in the theorem means faithfully tracking/simulating. That is, for states in $\tilde{X}_E$ (which the internal system views as $X_M$) the internal system doesn't wait for the environment and then update a timestep later following the environment. Instead, it updates accordingly to the environment in the same time step. We’ll discuss more about that in a later section
*   Conclusion (1) guarantees $\alpha_C$ \- the autonomous dynamics on the controller - is well defined and unique. Conclusion (2) states that $\alpha_C$ simulates $\alpha_E$ and Conclusion (3) says this simulation is faithful.

Comparing the less general version of the theorem in the first post with this version, 

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/485696bc47feae5c99040a548d02b76a162d8ddb391118ab.png)

On the left, the setup of the first post. On the right, the setup of the second post - we're calling $\tilde{X}_E := X_E$, since generally $X_E$ may not be a subset of $X$

*   This theorem does apply for systems where $\gamma$ is not a bijection. In fact, $\gamma$ is injective on $X_E$ and surjective on $K$. It also seems useful to model a wider range of systems.
*   Our previous version of the theorem is a particular case of this, with $X_E = X = K$ and $\alpha_E = \alpha$.
*   $\tilde{X}_E \subseteq K$ and $X_C \subseteq \gamma(K)$ are the conditions ensuring all the states involved in the internal modeling are good states. Thus, this theorem is supposed to apply after the regulation has "converged" in some sense (such as $t \to \infty$).

Thus, modeling here means tracking faithfully.

Example
=======

Consider an unidimensional circular grid of size $N$ (i.e, a row of $N$ squares such that the first square is connected to the last square) with a moving target and an agent that has the goal to pursue that target. The target and the agent can move left and right and are always inside some square of the grid. 

The squares of our grid will be the set $\mathcal{N} := \{0, \ldots, N-1\}$.

We want the world to be able to describe the agent and the moving target, each moving in this $N$ sized grid, so we will consider a state of the world as an ordered pair $(i,j)$ with $i,j \in \{0,\ldots, N-1\} = \mathcal{N}$ and so we'll define the world as $X := \mathcal{N} \times \mathcal{N}$. Here, the first coordinate of the pair represents the position of the moving target and the second coordinate represents the position of the agent.

We will consider the environment to be the position of the moving target on the grid, thus $X_E := \mathcal{N}$.

We assume the moving target always moves one square to the right. That is, $\alpha_E : X_E \to X_E$ is given by $\alpha_E(i) := i+1 \mod N$, where the $\mod N$ is to account for the fact that the world is circular.

We'll define the dynamics of the world $\alpha : X \to X$ by $\alpha(i,j) = (i+1 \mod N, j+1 \mod N)$ if $i=j$ and $\alpha(i,j) = (i+1 \mod N, j \mod N)$ if $i \neq j$

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/adc89eb97816437c48a65c285545d44c4903078bc78b0d98.png)

Consider $j_E : X_E \to X$ defined by $j_E(x_E) := (x_E, x_E)$. Then, $\tilde{X}_E :=j_E(X_E) \subseteq X$ and$j_E \circ \alpha_E(x_E) = j_E(\alpha_E(x_E)) = j_E(x_E+1\mod N) = (x_E+1 \mod N, x_E+1 \mod N) = \alpha((x_E,x_E)) = \alpha(j_E(x_E)) = \alpha \circ j_E$

In other words, let $\alpha_{\tilde{X}_E} := j_E \circ \alpha_E = \alpha \circ j_E = \alpha \vert_{\tilde{X}_E}$ (since $j_E$ is injective). Thus we can use the internal model theorem with $\tilde{X}_E=j_E(X_E)$ as environment instead of $X_E$ directly.

For the agent, 

*   $X_C$ should represent the states the agent can be in, hence $X_C := \{0, \ldots, N-1\}$
*   $\gamma : X \to X_C$ defined by
    *   Clearly, $\gamma$ is a surjection: given $j \in X_C, \exists x = (i,j) \in X$ s.t. $\gamma(x) = x_C, \forall i \in \{0, \ldots, N-1\}$
*   We want our agent to pursue the moving target, so we will define $K : = \{(i,j) \in X| i = j\}$

This setup satisfy our hypothesis:

*   $\tilde{X}_E = \{(x_E,x_E) \in X| x_E \in X_E\} \subseteq K = \{(i,j) \in X|i=j\}$ and $\alpha_{\tilde{X}_E} = \alpha \vert_{\tilde{X}_E}$
*   $\gamma(K) = \mathcal{N} = X_C$
*   $\ker \gamma \vert_K \leq \ker \gamma \circ \alpha \vert_K$.
    *   Suppose $x,y \in K$ such that $(x,y) \in \ker \gamma  \iff \gamma(x) = \gamma(y)$. Since $x,y \in K, x =(i,i)$ and $y = (j,j)$. Then, $i = \gamma(x) = \gamma(y) = j \implies i = j$. Now, $\gamma \circ \alpha(i,i) = \gamma \circ \alpha(j,j)$ since $i = j$. Thus, $(x,y) \in \ker \gamma \circ \alpha$.
*   $\tilde{X}_E$ is $\alpha$-invariant.
    *   Let $(x_E, x_E) \in \tilde{X}_E$, then $\alpha((x_E,x_E)) = (x_E+1\mod N, x_E+1 \mod N) = j_E(x_E+1)$ if $x_E+1 \leq N-1$ and $=j_E(0) \text{ if } x_E + 1 = N$. That is, $\alpha((x_E, x_E)) = j_E(x_E') \in \tilde{X}_E$ for some $x_E' \in X_E$.   
*   $\inf \ker \gamma \circ \alpha^n \vert_{\tilde{X}_E} = \bot$
    *   This follows from feedback and regulation and $\alpha$-invariance of $\tilde{X}_E$: Since feedback holds and $\tilde{X}_E \subseteq K$, then $\ker \gamma \vert_{\tilde{X}_E} \leq \ker \gamma \circ \alpha \vert_{\tilde{X}_E}$. Because $\tilde{X}_E$ is $\alpha$-invariant, one can prove the generalized feedback lemma for the sequence $\ker \gamma \circ \alpha^n \vert_{\tilde{X}_E}$. Then $\inf \ker \gamma \circ \alpha^n \vert_{\tilde{X}_E} = \bot$

Since the theorem's assumptions are all true, we already know that there's a unique $\alpha_C$ determined by $\alpha_C \circ \gamma = \gamma \circ \alpha$.

*   That is, $x_C = \gamma(x) = \gamma((i,j)) = j$, $\alpha_C(x_C) = \gamma(\alpha(x)) = \gamma(\alpha(i,j))$ $=$ $j \mod N$ if $i \neq j$ and $= j+1 \mod N$ if $i=j$. 

Then the pair $X_M = \gamma \vert_{\tilde{X}_E}(\tilde{X}_E)$ and $\alpha_C \vert_{X_M}$ is our internal model.

Discussion and further work
===========================

We presented the Internal Model Theorem statement, which basically states that, under a setup of an external system passing signals to an autonomous internal system syuch that these signals satisfy observability, then: **feedback structure and regulation implies the controller necessarily have an internal model of the external system.**

Some critiques:

*   As we discuss in the [first post](https://www.lesswrong.com/posts/g4avk6cLHomHjcFkx/distilling-the-internal-model-principle), the update rules involved are all deterministic. Thus, the theorem can't represent non-deterministic scenarios such as taking decisions under uncertainty
    *   Note, though, that the theorem is supposed to model regulation after some sort of equilibria or convergence. I expect intuitively many systems in these situations have at least an approximately deterministic behavior
*   It's **really hard to come up with non-trivial examples for the theorem**. This difficulty is particularly present when trying to come up with examples that satisfy Feedback and Observability together
    *   In fact, I'd be glad to see non-trivial examples of this theorem. If you know or construct one, please write in the comments or send it

IMP as a selection theorem
--------------------------

A selection theorem is a theorem that states something in the lines of "this is the *type* of agents we expect to find in environments with this specific type of selection pressure. Currently, the theorem doesn't say much because the controller is not properly an agent. It's an autonomous system, but it doesn't act on the world. Phrased as a selection theorem wannabe, the IMP states that in environments where the controller is autonomous in good states, the controller acts as/tracks the environment internal model. 

We can think of extending the theorem in two directions

*    “Systems that approximately regulate their internal state have approximate internal models”, we would get a better version of a selection theorem.
    *   I’d expect this extended theorem to work for a wider range of real world systems.
    *   This still wouldn't make the controller look more agentic because it still wouldn't properly act on the world.
*   "The controller acts upon the environment but it has an internal model of the environment."
    *   This would make the controller more agentic.

The first point above would make the theorem more useful to real systems, while the last would make the controller feel more like an agent. I'd think those two extensions would provide a selection theorem.

Relevance to Agent Structure problem
------------------------------------

The [agent-like structure problem](https://www.lesswrong.com/posts/moi3cFY2wpeKGu9TT/clarifying-the-agent-like-structure-problem) is the problem of determining if, given a policy that robustly optimizes far away regions of the space into small chunks of the state space, does this policy has agent structure (by agent structure we mean informally having an internal model and a search process)? [Another way](https://www.lesswrong.com/posts/osxNg6yBCJ4ur9hpi/does-agent-like-behavior-imply-agent-like-architecture) to phrase this questions is "under which types of environments is the implication above true?"

[Alex](https://www.lesswrong.com/posts/oxsBpx9v3bgxraiPj/towards-a-formalization-of-the-agent-structure-problem) gave a loose formalism to answer this question, making some notions more precise:

> "If we take some class of behaving things and apply a filter for agent-like *behavior*, do we end up selecting things with agent-like *architecture* (or *structure*)? Under *which* conditions does agent-like behavior imply agent-like structure?"

This loose formalism consist of a policy and an environment. The policy receives an observation from the environment, updates its internal state and acts on the environment, changing its state. Then the environment sends a new observation to the policy and so on, in discrete time-steps. The policy is, thus, a function that sends each policy state and observation to a policy state. Analogously, the environment sends each environment state and action to an environment state.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/f79ce26576ce829aaa829f8b12dafad4c9ada18eae29f27b.webp)

We can define a class of different policies and different environments. 

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/b2232822bfdbe03f0c45fdc11eea2f67da3a32274aea181c.webp)

In Alex's words "Here we "run" the policy $\pi_i$ in each environment, producing a collection of trajectories of states. Each state has some measure of goodness or badness, indicated here by the subscript and color. The policy does well ("optimizes") in some environment, and poorly in others."

The idea of the formalism is being able to assess a function that associates to each policy in the policy class a number in $[0,1]$, thought of as the "degree of agent structure". We expect policies that perform well in a wide range of environments are highly “agentic”. Based on the performance of a policy in a wide range of environments, we want to be able to tell the degree of agent structure this policy has. 

In Alex's words, 

> “One result we might wish to have is that if you tell me how many parameters are in your ML model, how long you ran it for, and what its performance was, then I could tell you the minimum amount of agent structure it must have”.

The important idea here is that we expect to be able to define a function $\epsilon$ depending on the parameters, training, performance or other relevant variable such that it’s always true that the structure of a given policy is $\geq 1 - \epsilon$. Since we want the structure function to be between $0$ and $1$, $\epsilon = 1$ would always make this statement true, but we want this function to be zero in the limit, in some sense of limit.

More concretely, in the agent structure setup, we want to be able to:

1.  Have a measure of performance of a given policy in a wide range of environments.
2.  Filter the policy class (because a lookup table containing “optimal” moves for each environment in the environment class would have a very good performance, but we would expect a lookup table would be the policy with less agent structure amongst all policies).
3.  Define $\epsilon$ appropriately such that its limit is zero in some sense of asymptotics.

The IMP setup fails these conditions because

1.  It doesn’t encompass a measure of performance of different policies. Actually, we’ve already proved the dynamics of the internal system is unique under IMP conditions, so we would actually have only one policy.
2.  The IMP’s setup doesn’t seem to consider a policy acting over an environment. The internal system (the analogous of policy here) can be influenced by the environment (via $\gamma$), but can’t influence the environment. In a self-driving car analogy, it’s like the car being in position $x=10$ or $x=20$, moving or not corresponds to same environment states. 

We wish to extend the IMP in two different ways, addressing those two problems:

1.  Modify the IMP to show that systems which *approximately* regulate their internal state must have *approximate* models of their environments.
    1.  This could give us a notion of performance and different policies.
2.  Rework the IMP so that it applies to controllers regulating the external environment (rather than regulating their internal state).
    1.  This would solve the fact that in current IMP, the internal system doesn’t interact with the environment.

We expect if one can extend the theorem to these two different situations, it might give some insight on the agent structure problem.

[^0j5c5ysh2yvm]: Supervisory Control of Discrete-Event Systems, (2019) Cai & Wonham as section 1.5.