# Some Notes on the mathematics of Toy Autoencoding Problems

Anthropic's recent mechanistic interpretability paper, [Toy Models of Superposition](https://transformer-circuits.pub/2022/toy_model/index.html), helps to demonstrate the conceptual richness of very small feedforward neural networks. Even when being trained on synthetic, hand-coded data to reconstruct a very straightforward function (the identity map), there appears to be non-trivial mathematics at play and the analysis of these small networks seems to providing an interesting playground for mechanistic interpretability.   
  
While trying to understand their work and train my own toy models, I ended up making various notes on the underlying mathematics. This post is a slightly neatened-up version of those notes, but is still quite rough and un-edited and is a far-from-optimal presentation of the material. In particular, these notes may contain errors, which are my responsibility.

1\. Directly Analyzing the Critical Points of a Linear Toy Model
----------------------------------------------------------------

Throughout we will be considering feedforward neural networks with one hidden layer. The input and output layers will be of the same size and the hidden layer is smaller. We will only be considering the autoencoding problem, which means that our networks are being trained to reconstruct the data. The first couple of subsections here are largely taken from the Appendix to the paper "[Neural networks and principal component analysis: Learning from examples without local minima](http://www.vision.jhu.edu/teaching/learning/deeplearning19/assets/Baldi_Hornik-89.pdf)." by Pierre Baldi and Kurt Hornik. (Neural networks 2.1 (1989): 53-58).  
  
Consider to begin with a completely liner model., i.e. one without any activation functions or biases. Suppose the input and output layers have $D$ neurons and that the middle layer has $d < D$ neurons.  This means that the function that the model is implementing is of the form $x \mapsto ABx$, where $x \in \mathbb{R}^D$, $B$ is a $d\times D$ matrix, and $A$ is a $D \times d$ matrix. That is, the matrix $B$ contains the weights of the connections between the input layer and the hidden layer, and the matrix $A$ is the weights of the connections between the hidden layer and the output layer. It is important to realise that even though - for a given set of weights - the function that is being implemented here is linear, the mathematics of this model and the dynamics of the training are not completely linear.

The error on a given input $x$ will be measured by $\bigl\| x - ABx\bigr\|^2$ and on the data set $\{x^t\}_{t=1}^T$, the total loss is 

$$
\mathcal{L} = \mathcal{L}\bigl(\mathrm{A},\mathrm{B},\{x^t\}_{t=1}^T\bigr) :=\sum_{t=1}^T \bigl\| x^t - \mathrm{AB}x^t\bigr\|^2 = \sum_{t=1}^T\sum_{i=1}^D \Bigl(x_i^t - \sum_{j,k=1}^D a_{ij}b_{jk}x_k^t\Bigr)^2
$$

Define $\Sigma$ to be the matrix whose $(i,j)^{th}$ entry $\sigma_{ij}$ is given by 

$$
\sigma_{ij} =  \sum_{t=1}^T x_i^tx_j^t.
$$

Clearly this matrix is symmetric.    
  
**Assumption.** We will assume that the data is such that a) $\Sigma$ is invertible and b) $\Sigma$ has distinct eigenvalues.   
  
Let $\lambda_1 > \dots > \lambda_D$ be the eigenvalues of $\Sigma$.

### 1.1 The Global Minimum

  
**Proposition 1.** (Characterization of Critical Points)  *Fix the dataset and consider *$\mathcal{L}$* to be a function of the two matrix variables *$\mathrm{A}$* and *$\mathrm{B}$*. For any critical point *$(A,B)$* of *$\mathcal{L}$*, there is a subset *$\mathcal{I} \subset \{1,\dots,D\}$* of size *$d$*for which *

1.  $AB$* is an orthogonal projection onto a *$d$*-dimensional subspace spanned by orthonormal eigenvectors of *$\Sigma$* corresponding to the eigenvalues *$\{\lambda_i\}_{i \in \mathcal{I}}$*; and*
2.  $\mathcal{L}(A,B) = \mathrm{tr}\, \Sigma - \sum_{i \in \mathcal{I}} \lambda_i = \sum_{i \notin \mathcal{I}}\lambda_i$*.*

**Corollary 2.** (Characterization of the Minimum)  *The loss has a unique minimum value that is attained when *$\mathcal{I} = \{1,\dots,d\}$*, which corresponds to the situation when *$AB$*  is an orthogonal projection onto the *$d$*-dimensional subspace spanned by the eigendirections of *$\Sigma$* that have the largest eigenvalues. *

**Remarks.** We won't try to spell out all of the various connections to other closely related things, but for those who want some more keywords to go away and investigate further, we just remark that the minimization problem being studied here is about finding a low-rank approximation to identity and is closely related to Principal Component Analysis. See also the Eckart–Young–Mirsky Theorem.

We begin by directly differentiating $\mathcal{L}$ with respect to the entries of $A$ and $B$. Using summation convention on repeated indices, we first take the derivative with respect to $b_{j'k'} :$

$$
\begin{align} \frac{\partial \mathcal{L}}{\partial b_{j'k'}} &= \sum_{t=1}^T\sum_{i=1}^D-2 \Bigl( x_i^t - a_{ij}b_{jk}x_k^t\Bigr)a_{il}\delta_{lj'}\delta_{qk'}x_q^t \ &= -2\sum_{t=1}^T\Bigl( x_i^ta_{ij'}x_{k'}^t - a_{ij}b_{jk}x_k^ta_{ij'}x_{k'}^t\Bigr) \end{align}
$$

Setting this equal to zero and interpreting this equation for all $j' = 1,\dots,d$ and $k' = 1,\dots,D$ gives us that 

$$
\begin{equation} A^T\Sigma = A^TAB\Sigma. \tag{1} \end{equation}
$$

Then, separately, we differentiate $\mathcal{L}$ with respect to $a_{i'j'}$ : 

$$
\begin{align} \frac{\partial \mathcal{L}}{\partial a_{i'j'}} &=\sum_{t=1}^T\sum_{i=1}^D -2\Bigl(x_i^t - a_{ij}b_{jk}x_k^t\Bigr)\delta_{ii'}\delta_{pj'}b_{pq}x_q^t \&= -2\sum_{t=1}^T\Bigl(x_{i'}^tb_{j'q}x_q^t - a_{i'j}b_{jk}x_k^tb_{j'q}x_q^t\Bigr).\end{align}
$$

Setting this equation equal to zero for every $i'= 1,\dots,D$ and $j'=1,\dots , d$ we have that: 

$$
\begin{align} \Sigma B^T = AB\Sigma B^T. \tag{2}\end{align}
$$

Thus 

$$
\begin{align}   \tag{3} \nabla \mathcal{L}(A,B) = 0 \quad \Longleftrightarrow \quad \begin{cases} A^T\Sigma &= A^TAB\Sigma \ \Sigma B^T &= AB\Sigma B^T. \end{cases}\end{align}
$$

Since we have assumed that $\Sigma$ is invertible, the first equation immediately implies that $A^T = A^TAB$. If we assume in addition that $A$ has full rank (a reasonable assumption in any case of practical interest), then $A^TA$ is invertible and we have that 

$$
\begin{align}   \tag{4} (A^TA)^{-1}A^T=B,\end{align}
$$

which in turn implies that 

$$
\begin{align} \tag{5} AB = A(A^TA)^{-1}A^T = P_A,\end{align}
$$

where we have written $P_A$ to denote the orthogonal projection on to the column space of $A$.  

**Claim.** We next claim that $\Sigma$ commutes with $P_A$.

**Proof of claim.** Plugging (5) into (3), we have:

$$
\begin{align} \tag{6}\Sigma B^T = P_A \Sigma B^T.\end{align}
$$

Then, right-multiply by $A^T$ and use the fact that $P_A^T = P_A$ to get:

$$
\begin{align} \tag{7}\Sigma P_A = P_A \Sigma P_A.\end{align}
$$

The right-hand side is manifestly a symmetric matrix, so we deduce that $\Sigma P_A$ is symmetric. If the product of two symmetric matrices is symmetric then they commute, so this indeed shows that $\Sigma$ commutes with $P_A$ and completes the proof of the claim.

Now let $U$ be the orthogonal matrix which diagonalizes $\Sigma$,  i.e. the matrix for which 

$$
\begin{align} \tag{8}\Sigma = U\Lambda U^T,\end{align}
$$

where $\Lambda$ is a diagonal matrix with entries $\lambda_1 > \lambda_2 > \dots > \lambda_D > 0$. 

**Claim.** We next claim that $P_A =U P_{U^TA} U^T$ and that $P_{U^TA}$ is diagonal.  

**Proof of Claim.** Firstly, using the standard formula for orthogonal projections, we have 

$$
P_{U^TA} = U^TA\bigl(A^TUU^TA)^{-1}A^TU = U^TA(A^TA)^{-1}A^TU = U^TP_AU,
$$

 which implies that

$$
\begin{align} \tag{9}P_A = UP_{U^TA}U^T.\end{align}
$$

To show that $P_{U^TA}$ is diagonal, we show that it commutes with the diagonal matrix $\Lambda$ (any matrix that commutes with a diagonal matrix must itself be diagonal). Starting from $P_{U^TA}\Lambda$, we first insert the identity matrix in the form $U^TU$, and then use (8) and (9) thus: 

$$
P_{U^TA}\Lambda = U^TUP_{U^TA}U^TU\Lambda U^TU = U^TP_A\Sigma U
$$

Then recall that we have already established that $P_A$ commutes with $\Sigma$. So we can swap them and then performing the same trick in reverse: 

$$
U^TP_A\Sigma U = U^T\Sigma P_A U = U^TU\Lambda U^T U P_{U^TA} U^T U = \Lambda P_{U^TA}.
$$

This shows that $P_{U^TA}$ commutes with $\Lambda$ and completes the proof of the claim.

So, given that $P_{U^TA}$ is an orthogonal projection of rank $d$ and is diagonal, there exists a set of indices $\mathcal{I} = \{i_1,\dots,i_d\}$ with $1 \leq i_1 < i_2 < \dots < i_d \leq D$ such that the $(i,j)^{th}$ entry of $P_{U^TA}$ is zero if $i \neq j$ and 1 if $i = j \textit{and} i \in \mathcal{I}$. And since $P_A = U P_{U^TA} U^T$, we see that 

$$
\begin{align} \tag{10}P_A = U_{\mathcal{I}} U^T_{\mathcal{I}},\end{align}
$$

where $U_{\mathcal{I}}$ is formed from $U$ by simply setting to zero the $j^{th}$ column if $j \notin \mathcal{I}$. This is manifestly an orthogonal projection onto the span of $\{u_{i_1},\dots,u_{i_d}\}$, where $u_1,u_2,\dots, u_D$ is an orthonormal basis of eigenvectors of $\Sigma$ (and indeed the columns of $U$).  Combining these observations with (5), we have that

$$
\begin{align} \tag{11}AB = P_A = U_{\mathcal{I}} U^T_{\mathcal{I}} = P_{U_{\mathcal{I}}}.\end{align}
$$

This proves the first claim of the proposition.

To prove the second part, write $AB = [p_{ij}]$ and compute thus: 

$$
\begin{align*}\sum_{t=1}^T \Bigl\|x^t - ABx^t\Bigr\|^2 &= \sum_{t=1}^T \sum_{i=1}^D (x_i^t - p_{ij}x_j^t)^2 \&= \sum_{t=1}^T \Bigl(x_i^tx_i^t - 2x_i^tp_{ij}x_j^t + p_{ij}x_j^tp_{ik}x_k^t\Bigr) \&= \mathrm{tr} \Sigma - 2\mathrm{tr}(P_{U_{\mathcal{I}}}\Sigma) + \mathrm{tr}(P_{U_{\mathcal{I}}}\Sigma P_{U_{\mathcal{I}}}^T) \tag{12}.\end{align*}
$$

But we know from (7) and (11) that $P_{U_{\mathcal{I}}}\Sigma P_{U_{\mathcal{I}}} = \Sigma P_{U_{\mathcal{I}}}$ and so this last line is actually just equal to

$$
\mathrm{tr} \Sigma - \mathrm{tr}(P_{U_{\mathcal{I}}} \Sigma).
$$

Focussing on the second term and using (11), then (9) and (8), then cancelling $U^TU=I$, and then - to reach the last line - cyclicly permuting the matrices inside the trace operator to produce another $U^TU$ cancellation, we have:

$$
\begin{align*} \mathrm{tr}(P_{U_{\mathcal{I}}} \Sigma) &=  \mathrm{tr}(P_A\Sigma) \ &= \mathrm{tr}\Bigl(UP_{U^TA}U^TU\Lambda U^T\Bigr) \ &=  \mathrm{tr}\Bigl(UP_{U^TA}\Lambda U^T\Bigr) \ &=  \mathrm{tr}\Bigl(P_{U^TA}\Lambda\Bigr). \end{align*}
$$

The diagonal form of $P_{U^TA}$ means that this final expression is equal to $\sum_{i \in \mathcal{I}} \lambda_i$, meaning that 

$$
\begin{align}\sum_{t=1}^T \Bigl\|x^t - ABx^t\Bigr\|^2  =  \mathrm{tr} \Sigma - \sum_{i\in \mathcal{I}} \lambda_i.\end{align}
$$

Since $\mathrm{tr} \Sigma = \sum_{i=1}^D \lambda_i$ (the trace is always equal to the sum of the eigenvalues), this completes the proof of the proposition. $\Box$

**Remarks.** Equation (10) above tells us that $\mathrm{col}(A) = \mathrm{span}\langle u_{i_1},\dots,u_{i_d} \rangle$, which means that there exists an invertible matrix $C$ with $A = U_{\mathcal{I}}C$. Then, using (4), we compute that 

$$
B = (A^TA)^{-1}A^T = (C^TU_{\mathcal{I}}^TU_{\mathcal{I}}C)^{-1} (U_{\mathcal{I}}C)^T = C^{-1}(C^T)^{-1} C^T U_{\mathcal{I}}^T = C^{-1}U_{\mathcal{I}}^T.
$$

So we have:

$$
\begin{align} \begin{cases}A = U_{\mathcal{I}}C \ B = C^{-1}U_{\mathcal{I}}^T \end{cases} \tag{$\star$} \end{align}
$$

### 1.2 Characterizing Other Critical Points

This subsection is something of an aside, but it is included for completeness.

**Proposition 3.** (Other Critical Points are Saddle Points.) *Fix the dataset and consider *$\mathcal{L}$* to be a function of the two matrix variables *$\mathrm{A}$* and *$\mathrm{B}$*. Every other critical point is a saddle point, i.e. if *$(A,B)$* is a critical point but not equal to the unique minimum, then exist *$\tilde{A}$* and *$\tilde{B}$* which are arbitrarily close to *$A$* and *$B$* respectively and at which a lower loss is achieved. *

**Proof.** Since $(A,B)$ is not the unique global minimum, we know from Corollary 2 that $\mathcal{I} \neq \{1,\dots,d\}$. This means that there are distinct indices $j$ and $k$ for which $j \in \mathcal{I}$, $k \notin \mathcal{I}$ and $k < j$. In particular, bear in mind that $\lambda_k > \lambda_j$. 

Now, given any $\epsilon > 0$, put 

$$
\tilde{u}_j := \frac{u_j + \epsilon u_k}{\sqrt{1+\epsilon^2}}.
$$

And let us form the new matrix $\tilde{U}_{\mathcal{I}}$ by starting with $U_{\mathcal{I}}$ and replacing the column $u_j$ with $\tilde{u}_j$. Write 

$$
\begin{align} \tilde{A} &= \tilde{U}_{\mathcal{I}}C \tag{13}\ \tilde{B} &= C^{-1}\tilde{U}^T_{\mathcal{I}}   \tag{14} \end{align}
$$

We want to calculate the loss of the model at $(\tilde{A},\tilde{B})$. We ought to bear in mind that it is not a critical point, so we cannot assume the intermediate results in the proof of Proposition 2, but it turns out that the bits that are most useful for this computation rely only on algebra and (13), (14). We start from the equivalent of line (11) which is that $\tilde{A}\tilde{B}  = \tilde{U}_{\mathcal{I}}\tilde{U}^T_{\mathcal{I}} = P_{\tilde{U}_{\mathcal{I}}},$  which implies that $\tilde{A}\tilde{B} = P_{\tilde{A}}$. And so just as in (12) above, we have 

$$
\begin{align} \sum_{t=1}^T \Bigl\|x^t - \tilde{A}\tilde{B}x^t\Bigr\|^2 &=  \mathrm{tr} \Sigma - 2\mathrm{tr}(P_{\tilde{U}_{\mathcal{I}}}\Sigma) + \mathrm{tr}(P_{\tilde{U}_{\mathcal{I}}}\Sigma P_{\tilde{U}_{\mathcal{I}}}^T). \tag{15} \end{align}
$$

Now, looking at the final term on the right-hand side, we have $P_{\tilde{U}_{\mathcal{I}}}\Sigma P^T_{\tilde{U}_{\mathcal{I}}} = P_\tilde{A}\Sigma P_{\tilde{A}}$ and (by cycling permutation) $\mathrm{tr}(P_{\tilde{A}}\Sigma P_{\tilde{A}}) = \mathrm{tr}(P_{\tilde{A}}\Sigma)$. And since 

$$
P_{U^T\tilde{A}} = U^T\tilde{A}(\tilde{A}^TUU^T\tilde{A})^{-1}\tilde{A}^TU = U^TP_{\tilde{A}}U,
$$

we have:

$$
\begin{align} \mathrm{tr}(P_{\tilde{A}}\Sigma) = \mathrm{tr}(UP_{U^T\tilde{A}}U^T\Sigma) = \mathrm{tr}(P_{U^T\tilde{A}}\Lambda). \tag{16}\end{align}
$$

We also use $\mathrm{tr}(P_{\tilde{U}_{\mathcal{I}}}\Sigma) = \mathrm{tr}(P_{\tilde{A}}\Sigma)$ and (16) on the second term on the right-hand side of (15) to ultimately arrive at:

$$
\begin{align} \sum_{t=1}^T \Bigl\|x^t - \tilde{A}\tilde{B}x^t\Bigr\|^2 &=  \mathrm{tr} \Sigma - \mathrm{tr}(P_{U^T\tilde{A}}\Lambda). \tag{17} \end{align}
$$

So we are interested in computing the diagonal elements of $P_{U^T\tilde{A}}$. Fix $i \in \{1,\dots,D\}$. The $i^{th}$ diagonal entry is given by: 

$$
e_i^T P_{U^T\tilde{A}} e_i = e_i^TU^T P_{\tilde{A}}Ue_i = u_i^T\tilde{U}_{\mathcal{I}}\tilde{U}^T_{\mathcal{I}}u_i.
$$

This can be computed directly from the definition of $\tilde{U}_{\mathcal{I}}$ to give that the $i^{th}$ entry on the diagonal is equal to

$$
\begin{align} \begin{cases} 0 & \text{if} i \notin \mathcal{I} \cup \{k\} \ 1 & \text{if} i \in \mathcal{I}\setminus\{j\} \ 1/(1+\epsilon^2) & \text{if} i = j \ \epsilon^2/(1+\epsilon^2) & \text{if} i = k.  \end{cases} \tag{18}\end{align}
$$

Therefore 

$$
\begin{align} \sum_{t=1}^T \Bigl\|x^t - \tilde{A}\tilde{B}x^t\Bigr\|^2 &=  \mathrm{tr}\Sigma - \Bigl[ \sum_{i \in \mathcal{I}\setminus\{j\}}\lambda_i + \lambda_j/(1+\epsilon^2) + \epsilon^2\lambda_k/(1+\epsilon^2)\Bigr]\ &= \mathrm{tr}\Sigma - \sum_{i \in \mathcal{I}}\lambda_i - \frac{\epsilon^2}{(1+\epsilon^2)}(\lambda_k - \lambda_j) \ &= \sum_{t=1}^T \Bigl\|x^t - ABx^t\Bigr\|^2 - \frac{\epsilon^2}{(1+\epsilon^2)}(\lambda_k - \lambda_j). \end{align}
$$

Since $\lambda_k > \lambda_j$ this shows that in an arbitrarily small neighbourhood of the critical point $(A,B)$ we can find a point $(\tilde{A},\tilde{B})$ where smaller loss is achieved. We will not bother doing so here, but one can also check that $(A,B)$ is not a local *maxima* by using the fact that for fixed (full rank) $A$, the function $z \mapsto \|x- Az\|^2$ is convex. $\Box$

2\. Sparse Data, Weight Tying, and Gradients
--------------------------------------------

Abstractly analyzing critical points is not at all the same as training real models. In this section we start to think about data and the optimization process.

### 2.1 Sparse Synthetic Data

Here we describe the kind of training data used in Anthropic's toy experiments

Fix a number $S \in [0,1]$. This parameter is the *sparsity* of the data. We will typically be most interested in the case where $S$ is close to 1. 

Let $\{B^t_i\}_{t=1}^{\infty}{}_{i=1}^D$ be an independent and identically distributed family of Bernoulli random variables with parameter $(1-S)$. And let $\{U^t_i\}_{t=1}^{\infty}{}_{i=1}^D$ be an IID family of $\text{Uniform}\bigl([0,1]\bigr)$ random variables. Write $X^t_i = B^t_iU^t_i$ and $X^t := (X^t_1,\dots,X^t_D)$. Our datasets $\{x^t\}_{t=1}^T \in \mathbf{R}^D$ will be drawn from the IID family $\{X^t\}_{t=1}^{\infty}$. Notice that

*   Independently, for each data point $x^t \in \mathbb{R}^D$ and for each $i \in \{1,\dots,D\}$, we will have $\mathbf{P}(x^t_i = 0) = S$. 
*   So, the expected number of *non-zero* entries for each data point is $(1-S)D$. To bring this in line with the way people say things like "$k$-sparse", we can say that the data is, on average, $(1-S)D$-sparse.
*   $\mathbf{E}(x_i^t) = \tfrac{1}{2}(1-S)$.

**Remark.** Judging from some of the existing literature on the linear model that we analyze in Section 1 (e.g. "[Exact solutions to the nonlinear dynamics of learning in deep linear neural networks.](https://arxiv.org/abs/1312.6120)" by Andrew M. Saxe, James L. McClelland and Surya Ganguli), it seems like it's tempting to make an assumption/simplification/approximation that $\Sigma = I$. I still don't feel like I understand how justifiable that is - for me this question is a potential 'jumping-off' point for further analysis of the whole problem. Recall that the matrix $\Sigma$ is equal to  $\sum_{t=1}^T x^t \otimes x^t$.  Certainly the probability that an off-diagonal entry of $x^t \otimes x^t$ is equal to zero is $1-(1-S)^2$ whereas for the diagonal entries it is just $S$. And note that $\mathbf{E}(x^t_ix^t_j) = \tfrac{1}{4}(1-S)^2$ if $i\neq j$ and $\mathbf{E}\bigl((x^t_i)^2\bigr) = \tfrac{1}{3}(1-S)$.   But the diagonal entries are still independent and I'm not sure why thinking of them as equal makes sense. 

The data (and the loss) are model two main ideas: Firstly, that the coordinate directions of the input space act as a natural set of features for the data. And secondly, when $S$ is close to 1, the sparsity of the data is supposed to capture the fact that features really do often tend to be sparse in real-world data, i.e. we see that for any given object or any given word/idea that appears in a language, it is the case that *most* images *don't* contain that object and *most* sentences *don't* contain that word or idea. 

### 2.2 Weight Tying and The Gradient Flow

In practice, when we train an autoencoder like this, we do so with *weight tying.* Roughly speaking, this means that we only consider the case where $A = B^T$. Proposition 1 does indeed allow for a global minimum in which $A = B^T$: This is achieved by essentially taking $C = I$ in the equations ($\star$) at the end of Section 1.1, i.e. we have:

$$
\begin{align} A &= U_{\mathcal{I}} \ B &= U_{\mathcal{I}}^T   \end{align}
$$

But note that we don't actually want to try to repeat the analysis of Section 1 on a loss of the form $\sum_t \|x^t - W^TWx^t\|^2$. This would be a higher-order polynomial function of the entries of $W$ and so it's genuinely a different and potentially more complicated functional. The way that weight-tying is done in practice is more similar to saying that we insist *during training* that updates are made that preserve the equality $A=B^T$.

Equations (1) and (2) in subsection 1.1 are obtained as a direct result of differentiating the loss with respect to individual entries of the matrices (or individual 'weights' if we interpret this model as a feedforward neural network without activations). Our computations show that:

$$
\begin{align}   \tag{19} \nabla \mathcal{L}(A,B) = -2\begin{pmatrix}A^T\Sigma - A^TAB\Sigma\\\Sigma B^T - AB\Sigma B^T \end{pmatrix}.\end{align}
$$

In an appropriate continuous time limit, if we set the learning rate to 1, the weights during training evolve according to the differential equations:

$$
\begin{align*}\frac{d}{dt}B &= A^T\bigl(\Sigma - AB\Sigma\bigr) \tag{20}\\\frac{d}{dt}A &= \bigl(\Sigma - AB\Sigma)B^T. \tag{21}\end{align*}
$$

**Remarks.** Notice that there is a certain deliberate sloppiness here: One doesn't really have a fixed matrix $\Sigma$ and then run this gradient flow for all time; the matrix $\Sigma$ is a function of (a batch of) training data. So we need to be careful about any further manipulations or interpretations of these equations. 

Those caveats having been noted, if we additionally add in the weight-tying constraint $A = B^T$ , we get:

$$
\begin{align*}\frac{d}{dt}W &= W\bigl(\Sigma - W^TW\Sigma\bigr). \tag{22}\end{align*}
$$

We can even make the substitution $W = \overline{W}U^T$ to introduce the form:

$$
\begin{align}\frac{d}{dt}\overline{W} = \overline{W}\bigl(I - \overline{W}^T\overline{W}\bigr)\Lambda. \tag{23} \end{align}
$$

 In components (and without summation convention) the equation reads 

$$
\begin{align} \frac{d}{dt}\overline{w}_{ij} = \sum_{k,l=1}^D\overline{w}_{ik}\bigl(\delta_{kl} - \sum_{m=1}^d \overline{w}_{mk}\overline{w}_{ml}\bigr)\delta_{lj}\lambda_j. \tag{24} \end{align}
$$

Let $\{\overline{w}^i\}_{i=1}^D$ denote the set of *columns* of $\overline{W}$ so that (24) can becomes:

$$
\begin{align} \frac{d}{dt}\overline{w}^j = \sum_{k,l=1}^D\bigl(\delta_{kl} - \langle\overline{w}^k,\overline{w}^l\rangle\bigr)\delta_{lj}\lambda_j\overline{w}^k. \tag{25} \end{align}
$$

Expanding the brackets and executing the sum over $l$ gives:

$$
\begin{align} \frac{d}{dt}\overline{w}^j = \sum_{k=1}^D \delta_{kj} \lambda_j \overline{w}^k - \sum_{k=1}^D \langle \overline{w}^k,\overline{w}^j\rangle \lambda_j \overline{w}^k. \tag{26} \end{align}
$$

Then the sum over $k$ further simplifies the first term to give: 

$$
\begin{align} \frac{d}{dt}\overline{w}^j =  \lambda_j \overline{w}^j - \sum_{k=1}^D \langle \overline{w}^k,\overline{w}^j\rangle \lambda_j \overline{w}^k. \tag{27} \end{align}
$$

Finally, just peel off the $k=j$ term from the remaining summation to arrive at the equation 

$$
\begin{align} \frac{d}{dt}\overline{w}^j =  \bigl(1-|\overline{w}^j|^2\bigr)\lambda_j \overline{w}^j - \sum_{k\neq j}^D \langle \overline{w}^k,\overline{w}^j\rangle \lambda_j \overline{w}^k. \tag{28} \end{align}
$$

**Remarks.** (cf.  the previous two Remarks)  *If* we *assume* that $\Sigma = I$, then $W = \overline{W}$ and the equation above arises as gradient descent on the energy functional 

$$
\begin{align}E =\frac{1}{4} \sum_{i=1}^D \lambda\bigl( 1 - |w^{i} |^2 \bigr)^2 + \frac{1}{2}\sum_{i,j : i \neq j} \lambda\Bigl| \langle w^{i},w^{j} \rangle\Bigr|^2.\tag{28} \end{align}
$$

It's plausible that a reasonable line of argument to justify this is that since no particular directions in the data are special, it means that over time, on average, the effects of different eigenvalues of $\Sigma$ just somehow 'average out'. But I don't endorse or understand how that argument would actually go. Regardless, if we just assume this for now, as is explained in the *Anthropic* paper, we can think of the two terms in (28) as being in competition. The first term suggests that model 'wants' to learn the $k^{th}$ feature by arranging $|w^k| = 1$. However, as it tries to does so, it incurs a penalty - given by $\sum_{i \neq k}\lambda \bigl|\langle w^i,w^k\rangle \bigr|^2$ $$ \- that can reasonably be interpreted as the extent to which the hidden representation $w^{k} \in \mathbf{R}^d$ of that feature interferes with its attempts to represent and reconstruct the other features. 

3\. The ReLU Output Model 
--------------------------

### 3.1 The Distribution of the Data and the Integral Loss

Perhaps a better way to try to incorporate information about the distribution of the data into the analysis here is to directly let $\mu$ be the distribution (i.e. in the proper measure-theoretic since) of $X_t$ on $\mathbf{R}^D$ and to consider

$$
\mathcal{L} = \int_{\mathbf{R}^D} \bigl\|x - W^TWx\|^2\; d\mu(x).
$$

In the Anthropic paper and in my own work, we are ultimately more interested in a model with biases and ReLUs at the output layer. 

$$
\mathcal{L} = \int_{\mathbf{R}^D} \bigl\|x - \mathrm{ReLU}\bigl(W^TWx - b\bigr)\bigr\|^2\; d\mu(x)
$$

Performing an analysis anything like that done in Section 1 seems much harder for this model, but perhaps more progress can be made studying the integral above. 

The synthetic data we described in the previous section is all contained in the cube $Q:= [0,1]^D \subset \mathbf{R}^D$ . In the sparse regime i.e. with $S$ close to 1, the vast majority of the data is concentrated around the lower-dimensional skeletons of the cube. For $l=1,\dots,D$, if we write $Q_l$ for the set of points in the cube with only $l$ non-zero entries, i.e.

$$
Q_l := \Big\{ x \in Q : \#\{j : x_j \neq 0\} = l\Bigr\},
$$

then $C$ is the disjoint union  

$$
C = \bigcup_{l=0}^n Q_l
$$

Without a closer analysis of binomial tail bounds I can't immediately tell how well-justified it is to say, ignore $\cup_{l \geq 2}Q_l$ and focus the analysis just on 1-sparse vectors in the dataset. i.e. You might want to say that $\mu\Bigl( \bigcup_{l \geq 2}Q_l \Bigr)$ is sufficiently small such that that region contributes only negligibly to the integral. Then you can start to work with more manageable expressions To my mind this is another concrete potential 'jumping-off' point if one were to do more investigation. In particular, it is in the direction of the observations made in *Toy Models of Superposition* to suggest a link between this problem and 'Thomson Problem'.