# A Robust Natural Latent Over A Mixed Distribution Is Natural Over The Distributions Which Were Mixed

This post walks through the math for a theorem. It’s intended to be a reference post, which we’ll link back to as-needed from future posts. The question which first motivated this theorem for us was: “Redness of a marker seems like maybe a natural latent over a bunch of parts of the marker, and redness of a car seems like maybe a natural latent over a bunch of parts of the car, but what makes redness of the marker ‘the same as’ redness of the car? How are they both instances of one natural thing, i.e. redness? (or ‘color’?)”. But we’re not going to explain in this post how the math might connect to that use-case; this post is just the math.

Suppose we have multiple distributions $P^1, …, P^k$ over the same random variables $X_1, …, X_n$. (Speaking somewhat more precisely: the distributions are over the same set, and an element of that set is represented by values $(x_1, …, x_n)$.) We take a mixture of the distributions: $P[X] := \sum_j \alpha_j P^j[X]$, where $\sum_j \alpha_j = 1$ and $\alpha$ is nonnegative. Then our theorem says: if an approximate natural latent exists over $P[X]$, and that latent is robustly natural under changing the mixture weights $\alpha$, then the same latent is approximately natural over $P^j[X]$ for all $j$.

Mathematically: the natural latent over $P[X]$ is defined by $(x, \lambda \mapsto P[\Lambda=\lambda | X=x])$, and naturality means that the distribution $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] P[X=x])$ satisfies the [naturality conditions](https://www.lesswrong.com/posts/dWQWzGCSFj6GTZHz7/natural-latents-the-math) (mediation and redundancy).The theorem says that, if the joint distribution $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] \sum_j \alpha_j P^j[X=x])$ satisfies the naturality conditions *robustly* with respect to changes in $\alpha$, then $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] P^j[X=x])$ satisfies the naturality conditions for all $j$. “Robustness” here can be interpreted in multiple ways - we’ll cover two here, one for which the theorem is trivial and another more substantive, but we expect there are probably more notions of “robustness” which also make the theorem work.

Trivial Version
---------------

First notion of robustness: the joint distribution $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] \sum_j \alpha_j P^j[X=x])$ satisfies the naturality conditions to within $\epsilon$ for all values of $\alpha$ (subject to $\sum_j \alpha_j = 1$ and $\alpha$ nonnegative).

Then: the joint distribution $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] \sum_j \alpha_j P^j[X=x])$ satisfies the naturality conditions to within $\epsilon$ specifically for $\alpha_j = \delta_{jk}$, i.e. $\alpha$ which is 0 in all entries except a 1 in entry $k$. In that case, the joint distribution is $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] P^k[X=x])$, therefore $\Lambda$ is natural over $P^k$. Invoke for each k, and the theorem is proven.

... but that's just abusing an overly-strong notion of robustness. Let's do a more interesting one.

Nontrivial Version
------------------

Second notion of robustness:  the joint distribution $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] \sum_j \alpha_j P^j[X=x])$ satisfies the naturality conditions to within $\epsilon$, and the gradient of the approximation error with respect to (allowed) changes in $\alpha$ is (locally) zero.

We need to prove that the joint distributions $(x, \lambda \mapsto P[\Lambda=\lambda | X=x] P^j[X=x])$ satisfy both the mediation and redundancy conditions for each $j$. We’ll start with redundancy, because it’s simpler.

### Redundancy

We can express the approximation error of the redundancy condition with respect to $X_i$ under the mixed distribution as

$D_{KL}(P[\Lambda, X] || P[X] P[\Lambda | X_i]) = E_X[D_{KL}(P[\Lambda|X] || P[\Lambda |X_i])]$

where, recall, $P[\Lambda, X] := P[\Lambda|X] \sum_j \alpha_j P^j[X]$.

We can rewrite that approximation error as:

$E_X[D_{KL}(P[\Lambda|X] || P[\Lambda |X_i])]$

$= \sum_j \alpha_j P^j[X] D_{KL}(P[\Lambda|X] || P[\Lambda |X_i])$

$= \sum_j \alpha_j E^j_X[D_{KL}(P[\Lambda|X] || P[\Lambda |X_i])]$

Note that $P^j[\Lambda|X] = P[\Lambda|X]$ is the same under all the distributions (by definition), so:

$= \sum_j \alpha_j D_{KL}(P^j[\Lambda, X] || P[\Lambda |X_i] P^j[X])$

and by [factorization transfer](https://www.lesswrong.com/posts/XHtygebvHoJSSeNPP/some-rules-for-an-algebra-of-bayes-nets#Factorization_Transfer_Rule):

$\geq \sum_j \alpha_j D_{KL}(P^j[\Lambda, X] || P^j[\Lambda |X_i] P^j[X])$

In other words: if $\epsilon^j_i$ is the redundancy error with respect to $X_i$ under distribution $j$, and $\epsilon_i$ is the redundancy error with respect to $X_i$ under the mixed distribution $P$, then

$\epsilon_i \geq \sum_j \alpha_j \epsilon^j_i$

The redundancy error of the mixed distribution is at least the weighted average of the redundancy errors of the individual distributions.

Since the $\alpha_j \epsilon^j_i$ terms are nonnegative, that also means

$\epsilon^j_i \leq \frac{1}{\alpha_j} \epsilon_i$

which bounds the approximation error for the $i^{th}$ redundancy condition under distribution $j$. Also note that, insofar as the latent is natural across multiple $\alpha$ values, we can use the $\alpha$ value with largest $\alpha_j$ to get the best bound for $\epsilon^j_i$.

### Mediation

Mediation relies more heavily on the robustness of naturality to changes in $\alpha$. The gradient of the mediation approximation error with respect to $\alpha$ is:

$\frac{\partial}{\partial \alpha_j} D_{KL}(P[\Lambda, X] || P[\Lambda] \prod_i P[X_i|\Lambda])$

$= \sum_{X, \Lambda} P[\Lambda|X] P^j[X] \text{ln} \frac{P[\Lambda, X]}{P[\Lambda] \prod_i P[X_i|\Lambda]}$

(Note: it’s a nontrivial but handy fact that, in general, the change in approximation error of a distribution $P[Y]$ over some DAG $d D_{KL}(P[Y] || \prod_i P[Y_i|Y_{pa(i)}])$ under a change $dP$ is $\sum_Y dP[Y] \text{ln} \frac{P[Y]}{\prod_i P[Y_i|Y_{pa(i)}]}$.)

Note that this gradient must be zero along *allowed* changes in $\alpha$, which means the changes must respect $\sum_j \alpha_j = 1$. That means the gradient must be constant across indices $j$:

$\text{constant} = \sum_{X, \Lambda} P[\Lambda|X] P^j[X] \text{ln} \frac{P[\Lambda, X]}{P[\Lambda] \prod_i P[X_i|\Lambda]}$

To find that constant, we can take a sum weighted by $\alpha_j$ on both sides:

$\text{constant} = \sum_j \alpha_j \sum_{X, \Lambda} P[\Lambda|X] P^j[X] \text{ln} \frac{P[\Lambda, X]}{P[\Lambda] \prod_i P[X_i|\Lambda]}$

$= D_{KL}(P[\Lambda, X] || P[\Lambda] \prod_i P[X_i|\Lambda])$

So, robustness tells us that the approximation error under the mixed distribution can be written as

$D_{KL}(P[\Lambda, X] || P[\Lambda] \prod_i P[X_i|\Lambda]) = \text{constant} = \sum_{X, \Lambda} P[\Lambda|X] P^j[X] \text{ln} \frac{P[\Lambda, X]}{P[\Lambda] \prod_i P[X_i|\Lambda]}$

for any $j$.

Next, we’ll write out $P[\Lambda, X]$ as a mixture weighted by $\alpha$, and use Jensen’s inequality on that mixture and the logarithm:

$= E^j[ \text{ln} \frac{\sum_j \alpha_j P[\Lambda| X] P^j[X]}{P[\Lambda] \prod_i P[X_i|\Lambda]}]$

$\geq E^j[ \sum_j \alpha_j \text{ln} \frac{P[\Lambda| X] P^j[X]}{P[\Lambda] \prod_i P[X_i|\Lambda]}]$

$= \sum_j \alpha_j D_{KL}(P^j[\Lambda, X] || P[\Lambda] \prod_i P[X_i|\Lambda])$

Then factorization transfer gives:

$\geq \sum_j \alpha_j D_{KL}(P^j[\Lambda, X] || P^j[\Lambda] \prod_i P^j[X_i|\Lambda])$

Much like redundancy, if $\epsilon^j_i$ is the mediation error with respect to $X_i$ under distribution $j$ (note that we’re overloading notation, $\epsilon$ is no longer the redundancy error), and $\epsilon_i$ is the mediation error with respect to $X_i$ under the mixed distribution $P$, then the above says

$\epsilon_i \geq \sum_j \alpha_j \epsilon^j_i$

Since the $\alpha_j \epsilon^j_i$ terms are nonnegative, that also means

$\epsilon^j_i \leq \frac{1}{\alpha_j} \epsilon_i$

which bounds the approximation error for the $i^{th}$ mediation condition under distribution $j$.