# Resampling Conserves Redundancy (Approximately)

Suppose random variables $X_1$ and $X_2$ contain approximately the same information about a third random variable $\Lambda$, i.e. both of the following diagrams are [satisfied to within approximation](https://www.lesswrong.com/posts/XHtygebvHoJSSeNPP/some-rules-for-an-algebra-of-bayes-nets) $\epsilon$:

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

"Red" for redundancy

We call $\Lambda$ a "redund" over $X_1, X_2$, since conceptually, any information $\Lambda$ contains about $X$ must be redundantly represented in both $X_1$ and $X_2$ (to within approximation).

Here's an intuitive claim which is surprisingly tricky to prove: suppose we construct a new variable $\Lambda'$ by sampling from $P[\Lambda|X_2]$, so the new joint distribution is 

$P[X_1 = x_1, X_2 = x_2, \Lambda' = \lambda'] = P[X_1 = x_1, X_2 = x_2]P[\Lambda = \lambda' | X_2 = x_2]$

By construction, this "resampled" variable satisfies one of the two redundancy diagrams perfectly: $X_1 \rightarrow X_2 \rightarrow \Lambda'$. Intuitively, we might expect that $\Lambda'$ approximately satisfies the other redundancy diagram as well; conceptually, $\Lambda'$ (approximately) only contains redundant information about $X$, so $X_2$ contains (approximately) the same information about $\Lambda'$ as $X$ does, so the resampling operation should result in (approximately, in some sense) the same distribution we started with and therefore (approximately) the same properties.

In this post, we'll prove that claim and give a bound for the approximation error.

Specifically:

+++ Theorem: Resampling (Approximately) Conserves (Approximate) Redundancy

Let random variables $X_1, X_2$, $\Lambda$ satisfy the diagrams $X_1 \rightarrow X_2 \rightarrow \Lambda$ and $X_2 \rightarrow X_1 \rightarrow \Lambda$ to within $\epsilon$, i.e.

$\epsilon \geq D_{KL}(P[X_1, X_2, \Lambda] || P[X_1, X_2] P[\Lambda|X_2])$

$\epsilon \geq D_{KL}(P[X_1, X_2, \Lambda] || P[X_1, X_2] P[\Lambda|X_1])$

Also, assume $P[X, \Lambda] > 0$.

Construct $\Lambda'$ by sampling from $P[\Lambda|X_2]$, so $P[X_1, X_2, \Lambda'] = P[X_1, X_2]P[\Lambda = \lambda' | X_2]$. Then $X_1 \rightarrow X_2 \rightarrow \Lambda'$ is perfectly satisfied by construction, and $X_2 \rightarrow X_1 \rightarrow \Lambda'$ is satisfied to within $9 \epsilon$, i.e.

$9 \epsilon \geq D_{KL}(P[X_1, X_2, \Lambda'] || P[X_1, X_2] P[\Lambda'|X_1])$

* * *

In diagrammatic form:

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

(Where O(Ɛ) in this version of the proof is 9Ɛ, specifically.)






+++

Notation
--------

We will use the shorthand $D_{KL}(<\text{diagram over X}>)$ to mean $D_{KL}(P[X]||\prod_i P[X_i|X_{pa(i)}])$. For instance, $D_{KL}(X_1 \rightarrow X_2 \rightarrow \Lambda)$  is shorthand for $D_{KL}(P[X_1, X_2, \Lambda] || P[X_1] P[X_2|X_1] P[\Lambda|X_2])$, which is equivalent to $D_{KL}(P[X, \Lambda] || P[X] P[\Lambda|X_2])$.

We will work with nats for mathematical convenience (i.e. all logarithms are natural logs).

Proof
=====

The proof proceeds in three steps:

*   From $\Lambda$, we can construct a new variable $\Gamma$ which is equal to $\Lambda$ with probability $p$ and is otherwise a constant. Then the errors on all diagrams in the theorem for $\Gamma$ are the same as the corresponding errors for $\Lambda$, but scaled down by factor $p$. This allows us to focus only on the regime of arbitrarily small errors, and obtain a global bound from that regime.
*   Within the regime of arbitrarily small errors, $D_{KL}(P||Q)$ is approximately (to second order) equal to twice the Hellinger distance, $2\sum_X (\sqrt{P[X]} - \sqrt{Q[X]})^2$. Hellinger distance is a straightforward Euclidean distance metric, so we can use standard geometric reasoning on it.
*   The Hellinger distance between $P[\Lambda|X_2]$ and $P[\Lambda|X]$, between $P[\Lambda|X]$ and $P[\Lambda | X_1]$, and between $P[\Lambda|X_1]$ and $P[\Lambda'|X_1]$ are all small, so end-to-end the Hellinger distance between $P[\Lambda|X_2]$ and $P[\Lambda'|X_1]$ is small. That yields the bound we're after.

Step 1: Scaling Down The Errors
-------------------------------

First we construct the new variable $\Gamma$ as a stochastic function of $\Lambda$. Specifically, $\Gamma$$= \Lambda$ with probability $p$, else $\Gamma$ is a constant $C$, where $C$ is outside the support of $\Lambda$ (so when we see $\Gamma = C$, we gain no information about $\Lambda$).

A little algebra confirms that $\Gamma$'s errors are simply $\Lambda$'s errors scaled down by $p$:

$D_{KL}(P[X, \Gamma] || P[X] P[\Gamma|X_i])$

$= E_X[P[\Gamma = C](lnP[\Gamma = C|X] - lnP[\Gamma=C|X_i]) + \sum_\lambda P[\Gamma = \lambda|X] (ln P[\Gamma = \lambda|X] - ln P[\Gamma = \lambda|X_i])]$

$= E_X[(1-p)(ln(1-p) - ln(1-p)) + \sum_\lambda pP[\Lambda = \lambda|X] (ln( pP[\Lambda = \lambda|X]) - ln( pP[\Lambda = \lambda|X_i])) ]$

$= p E_X[\sum_\lambda P[\Lambda = \lambda|X] (ln( P[\Lambda = \lambda|X]) - ln( P[\Lambda = \lambda|X_i])) ]$

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

Similarly, constructing $\Gamma'$ just like $\Lambda'$ (i.e. $P[X, \Gamma'] = P[X]P[\Gamma = \gamma' | X_2]$) is equivalent to constructing $\Gamma'$ as a stochastic function of $\Lambda'$ where $\Gamma' = \Lambda'$ with probability $p$, else $\Gamma'$ is $C$. So, by the same algebra as above,

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

The upshot: if there exists a distribution over variables $X_1, X_2, \Lambda$ for which

$D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda') > n \cdot \text{max}(D_{KL}(X_1 \rightarrow X_2 \rightarrow \Lambda), D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda))$

then there *also* exists a distribution satisfying the same inequality with all $D_{KL}$'s arbitrarily small[^cj6hse8f1kn]. Flipping that statement around: if there does *not* exist any distribution for which the $D_{KL}$'s are all arbitrarily small *and* the inequality is satisfied, then there does not exist any distribution for which the inequality is satisfied.

In other words: if we can show

$D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda') \leq n \cdot \text{max}(D_{KL}(X_1 \rightarrow X_2 \rightarrow \Lambda), D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda)) \leq n \epsilon$

in the regime where all the $D_{KL}$'s are arbitrarily small, then the same inequality is also established globally, proving our theorem. The rest of the proof will therefore show

$D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda') \leq n \cdot \text{max}(D_{KL}(X_1 \rightarrow X_2 \rightarrow \Lambda), D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda))$

in the regime where all the $D_{KL}$'s are arbitrarily small. In particular, we'll use a second order approximation for the $D_{KL}$'s.

Step 2: Second Order Approximation
----------------------------------

### Validity

Before we can use a second order approximation of the $D_{KL}$'s, we need to show that small $D_{KL}$ implies that second order approximationis valid.

For that purpose, we use the [Hellinger-KL inequality](https://people.lids.mit.edu/yp/homepage/data/LN_fdiv.pdf):

$D(P||Q) ≥ 2 ln \frac{2}{2 − H^2(P, Q)}$

where $H^2(P, Q) := \sum_X (\sqrt{P[X]} - \sqrt{Q[X]})^2$ is the squared Hellinger distance.[^8ajctdftkit]

Using standard logarithm inequalities, we can weaken the Hellinger-KL inequality to

$D(P||Q) ≥ H^2(P, Q)$

So, as $D_{KL}(P||Q)$ goes to 0, the Hellinger distance goes to 0, and therefore $\sqrt{P}$ and $\sqrt{Q}$ are arbitrarily close together in standard Euclidean distance. Since $D_{KL}$ is smooth (for strictly positive distributions, which we have assumed), we can therefore use a second order approximation (with respect to $\sqrt{P} - \sqrt{Q}$) for our arbitrarily small $D_{KL}$'s.

### Expansion

Now for the second order expansion itself.

Our small quantity is $\delta[X] := \sqrt{P[X]} - \sqrt{Q[X]}$. Then

$D_{KL}(P||Q) = \sum_X P[X](ln P[X] - 2 ln \sqrt{Q[X]})$

$= \sum_X P[X](ln P[X] - 2 ln (\sqrt{P[X]} - \delta[X]))$

$= \sum_X P[X](ln P[X] - 2 ln (\sqrt{P[X]}) +2 \frac{\delta[X]}{\sqrt{P[X]}} + 2 \frac{1}{2}(\frac{\delta[X]}{\sqrt{P[X]}})^2 ) + o(\delta^3)$

$= \sum_X 2 \sqrt{P[X]}\delta[X] + \delta[X]^2  + o(\delta^3)$

To simplify that further, we can use the sum-to-1 constraints on the distributions: $\sqrt{Q[X]} = \sqrt{P[X]} - \delta[X]$ implies

$\sum_X Q[X] = \sum_X (\sqrt{P[X]} - \delta[X])^2 = \sum_X P[X] - 2 \sqrt{P[X]} \delta[X] + \delta[X]^2$

so $\sum_X 2 \sqrt{P[X]} \delta[X] = \sum_X \delta[X]^2$. That simplifies our second order approximation to

$D_{KL}(P||Q) = 2 \sum_X \delta[X]^2 + o(\delta^3)$

$= 2 \sum_X (\sqrt{P[X]} - \sqrt{Q[X]})^2 + o(\delta^3)$

i.e. in the second order regime $D_{KL}$ is twice the Hellinger distance.

Combining this with Step 1, we've now established that if we can prove our desired bound for Hellinger distances rather than $D_{KL}$, then the bound also applies globally for $D_{KL}$ errors. So now, we can set aside the notoriously finicky KL divergences, and work with good ol' Euclidean geometry.

Step 3: Good Ol' Euclidean Geometry
-----------------------------------

Writing everything out in the second order regime, our preconditions say

$\epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_2]})^2]$

$\epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_1]})^2]$

and we want to bound

$2 E_X[\sum_\Lambda' (\sqrt{P[\Lambda'|X]} - \sqrt{P[\Lambda'|X_1]})^2]$

$= 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X_2]} - \sqrt{\sum_{X_2'}P[\Lambda|X_2'] P[X_2'|X_1]})^2]$

That last expression has a Jensen vibe to it, so let's use Jensen's inequality.

### Jensen

We're going to use Jensen's inequality on the squared Hellinger distance, so we need to establish that squared Hellinger distance is convex as a function of the distributions $P, Q$.

Differentiating $(\sqrt{p} - \sqrt{q})^2$ twice with respect to $(p, q)$ yields the Hessian

$\frac{1}{2}\frac{1}{\sqrt{pq}} \begin{pmatrix}\frac{q}{p} & -1 \-1 & \frac{p}{q}\end{pmatrix}$

Note that one column is the other column multiplied by $-\frac{p}{q}$, so one of the eigenvalues is 0. The trace is positive, so the other eigenvalue is positive. Thus, the function is (non-strictly) convex.

Now, we'll use Jensen's inequality on

$\epsilon \geq E_X[\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_2]})^2]$

Specifically:

*   We'll hold $X_1$ constant, so it's not involved in our application of Jensen.
*   For each $X_1$ value, the expression takes a convex combination with weights $P[X_2|X_1]$ of the function $\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_2]})^2$.
*   Viewing $(P[\Lambda|X], P[\Lambda|X_2])$ at fixed $X_1$ as the function's inputs, the function is convex.

So, applying Jensen's, we get

$\epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_2]})^2]$

$\geq 2 E_{X_1}[\sum_\Lambda (\sqrt{\sum_{X_2} P[\Lambda|X] P[X_2|X_1]} - \sqrt{\sum_{X_2} P[\Lambda|X_2] P[X_2|X_1]})^2]$

$= 2 E_{X_1}[\sum_\Lambda (\sqrt{P[\Lambda|X_1]} - \sqrt{\sum_{X_2} P[\Lambda|X_2] P[X_2|X_1]})^2]$

$= 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X_1]} - \sqrt{\sum_{X_2} P[\Lambda|X_2] P[X_2|X_1]})^2]$

### Euclidean Distances

With that, we have bounds on three (squared) Hellinger distances:

$\epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_2]})^2]$

$\epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X]} - \sqrt{P[\Lambda|X_1]})^2]$

$\epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X_1]} - \sqrt{\sum_{X_2} P[\Lambda|X_2] P[X_2|X_1]})^2]$

So, on average over $X$:

*   The Euclidean distance between $\sqrt{P[\Lambda|X_2]}$ and $\sqrt{P[\Lambda|X]}$ is at most $\sqrt{\frac{\epsilon}{2}}$.
*   The Euclidean distance between $\sqrt{P[\Lambda|X]}$ and $\sqrt{P[\Lambda|X_1]}$ is at most $\sqrt{\frac{\epsilon}{2}}$.
*   The Euclidean distance between $\sqrt{P[\Lambda|X_1]}$ and $\sqrt{\sum_{X_2} P[\Lambda|X_2] P[X_2|X_1]}$ is at most $\sqrt{\frac{\epsilon}{2}}$.

So, on average, the Euclidean distance from end-to-end, between $\sqrt{P[\Lambda|X_2]}$ and $\sqrt{\sum_{X_2} P[\Lambda|X_2] P[X_2|X_1]}$, is at most $3\sqrt{\frac{\epsilon}{2}}$.

That gives us the desired bound:

$(3\sqrt{\frac{\epsilon}{2}})^2 \geq E_X[\sum_\Lambda (\sqrt{P[\Lambda|X_2]} - \sqrt{\sum_{X_2'}P[\Lambda|X_2'] P[X_2'|X_1]})^2]$

implying

$9 \epsilon \geq 2 E_X[\sum_\Lambda (\sqrt{P[\Lambda|X_2]} - \sqrt{\sum_{X_2'}P[\Lambda|X_2'] P[X_2'|X_1]})^2]$

Combined with our previous two sections, that establishes the desired upper bound of $9\epsilon$ on $D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda')$.

Empirical Results and Room for Improvement
==========================================

Below is a plot of the maximal error achieved via numerical minimization of $- D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda')$ subject to a constraint on$D_{KL}(X_1 \rightarrow X_2 \rightarrow \Lambda) + D_{KL}(X_2 \rightarrow X_1 \rightarrow \Lambda)$, searching over distributions of X and $\Lambda$. Above, we proved that the ratio of those two quantities can be no higher than $\frac{9}{2}$. As expected from the proof, it is visually clear that each point on the curve lies on a line between itself and the origin which itself always lies below the curve. Some, presumably, noise is present due to occasional failures of the optimizer to find the maximum error.

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

Zooming in on the steepest part of the curve and eyeballing the plot, it looks like the maximum ratio achieved is around 4 (.02/.005), implying an empirical upper bound of the resampled diagram of ~8$\epsilon$:

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

Looking into the actual solutions found, the solutions with ratio of ~4 involve one of the two terms in the x-axis sum being much larger than the other (5-10x). Therefore we expect to be able, in principle, to get a tighter bound (~4$\epsilon$, empirically, rather than the proven 9$\epsilon$ or empirical 8$\epsilon$.) The most likely place for improvement in the proof is to bound the Hellinger distance between $P[\Lambda|X_1]$ and $P[\Lambda|X_2]$ directly by $\epsilon$, cutting one step out of the "path", and that would indeed reduce the bound from 9$\epsilon$ to 4$\epsilon$. We'll leave that for future work.

Interesting additional piece for future reference: If we include the mediation condition into the denominator, and so look for a bound in terms of a factor of the sum of all natural latent condition epsilons, we find that the empirical factor in question is 1 (roughly. Not sure what happened at ~0.4):

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

[^cj6hse8f1kn]: Note that, since \(P[X, \Lambda] > 0\) by assumption, none of the \(D_{KL}\)'s are infinite. This is the only place where we need \(P[X, \Lambda] > 0\); that assumption can probably be eliminated by considering the infinite case directly, but we're not going to do that here. 

[^8ajctdftkit]: A quick aside: while it might look messy at first, the Hellinger distance is a particularly natural way to talk about Euclidean distances between probability distributions. In general, if one wants to view a distribution \(P[X]\) as a vector, \(\sqrt{P[X]}\) is the most natural vector to consider, since the sum-to-1 constraint says \(\sqrt{P[X]}\) is a unit vector under the standard Euclidean distance.