# Price’s equation for neural networks

Price’s equation is a fundamental equation in genetics, which can be used to predict how traits will change due to evolution. It can be phrased in many ways, but for the current post I will use the following simplified continuous-time variant:

Here, represents some genetic trait, represents the fitness of the organism, represents the genes of an organism, and represents the genetic covariance between the trait and the fitness. Usually people only use the part of the equation^{[1]}, but I’ve written out the definition

because that will make the analogy to neural networks easier to see.

## Neural network training and Price’s equation

Suppose we train a neural network’s weights using the following equation, where represents the loss for the network:

In that case, if we have some property of the network (e.g. could represent how a classifier labels an image, or how an agent acts in a specific situation, or similar), then we can derive an equation for ’s evolution over time:

Similar to how we have a concept of genetic covariance to represent the covariance linked to genes, we should probably also introduce a covariance concept linked to neural network weights, to make it cleaner to talk about. I’ll call that (short for neural tangent covariance), defined as:

Furthermore, to make it closer to being analogous, we might replace with , yielding the following equation for predicting the evolution of any property with training under gradient descent:

This makes a bunch of idealistic assumptions about the training process, e.g. that we have an exact measure of the full gradient. It might be worth relaxing the math to more realistic assumptions, and check how much still applies. But for now, let’s just charge ahead with the unrealistic assumptions.

## Covariance niceties

Covariances play nicely with linear causal effects. If and are linear transformations, then .

For instance, suppose you have a reinforcement learner that has learned to drink juice when close to it. Suppose further that now the main determinant for whether it gets reward is whether it approaches juice when it sees juice. We might formalize that effect as , where is the reward given to the agent, is the frequency at which it sees juice that it can approach, and is its likelihood of approaching juice if it sees it.

We can then compute: .

is a special quantity which we could call the neural tangent variance . It represents the degree to which is sensitive to the neural network parameters. For common situations, this may be dependent on the structure of the network, but also more directly on the nature and value of .

For instance, if is the expectation of a binary variable with a probability for being 1, then I bet there is probably going to be a Bernoulli distribution aspect to it, such that is approximately proportional to , but likely with a scale factor that depends on the network architecture or parameters, rather than being entirely equal to it.

In particular, this means that if is very low (in the juice example, if it is exceedingly rare for the agent to approach juice it sees), then will also be very low, and this will make low and therefore also make low.

- ^
And usually people also put in other terms too to account for various distortions.

- 26 Oct 2023 0:01 UTC; 4 points) 's comment on Buck’s Shortform by (
- 21 Dec 2022 13:10 UTC; 2 points) 's comment on Positive values seem more robust and lasting than prohibitions by (

I’ve been meaning to write for a while now:

I’ve realized that since the derivative is infinitesimal, we can actually strengthen the covariance niceties a lot. If f and g are arbitrary functions, then I believe that:

ntcov(f(x),g(y))=Jf(x)ntcov(x,y)Jg(y)⊤

I really like this post. Can you expand your intuitions on

Sure!

So let’s start with a basic example, an agent that has two actions, “don’t” and “do”. Suppose it has an output neuron that contains the logits for what action to take, and for simplicity’s sake (will address this in the end of the post) let’s assume that this output neuron is controlled by a single weight w which represents its bias. So this means that the p variable described in the OP expands into: p=P(a=do)=sigmoid(w).

We can then compute ∇wp(w)=p(w)(1−p(w)). And, hmm, this actually implies that ntvar(p)=p2(1−p)2, rather than the p(1−p) that my intuition suggested, I think? The difference is basically that p2(1−p)2 is flatter than p(1−p), especially in the tails where the former quadratically goes to 0 while the latter linearly goes to 0.

One thing I would wonder is what happens during training, if we e.g. use policy gradients and give a reward of 1 for do and a reward of −1 for don’t. The update rule for policy gradients is basically r∇wlogp(w), which according to Wolfram Alpha expands into 2(1+e−w)(1+ew), and which we can further simplify to 2p(1−p). But we would have to square it to get ntvar(r), so I guess the same point applies here as to before. 🤷

Anyway, obviously this is massively simplified because we are assuming a trivial neural network. In a nontrivial one, I think the principle would be the same, due to the chain rule which gives you a factor of p(1−p) onto whatever gradients exist before the final output neuron.

Actually upon further thought for something like policy gradients, in the limit where the probability p is close to 0, then ntvar(a) would probably be more like O(p2)? Because you get a factor of p from the probability, and then an additional factor of p(1−p)=O(p) from the derivative of sigmoid/softmax, which adds up to it being O(p2).