Type at least 2 letters. Enter opens the first result, Esc closes.

    Information Theory · Lesson 10 · Information-theoretic objectives in ML

    Lossy compression: rate–distortion, the information bottleneck and the β-VAE

    Advanced 75 min 5 interactive figures 4 videos Colab notebook

    Before this lesson: lesson 05 (lossless coding, rates in bits per symbol), lesson 07 (mutual information, the data processing inequality), lesson 09 (the ELBO and the VAE). "Conditioning reduces entropy" is from lesson 02; the maximum entropy of the Gaussian is from lesson 06. Reverse water-filling uses PCA (linear algebra lesson 09). Time: about 75 minutes, plus the notebook. This lesson is dense; take a break after section 3.4.


    Why this matters #

    • Learned compression. Neural image and video codecs (Ballé et al.) are trained with the loss rate + λ⋅+\ \lambda \cdot distortion. JPEG, MP3 and video codecs are hand-made points on the same plane.
    • VAEs and latent diffusion. The two terms of the VAE loss are a distortion and a rate. The β-VAE moves along the curve, and posterior collapse is the point "rate = 0". The autoencoder of a latent diffusion model chooses a point with a high rate, so that details survive.
    • Quantization of models. "How many bits per weight for a given error?" is a rate–distortion question. The rule "6 dB per bit" comes from the Gaussian R(D)R(D).
    • Representation learning. The information bottleneck and its variational form are used as regularizers, and as one (debated) theory of what deep networks learn.
    • ML for science. Climate, weather and simulation archives are compressed with error bounds, and compressors are compared by bits per value against error.

    As in the whole track, log⁡\log is the natural log (nats) and log⁡2\log_2 gives bits. Rates are in bits unless a formula says nats. Hb(x)=−xlog⁡2x−(1−x)log⁡2(1−x)H_b(x) = -x\log_2 x - (1-x)\log_2(1-x) is the binary entropy in bits.

    1. Predict first #

    2. The picture #

    Encoder, bits, decoder #

    An encoder sees a block of nn source symbols xn=(x1,…,xn)x^n = (x_1, \dots, x_n) and sends one of 2nR2^{nR} messages, that is, nRnR bits. A decoder turns the message into a reconstruction x^n\hat x^n. A distortion measure d(x,x^)≥0d(x, \hat x) \ge 0 scores each symbol:

    • Hamming distortion d(x,x^)=1[x≠x^]d(x, \hat x) = \mathbf{1}[x \ne \hat x] for symbols: the average is the error rate;
    • squared error d(x,x^)=(x−x^)2d(x, \hat x) = (x - \hat x)^2 for real numbers: the average is the mean squared error (MSE).

    The rate RR is in bits per symbol. The question: what is the smallest rate for an average distortion of at most DD?

    A fair coin: store or guess #

    Take fair coin flips and Hamming distortion. A simple scheme: store a fraction α\alpha of the flips exactly (1 bit each), and output a fixed guess for the rest. A fixed guess is wrong half of the time. So

    R=α,D=12(1−α)⟹R=1−2D.R = \alpha, \qquad D = \tfrac12(1 - \alpha) \qquad\Longrightarrow\qquad R = 1 - 2D .

    This is a straight line from (D,R)=(0,1)(D, R) = (0, 1) to (12,0)(\frac12, 0). To allow 11% errors, it needs R=1−0.22=0.78R = 1 - 0.22 = 0.78 bits per flip.

    Shannon's answer is the curve R(D)=1−Hb(D)R(D) = 1 - H_b(D). At D=0.11D = 0.11, Hb(0.11)=0.50H_b(0.11) = 0.50, so only 0.50 bits per flip are needed. The curve lies below the line everywhere between the end points.

    Interactive figure: loading…

    Move the DD slider and compare the limit R(D)R(D) (magenta) with the store-or-guess line (orange). The aqua bar is the gain of coding long blocks. Then change pp: the curve starts at the lossless limit Hb(p)H_b(p) and reaches 0 at D=min⁡(p,1−p)D = \min(p, 1-p), where you can always output the more likely symbol.

    Why block coding wins (a counting picture). Code nn flips at once, for a large nn. Around each reconstruction sequence, the sequences within Hamming distance nDnD form a "ball". This ball contains about 2nHb(D)2^{nH_b(D)} sequences (for D≤12D \le \frac12). There are 2n2^n possible source sequences, so you need at least

    2n2nHb(D)=2n(1−Hb(D))\frac{2^n}{2^{nH_b(D)}} = 2^{n(1 - H_b(D))}

    reconstruction sequences to come within distance nDnD of every one. That is n(1−Hb(D))n(1 - H_b(D)) bits, a rate of 1−Hb(D)1 - H_b(D). Shannon showed that a random set of slightly more sequences is enough. Store-or-guess treats each flip alone and wastes this geometry. For n=100n = 100 and D=0.11D = 0.11: about 2502^{50} reconstruction sequences for 21002^{100} source sequences.

    The test channel #

    Think of encoder and decoder together as one noisy channel from XX to X^\hat X, with a conditional distribution q(x^∣x)q(\hat x \mid x): the test channel. The message has nRnR bits, so X^n\hat X^n can carry at most nRnR bits of information about XnX^n. Rate–distortion asks for the channel that carries the least information about XX while it still meets the distortion budget.

    Channel capacity (the other half of Shannon's theory) is the opposite problem: there the channel is fixed, and you maximize I(X;Y)I(X; Y) over the input distribution.

    Quick check

    For a fair coin with Hamming distortion, what is R(0)R(0)?

    3. Definitions and main results #

    3.1 The rate–distortion function #

    Notation. The source X∼p(x)X \sim p(x) is i.i.d. The reconstruction X^\hat X takes values in a set X^\hat{\mathcal X}. d(x,x^)≥0d(x, \hat x) \ge 0 is the distortion and q(x^∣x)q(\hat x \mid x) is a test channel.

    Definition (rate–distortion function).

    R(D)=min⁡q(x^∣x) :  E[d(X,X^)]≤DI(X;X^),R(D) = \min_{q(\hat x \mid x)\,:\; \mathbb{E}[d(X, \hat X)] \le D} I(X; \hat X),

    where the expectation and II are under the joint distribution p(x) q(x^∣x)p(x)\,q(\hat x \mid x). Let Dmax⁡=min⁡x^E[d(X,x^)]D_{\max} = \min_{\hat x}\mathbb{E}[d(X, \hat x)]: the distortion of the best constant output. For D≥Dmax⁡D \ge D_{\max}, a constant output meets the budget and carries no information, so R(D)=0R(D) = 0.

    Theorem (Shannon's rate–distortion theorem; stated without proof). For an i.i.d. source and a bounded distortion measure:

    • for every rate R>R(D)R > R(D) and every ε>0\varepsilon > 0, there are block codes of rate RR with expected distortion at most D+εD + \varepsilon, for nn large enough;
    • no code of rate R<R(D)R < R(D) has expected distortion at most DD.

    (Cover and Thomas, Elements of Information Theory, ch. 10.) So the mathematical minimum in the definition is also the operational limit.

    Properties.

    • R(D)R(D) is non-increasing: a larger DD allows more channels, so the minimum can only go down.
    • For a discrete source with Hamming distortion, R(0)=H(X)R(0) = H(X): D=0D = 0 forces X^=X\hat X = X.
    • R(D)R(D) is convex.

    Proof of convexity.

    1. Let q1q_1 and q2q_2 be optimal channels for D1D_1 and D2D_2, and λ∈[0,1]\lambda \in [0, 1]. Mix them: qλ=λq1+(1−λ)q2q_\lambda = \lambda q_1 + (1 - \lambda) q_2.
    2. The expected distortion is linear in the channel, so qλq_\lambda has distortion at most λD1+(1−λ)D2\lambda D_1 + (1 - \lambda) D_2.
    3. For a fixed p(x)p(x), I(X;X^)I(X; \hat X) is a convex function of q(x^∣x)q(\hat x \mid x) (Cover and Thomas, Theorem 2.7.4). So R(λD1+(1−λ)D2)≤I(qλ)≤λR(D1)+(1−λ)R(D2)R(\lambda D_1 + (1 - \lambda) D_2) \le I(q_\lambda) \le \lambda R(D_1) + (1 - \lambda) R(D_2). ■\blacksquare

    Convexity explains the coin picture: store-or-guess mixes the two end points (0,H(X))(0, H(X)) and (Dmax⁡,0)(D_{\max}, 0), so it is the straight line between them, and a convex curve lies below that line.

    Quick check

    Rate–distortion theory looks for the test channel q(x^∣x)q(\hat x \mid x) that

    3.2 A binary source with Hamming distortion #

    Theorem. Let X∼X \sim Bernoulli(pp) with p≤12p \le \frac12, and d(x,x^)=1[x≠x^]d(x, \hat x) = \mathbf{1}[x \ne \hat x]. Then

    R(D)=Hb(p)−Hb(D)for 0≤D≤p,R(D)=0for D≥p.R(D) = H_b(p) - H_b(D) \quad \text{for } 0 \le D \le p, \qquad R(D) = 0 \quad \text{for } D \ge p .

    (For p>12p > \frac12 swap the roles of 0 and 1: the formula holds with min⁡(p,1−p)\min(p, 1-p) in place of pp.)

    Proof. First a lower bound, for any channel with E[d]≤D≤p\mathbb{E}[d] \le D \le p.

    1. Let E=X⊕X^E = X \oplus \hat X (XOR). E=1E = 1 exactly when the reconstruction is wrong, so Pr⁡(E=1)=E[d]≤D\Pr(E = 1) = \mathbb{E}[d] \le D.
    2. I(X;X^)=H(X)−H(X∣X^)=Hb(p)−H(E∣X^)I(X; \hat X) = H(X) - H(X \mid \hat X) = H_b(p) - H(E \mid \hat X). Once X^\hat X is known, knowing XX is the same as knowing EE.
    3. H(E∣X^)≤H(E)=Hb(Pr⁡(E=1))≤Hb(D)H(E \mid \hat X) \le H(E) = H_b(\Pr(E = 1)) \le H_b(D). The first step is "conditioning reduces entropy" (lesson 02). The second holds because HbH_b is increasing on [0,12][0, \frac12].
    4. So I(X;X^)≥Hb(p)−Hb(D)I(X; \hat X) \ge H_b(p) - H_b(D).

    Then a channel that reaches the bound.

    1. Build the joint distribution backwards: X^∼\hat X \sim Bernoulli(ss) and X=X^⊕ZX = \hat X \oplus Z, with Z∼Z \sim Bernoulli(DD) independent of X^\hat X. Choose s=p−D1−2Ds = \frac{p - D}{1 - 2D}, so that Pr⁡(X=1)=s(1−D)+(1−s)D=p\Pr(X = 1) = s(1 - D) + (1 - s)D = p.
    2. Then E[d]=Pr⁡(Z=1)=D\mathbb{E}[d] = \Pr(Z = 1) = D and I(X;X^)=H(X)−H(X∣X^)=Hb(p)−Hb(D)I(X; \hat X) = H(X) - H(X \mid \hat X) = H_b(p) - H_b(D), because given X^\hat X, the only uncertainty in XX is ZZ. The forward channel q(x^∣x)q(\hat x \mid x) follows from Bayes' rule (section 4). ■\blacksquare

    Example. p=0.3p = 0.3, D=0.1D = 0.1: R=Hb(0.3)−Hb(0.1)=0.881−0.469=0.412R = H_b(0.3) - H_b(0.1) = 0.881 - 0.469 = 0.412 bits per symbol. Lossless coding needs 0.881 bits; allowing 10% errors saves more than half.

    3.3 A Gaussian source with squared error #

    Theorem. Let X∼N(0,σ2)X \sim \mathcal N(0, \sigma^2) and d(x,x^)=(x−x^)2d(x, \hat x) = (x - \hat x)^2. Then

    R(D)=12log⁡2σ2Dfor 0<D≤σ2,R(D)=0for D≥σ2.R(D) = \tfrac12 \log_2 \frac{\sigma^2}{D} \quad \text{for } 0 < D \le \sigma^2, \qquad R(D) = 0 \quad \text{for } D \ge \sigma^2 .

    Equivalently, the smallest MSE at rate RR is D(R)=σ2 2−2RD(R) = \sigma^2\, 2^{-2R}.

    Why this is true (intuition). The reconstruction must "explain" all of the variance except DD. The best reconstruction is itself Gaussian with variance σ2−D\sigma^2 - D, and the leftover error is Gaussian noise with variance DD. The information is the log of the ratio of the two "volumes", 12log⁡2(σ2/D)\frac12\log_2(\sigma^2/D).

    Proof. Lower bound, for any channel with E[(X−X^)2]≤D\mathbb{E}[(X - \hat X)^2] \le D. Here hh is the differential entropy in bits (lesson 06).

    1. I(X;X^)=h(X)−h(X∣X^)=h(X)−h(X−X^∣X^)≥h(X)−h(X−X^)I(X; \hat X) = h(X) - h(X \mid \hat X) = h(X) - h(X - \hat X \mid \hat X) \ge h(X) - h(X - \hat X). Given X^\hat X, subtracting it is a shift, which does not change hh; then conditioning reduces entropy.
    2. Among all distributions with a given variance, the Gaussian has the largest differential entropy, and the variance is at most the second moment. So h(X−X^)≤12log⁡2(2πe E[(X−X^)2])≤12log⁡2(2πeD)h(X - \hat X) \le \frac12\log_2\big(2\pi e\,\mathbb{E}[(X - \hat X)^2]\big) \le \frac12\log_2(2\pi e D).
    3. With h(X)=12log⁡2(2πeσ2)h(X) = \frac12\log_2(2\pi e\sigma^2): I(X;X^)≥12log⁡2(σ2/D)I(X; \hat X) \ge \frac12\log_2(\sigma^2/D).

    Achievability:

    1. Backwards again: X^∼N(0,σ2−D)\hat X \sim \mathcal N(0, \sigma^2 - D) and X=X^+ZX = \hat X + Z with Z∼N(0,D)Z \sim \mathcal N(0, D) independent of X^\hat X. Then X∼N(0,σ2)X \sim \mathcal N(0, \sigma^2), E[(X−X^)2]=D\mathbb{E}[(X - \hat X)^2] = D, and I(X;X^)=h(X)−h(Z)=12log⁡2(σ2/D)I(X; \hat X) = h(X) - h(Z) = \frac12\log_2(\sigma^2/D). ■\blacksquare

    Each extra bit divides DD by 4, that is, 10log⁡104=6.0210\log_{10} 4 = 6.02 dB per bit (it halves the standard deviation of the error). The Gaussian is also the hardest source for squared error: every source with variance σ2\sigma^2 has R(D)≤12log⁡2(σ2/D)R(D) \le \frac12\log_2(\sigma^2/D).

    Interactive figure: loading…

    Move the DD slider along the curve R(D)R(D). The lower chart shows a sample signal xx and a reconstruction x^\hat x drawn from the optimal test channel with that mean squared error; the aqua bars are the errors. Halve the bits and watch the errors grow. Then show the quantizer points: a uniform scalar quantizer followed by an ideal entropy coder stays about 0.25 bits above the curve.

    3.4 Many Gaussian components: reverse water-filling #

    Now let X=(X1,…,Xk)X = (X_1, \dots, X_k) have independent Gaussian components with variances λ1,…,λk\lambda_1, \dots, \lambda_k (for example, the principal components of data), and let the distortion be the total squared error. How should you share the bits?

    Theorem (reverse water-filling). Choose a "water level" θ>0\theta > 0. Component ii gets the distortion Di=min⁡(θ,λi)D_i = \min(\theta, \lambda_i) and the rate Ri=12log⁡2(λi/Di)R_i = \frac12\log_2(\lambda_i / D_i). Then

    R(D)=∑i=1k12log⁡2λiDi,D=∑i=1kDi,R(D) = \sum_{i=1}^k \tfrac12 \log_2 \frac{\lambda_i}{D_i}, \qquad D = \sum_{i=1}^k D_i ,

    where θ\theta is chosen so that the DiD_i add up to DD. Components with λi≤θ\lambda_i \le \theta get no bits at all.

    Interactive figure: loading…

    Move the water level θ\theta (yellow). Each blue bar is the variance of one component; the aqua part is its distortion Di=min⁡(θ,λi)D_i = \min(\theta, \lambda_i), and the number above the bar is its rate in bits. Notice that every coded component ends with the same error θ\theta, and that small components are dropped. Try the spectrum of the digits data set: its top principal components have similar variances.

    Why water-filling is optimal (sketch)
    1. For independent components, I(X;X^)≥∑iI(Xi;X^i)I(X; \hat X) \ge \sum_i I(X_i; \hat X_i) (Cover and Thomas, §10.3.3), and each term is at least Ri(Di)=max⁡(0,12log⁡2(λi/Di))R_i(D_i) = \max\big(0, \frac12\log_2(\lambda_i / D_i)\big). So R(D)≥min⁡∑iRi(Di)R(D) \ge \min \sum_i R_i(D_i) over D1+⋯+Dk=DD_1 + \dots + D_k = D. Coding each component with its own optimal channel reaches this sum, so equality holds.
    2. Minimize ∑i12log⁡2(λi/Di)\sum_i \frac12\log_2(\lambda_i / D_i) subject to ∑iDi=D\sum_i D_i = D and 0<Di≤λi0 < D_i \le \lambda_i. With a Lagrange multiplier, the derivative −12Diln⁡2-\frac{1}{2 D_i \ln 2} must be the same for every component that gets bits: all such DiD_i are equal, to θ\theta.
    3. If λi<θ\lambda_i < \theta, the best choice is Di=λiD_i = \lambda_i (send nothing): reducing its error below λi\lambda_i would cost more than spending the bits elsewhere. ■\blacksquare

    This is the theory behind transform coding: rotate the data to its principal components (PCA, the DCT in JPEG), then spend bits only on components with large variance. Dropping the small components is exactly what truncated PCA does.

    3.5 The Blahut–Arimoto algorithm #

    For a general discrete source there is no closed form. The Blahut–Arimoto (BA) algorithm computes points of the curve.

    1. Lagrangian. For β>0\beta > 0, minimize I(X;X^)+β E[d(X,X^)]I(X; \hat X) + \beta\,\mathbb{E}[d(X, \hat X)] over q(x^∣x)q(\hat x \mid x). The minimizer is the point of the curve where the slope is dR/dD=−βdR/dD = -\beta (with RR in nats). Large β\beta: low distortion and high rate. Small β\beta: low rate.
    2. A variational form of II. For any distribution r(x^)r(\hat x) on X^\hat{\mathcal X},
    ∑xp(x)∑x^q(x^∣x)log⁡q(x^∣x)r(x^)=I(X;X^)+KL(qˉ ∥ r)≥I(X;X^),\begin{aligned} &\sum_x p(x)\sum_{\hat x} q(\hat x \mid x)\log\frac{q(\hat x \mid x)}{r(\hat x)} \\ &\qquad = I(X; \hat X) + \mathrm{KL}(\bar q\,\|\,r) \ge I(X; \hat X), \end{aligned}

    where qˉ(x^)=∑xp(x) q(x^∣x)\bar q(\hat x) = \sum_x p(x)\,q(\hat x \mid x) is the output marginal. Equality holds if and only if r=qˉr = \bar q. So BA minimizes, over both qq and rr,

    F(q,r)=∑xp(x)∑x^q(x^∣x)×[log⁡q(x^∣x)r(x^)+β d(x,x^)].\begin{aligned} F(q, r) = &\sum_x p(x)\sum_{\hat x} q(\hat x \mid x) \\ &\times \Big[\log\frac{q(\hat x \mid x)}{r(\hat x)} + \beta\,d(x, \hat x)\Big]. \end{aligned}
    1. Alternate two exact minimizations (see the box).
    2. Convergence. No step increases FF, and FF is jointly convex in (q,r)(q, r), so the iteration converges to the minimum (Csiszár and Tusnády, 1984). At the end, report R=I(X;X^)R = I(X; \hat X) and D=E[d]D = \mathbb{E}[d]. A sweep over β\beta traces the whole curve.
    Interactive figure: loading…

    Press 1 step a few times, then 25 steps. The yellow point is the current channel; it moves onto the curve R(D)R(D) and stops where the dashed line of slope −β-\beta touches the curve. The table on the right is the test channel q(x^∣x)q(\hat x \mid x) (darker orange = larger). Move β\beta and run again to land on another point. Try the 3-level source with squared error.

    For the Bernoulli source, the slope of Hb(p)−Hb(D)H_b(p) - H_b(D) in nats is −log⁡1−DD-\log\frac{1 - D}{D}. Setting it to −β-\beta gives D=1/(1+eβ)D = 1/(1 + e^{\beta}), which does not depend on pp (as long as D≤min⁡(p,1−p)D \le \min(p, 1 - p)).

    Quick check

    You run Blahut–Arimoto on a Bernoulli(0.3) source with Hamming distortion and β=ln⁡9≈2.197\beta = \ln 9 \approx 2.197. Where does it end?

    3.6 The information bottleneck #

    Now the goal is not to reconstruct XX but to keep what matters for a target YY. Input XX, target YY, and a representation TT computed from XX alone, with a distribution p(t∣x)p(t \mid x). So Y→X→TY \to X \to T is a Markov chain. The information bottleneck (IB; Tishby, Pereira and Bialek, 1999) is, for β>0\beta > 0:

    min⁡p(t∣x)  I(X;T)−β I(T;Y).\min_{p(t \mid x)}\; I(X; T) - \beta\, I(T; Y).

    Compress XX (small I(X;T)I(X; T)) while keeping the information about YY (large I(T;Y)I(T; Y)). By the data processing inequality (lesson 07), I(T;Y)≤I(X;Y)I(T; Y) \le I(X; Y): TT cannot know more about YY than XX does.

    IB is a rate–distortion problem. Take the rate I(X;T)I(X; T) and the distortion d(x,t)=KL(p(y∣x) ∥ p(y∣t))d(x, t) = \mathrm{KL}(p(y \mid x)\,\|\,p(y \mid t)): how much the prediction of YY gets worse when you use tt instead of xx. The Markov chain gives p(y∣x,t)=p(y∣x)p(y \mid x, t) = p(y \mid x), so

    Ex,t[KL(p(y∣x) ∥ p(y∣t))]=E[log⁡p(y∣x)p(y)]−E[log⁡p(y∣t)p(y)]=I(X;Y)−I(T;Y).\mathbb{E}_{x,t}\big[\mathrm{KL}(p(y \mid x)\,\|\,p(y \mid t))\big] = \mathbb{E}\Big[\log\frac{p(y \mid x)}{p(y)}\Big] - \mathbb{E}\Big[\log\frac{p(y \mid t)}{p(y)}\Big] = I(X; Y) - I(T; Y).

    I(X;Y)I(X; Y) does not depend on p(t∣x)p(t \mid x). So minimizing I(X;T)+β E[d]I(X; T) + \beta\,\mathbb{E}[d] is the IB objective. Its solution has the BA form p(t∣x)∝p(t)exp⁡(−β KL(p(y∣x) ∥ p(y∣t)))p(t \mid x) \propto p(t)\exp\big(-\beta\,\mathrm{KL}(p(y \mid x)\,\|\,p(y \mid t))\big); the iteration also updates p(y∣t)p(y \mid t), because here the distortion itself depends on the channel.

    Variational IB (Alemi et al., 2017) makes this trainable with neural networks. For any r(t)r(t), I(X;T)≤Ex KL(p(t∣x) ∥ r(t))I(X; T) \le \mathbb{E}_x\,\mathrm{KL}(p(t \mid x)\,\|\,r(t)). For any decoder q(y∣t)q(y \mid t), I(T;Y)≥H(Y)+E[log⁡q(y∣t)]I(T; Y) \ge H(Y) + \mathbb{E}[\log q(y \mid t)]. The resulting loss is

    E[−log⁡q(y∣t)]+β′ Ex KL(p(t∣x) ∥ r(t)),β′=1/β,\mathbb{E}[-\log q(y \mid t)] + \beta'\,\mathbb{E}_x\,\mathrm{KL}(p(t \mid x)\,\|\,r(t)), \qquad \beta' = 1/\beta,

    a β-VAE whose decoder predicts yy instead of xx.

    3.7 The β-VAE as a rate–distortion trade-off #

    A VAE has an encoder qϕ(z∣x)q_\phi(z \mid x), a decoder pθ(x∣z)p_\theta(x \mid z) and a prior p(z)p(z) (lesson 09). For one data point xx:

    −ELBO(x)=Eqϕ(z∣x)[−log⁡pθ(x∣z)]⏟distortion D(x)+KL(qϕ(z∣x) ∥ p(z))⏟rate R(x).-\mathrm{ELBO}(x) = \underbrace{\mathbb{E}_{q_\phi(z\mid x)}[-\log p_\theta(x \mid z)]}_{\text{distortion } D(x)} + \underbrace{\mathrm{KL}(q_\phi(z \mid x)\,\|\,p(z))}_{\text{rate } R(x)} .
    • Distortion is the expected reconstruction loss in nats. For a Gaussian decoder with fixed variance σx2\sigma_x^2, −log⁡pθ(x∣z)=∥x−μθ(z)∥2/(2σx2)+const-\log p_\theta(x \mid z) = \|x - \mu_\theta(z)\|^2 / (2\sigma_x^2) + \text{const}: a scaled squared error.
    • Rate is the KL term. Averaged over the data it bounds the information that zz carries about xx.

    Theorem (the rate is an upper bound on I(X;Z)I(X; Z)). Average over the data pdata(x)p_{\text{data}}(x) and let q(z)=Ex qϕ(z∣x)q(z) = \mathbb{E}_{x}\,q_\phi(z \mid x) be the aggregate posterior. Then

    Ex KL(qϕ(z∣x) ∥ p(z))=Iq(X;Z)+KL(q(z) ∥ p(z))≥Iq(X;Z),\mathbb{E}_x\,\mathrm{KL}(q_\phi(z \mid x)\,\|\,p(z)) = I_q(X; Z) + \mathrm{KL}(q(z)\,\|\,p(z)) \ge I_q(X; Z),

    where IqI_q is the mutual information under pdata(x) qϕ(z∣x)p_{\text{data}}(x)\,q_\phi(z \mid x).

    Proof.

    1. Split the log: log⁡qϕ(z∣x)p(z)=log⁡qϕ(z∣x)q(z)+log⁡q(z)p(z)\log\frac{q_\phi(z\mid x)}{p(z)} = \log\frac{q_\phi(z\mid x)}{q(z)} + \log\frac{q(z)}{p(z)}.
    2. Take the expectation over pdata(x) qϕ(z∣x)p_{\text{data}}(x)\,q_\phi(z \mid x). The first term gives Iq(X;Z)I_q(X; Z) by the definition of mutual information.
    3. In the second term only zz appears, and its marginal is q(z)q(z). So it gives KL(q(z) ∥ p(z))≥0\mathrm{KL}(q(z)\,\|\,p(z)) \ge 0. ■\blacksquare

    The bound is tight when the aggregate posterior equals the prior. On the other side, Iq(X;Z)≥H−DI_q(X; Z) \ge H - D, where HH is the entropy of the data, because H(X∣Z)≤DH(X \mid Z) \le D (a cross-entropy is at least the entropy). So H−D≤Iq(X;Z)≤RH - D \le I_q(X; Z) \le R (Alemi et al., 2018).

    The β-VAE (Higgins et al., 2017) minimizes D+βRD + \beta R.

    • β=1\beta = 1 is the negative ELBO.
    • β>1\beta > 1 buys a lower rate with more distortion: more compressed codes, often blurrier reconstructions.
    • β<1\beta < 1 does the opposite: more information in zz, sharper reconstructions.
    • Same ELBO, different models. −ELBO=D+R-\mathrm{ELBO} = D + R, so every point on a line D+R=constD + R = \text{const} has the same ELBO. A model with R≈0R \approx 0 ignores zz: this is posterior collapse. A powerful decoder can reach a good ELBO this way. So report RR and DD separately, not only the ELBO.

    A linear-Gaussian example. Let X∼N(0,1)X \sim \mathcal N(0, 1), the encoder z=ax+s εz = a x + s\,\varepsilon with ε∼N(0,1)\varepsilon \sim \mathcal N(0, 1), the prior p(z)=N(0,1)p(z) = \mathcal N(0, 1), and the best decoder x^=E[X∣z]=aa2+s2z\hat x = \mathbb{E}[X \mid z] = \frac{a}{a^2 + s^2} z. With v=a2+s2v = a^2 + s^2, all quantities have closed forms (in nats):

    MSE=s2v,I(X;Z)=12ln⁡vs2,R=12(v−1−ln⁡s2),R−I=12(v−1−ln⁡v).\text{MSE} = \frac{s^2}{v}, \qquad I(X; Z) = \tfrac12 \ln\frac{v}{s^2}, \qquad R = \tfrac12\big(v - 1 - \ln s^2\big), \qquad R - I = \tfrac12(v - 1 - \ln v).

    So I(X;Z)=12ln⁡(1/MSE)I(X; Z) = \frac12\ln(1/\text{MSE}): measured by mutual information, every such encoder sits exactly on the Gaussian curve. The rate equals II only when v=1v = 1, that is, when q(z)=N(0,v)q(z) = \mathcal N(0, v) is the prior. With a decoder variance of 12\frac12 the distortion is the MSE (plus a constant), and the β-VAE optimum is MSE=β/2\text{MSE} = \beta/2 on the curve for β<2\beta < 2, and the collapsed point R=0R = 0, MSE=1\text{MSE} = 1 for β≥2\beta \ge 2.

    Interactive figure: loading…

    Move the encoder sliders aa and ss. The orange point is (MSE, rate) and the violet point is (MSE, I(X;Z)I(X;Z)); the aqua bar between them is KL(q(z) ∥ p(z))\mathrm{KL}(q(z)\,\|\,p(z)). The violet point always lies on the curve. Then move β\beta: the yellow point is the β-VAE optimum, where the dashed line of equal loss D+βRD + \beta R touches the curve. Press Go to the β-optimum, and try β≥2\beta \ge 2 to see posterior collapse.

    Learned image compression (Ballé et al., 2017) minimizes R+λDR + \lambda D, with the rate given by a learned entropy model of a quantized latent (coded with arithmetic coding, lesson 05). It is the β-VAE objective with β=1/λ\beta = 1/\lambda.

    Quick check

    You train a β-VAE and increase β\beta from 1 to 4. What do you expect?

    Quick check

    A VAE reports an average KL term of 12 nats. What do you know about Iq(X;Z)I_q(X; Z) under the encoder?

    Answers to section 1. (1) 1−Hb(0.11)=0.501 - H_b(0.11) = 0.50 bits per flip, not 0.78: coding long blocks beats store-or-guess. (2) By a factor of 4: D(R)=σ22−2RD(R) = \sigma^2 2^{-2R}, that is 6.02 dB per bit. (3) The KL term (rate) goes down and the reconstruction error goes up; for large enough β\beta the rate can reach 0 (posterior collapse).

    4. Worked example #

    A Bernoulli(0.3) source with Hamming distortion, at D=0.1D = 0.1.

    1. Rate. Hb(0.3)=0.8813H_b(0.3) = 0.8813 and Hb(0.1)=0.4690H_b(0.1) = 0.4690, so R(0.1)=0.4123R(0.1) = 0.4123 bits per symbol. Dmax⁡=0.3D_{\max} = 0.3 (always output 0).
    2. Backward channel. s=0.3−0.11−0.2=0.25s = \frac{0.3 - 0.1}{1 - 0.2} = 0.25: X^∼\hat X \sim Bernoulli(0.25), and XX is X^\hat X flipped with probability 0.1. Check: Pr⁡(X=1)=0.25⋅0.9+0.75⋅0.1=0.225+0.075=0.3\Pr(X = 1) = 0.25 \cdot 0.9 + 0.75 \cdot 0.1 = 0.225 + 0.075 = 0.3 ✓.
    3. Forward channel, by Bayes' rule. q(x^=1∣x=1)=Pr⁡(X^=1)Pr⁡(X=1∣X^=1)Pr⁡(X=1)=0.25⋅0.90.3=0.75q(\hat x{=}1 \mid x{=}1) = \frac{\Pr(\hat X = 1)\Pr(X = 1 \mid \hat X = 1)}{\Pr(X = 1)} = \frac{0.25 \cdot 0.9}{0.3} = 0.75, and q(x^=1∣x=0)=0.25⋅0.10.7=128=0.0357q(\hat x{=}1 \mid x{=}0) = \frac{0.25 \cdot 0.1}{0.7} = \frac1{28} = 0.0357. The encoder keeps almost all 0s and turns a quarter of the 1s into 0s: it errs toward the more likely symbol. Distortion: 0.3⋅0.25+0.7⋅0.0357=0.075+0.025=0.10.3 \cdot 0.25 + 0.7 \cdot 0.0357 = 0.075 + 0.025 = 0.1 ✓.
    4. Slope. dR/dD=−ln⁡0.90.1=−ln⁡9=−2.197dR/dD = -\ln\frac{0.9}{0.1} = -\ln 9 = -2.197 nats per unit of distortion. So BA with β=ln⁡9\beta = \ln 9 ends here: D=1/(1+9)=0.1D = 1/(1 + 9) = 0.1.
    5. This is a fixed point of BA. The output marginal is r=(0.75,0.25)r = (0.75, 0.25) (vectors list x^=0\hat x = 0, then x^=1\hat x = 1), and e−β=19e^{-\beta} = \frac19. For x=1x = 1: q∝(0.75⋅19, 0.25⋅1)=(0.0833,0.25)q \propto (0.75 \cdot \frac19,\ 0.25 \cdot 1) = (0.0833, 0.25), which normalizes to (0.25,0.75)(0.25, 0.75). For x=0x = 0: q∝(0.75⋅1, 0.25⋅19)=(0.75,0.0278)q \propto (0.75 \cdot 1,\ 0.25 \cdot \frac19) = (0.75, 0.0278), which normalizes to (0.9643,0.0357)(0.9643, 0.0357). Both match step 3.
    6. Gaussian. σ2=1\sigma^2 = 1 and D=0.25D = 0.25 give R=12log⁡24=1R = \frac12\log_2 4 = 1 bit per sample. A uniform scalar quantizer with ideal entropy coding needs about 12log⁡2πe6=0.254\frac12\log_2\frac{\pi e}{6} = 0.254 bits more per sample at high rate (1.53 dB). Coding long blocks closes this gap.

    5. In code #

    The code checks the Bernoulli formula by brute force over all binary test channels, runs Blahut–Arimoto at β=ln⁡9\beta = \ln 9, and evaluates the linear-Gaussian VAE in closed form. SciPy computes I(X;X^)I(X; \hat X) as KL(p(x,x^) ∥ p(x) p(x^))\mathrm{KL}(p(x, \hat x)\,\|\,p(x)\,p(\hat x)).

    import numpy as np
    from scipy.stats import entropy
    
    # 1. R(D) of a Bernoulli(0.3) source by brute force over all binary test channels.
    #    a = q(x̂=1 | x=0), b = q(x̂=0 | x=1) on a grid; I(X; X̂) = KL(joint || product of marginals).
    p1 = 0.3
    a, b = np.meshgrid(np.linspace(0, 1, 1001), np.linspace(0, 1, 1001))
    joint = np.stack([(1 - p1) * (1 - a), (1 - p1) * a, p1 * b, p1 * (1 - b)])   # (x, x̂) = 00, 01, 10, 11
    out1 = joint[1] + joint[3]                                                   # P(x̂ = 1)
    prod = np.stack([(1 - p1) * (1 - out1), (1 - p1) * out1, p1 * (1 - out1), p1 * out1])
    info_bits = entropy(joint, prod, axis=0, base=2)
    dist = joint[1] + joint[2]                                                   # P(x̂ != x)
    Hb = lambda x: entropy([x, 1 - x], base=2)
    for D in [0.05, 0.1, 0.2]:
        print(D, info_bits[dist <= D].min().round(3), round(Hb(p1) - Hb(D), 3))
    # 0.05 0.595 0.595
    # 0.1 0.412 0.412
    # 0.2 0.159 0.159
    
    # 2. Blahut-Arimoto for the same source at beta = ln 9.
    px, d = np.array([0.7, 0.3]), 1.0 - np.eye(2)
    beta, q = np.log(9), np.full((2, 2), 0.5)
    for _ in range(500):
        r = px @ q                                   # output marginal r(x̂)
        q = r * np.exp(-beta * d)                    # Gibbs form, then normalize each row
        q /= q.sum(axis=1, keepdims=True)
    r = px @ q
    I = np.sum(px[:, None] * q * np.log2(q / r))
    print(q.round(4).tolist(), round(I, 4), round(np.sum(px[:, None] * q * d), 4))
    # [[0.9643, 0.0357], [0.25, 0.75]] 0.4123 0.1
    
    # 3. Linear-Gaussian "VAE" on X ~ N(0, 1): encoder z = a x + s eps, prior N(0, 1).
    for a_, s_ in [(0.8, 0.6), (0.8, 0.3)]:
        v = a_**2 + s_**2
        rate = 0.5 * (v - 1 - np.log(s_**2))         # E_x KL(N(a x, s^2) || N(0, 1))
        mi = 0.5 * np.log(v / s_**2)                 # I(X; Z) = h(Z) - h(Z | X)
        mse = s_**2 / v                              # best linear decoder x̂ = (a / v) z
        print(f"rate {rate:.3f}  I {mi:.3f}  1/2 ln(1/MSE) {0.5 * np.log(1 / mse):.3f}  nats")
    # rate 0.511  I 0.511  1/2 ln(1/MSE) 0.511  nats    (a^2 + s^2 = 1: on the curve)
    # rate 1.069  I 1.047  1/2 ln(1/MSE) 1.047  nats    (rate = I + KL(q(z) || p(z)))
    

    Part 3: measured by I(X;Z)I(X; Z), a linear-Gaussian encoder with the best decoder sits exactly on the Gaussian curve 12ln⁡(σ2/D)\frac12\ln(\sigma^2/D). The VAE rate adds KL(q(z) ∥ p(z))\mathrm{KL}(q(z)\,\|\,p(z)), which is zero only when a2+s2=1a^2 + s^2 = 1.

    6. Where it shows up #

    • Learned compression. End-to-end image codecs (Ballé et al., 2017; with a hyperprior, 2018) minimize R+λDR + \lambda D, with the rate given by a learned entropy model and arithmetic coding. Neural codecs for video, audio (neural audio codecs with residual vector quantization) and scientific fields follow the same recipe.
    • VAEs and latent diffusion. β-VAEs move along the curve; free bits set a floor on the rate per latent dimension to avoid collapse. The first-stage autoencoder of a latent diffusion model uses a very small KL weight: a high rate, so details survive, and the diffusion model then learns the distribution of the latents.
    • Quantization. A uniform quantizer with step Δ\Delta has MSE about Δ2/12\Delta^2/12 at high resolution. Each extra bit halves Δ\Delta (for a fixed range) and divides the error by 4. Going from 8 to 4 bits per weight at a fixed range multiplies the error by 44=2564^4 = 256. Post-training quantization decides where to spend bits for the smallest output error: a rate–distortion problem, often solved layer by layer.
    • Transform coding. JPEG uses the DCT, an approximation of PCA for images, then spends more bits on the large low-frequency coefficients: reverse water-filling in practice.
    • ML for science. Lossy compressors for climate, weather and seismic archives (error-bounded SZ and ZFP, or neural codecs) are compared by bits per value against error. Reverse water-filling explains why coding in principal components (EOFs of a climate field) works.
    • Representations. Variational IB is used as a regularizer for classifiers and for robustness. Rate and distortion curves are a useful way to compare representation learners.

    7. Common mistakes #

    • Mixing up R(D)R(D) and capacity. R(D)R(D) minimizes II over channels for a fixed source. Capacity maximizes II over inputs for a fixed channel.
    • Using Hb(p)−Hb(D)H_b(p) - H_b(D) beyond D=min⁡(p,1−p)D = \min(p, 1 - p). There R(D)=0R(D) = 0; the formula would give a wrong, often negative, value. The same holds for the Gaussian formula when D>σ2D > \sigma^2.
    • Units. BA's slope −β-\beta is in nats per unit of distortion when II is in nats. Convert RR to bits at the end.
    • Mixing up the β's. In BA and the IB, a large β\beta means a high rate; in the β-VAE, a large β\beta means a low rate.
    • Reading the β-VAE rate as I(X;Z)I(X; Z). It is an upper bound; the gap is KL(q(z) ∥ p(z))\mathrm{KL}(q(z)\,\|\,p(z)).
    • Comparing VAEs by the ELBO alone. Equal ELBOs can hide very different (R,D)(R, D) pairs, including R=0R = 0.
    • Expecting a scalar quantizer to reach R(D)R(D). For a Gaussian at high rate, even with ideal entropy coding, it stays 0.254 bits per sample (1.53 dB) above the curve. The bound needs coding over long blocks (vector quantization).
    • IB with a deterministic network. For a continuous XX and an injective deterministic T=g(X)T = g(X), I(X;T)I(X; T) is infinite. A finite estimate comes from the estimator, not from the network.

    8. Check yourself #

    1. A fair coin, Hamming distortion, 0.25 bits per flip. What is the smallest error rate? What does store-or-guess reach?
      AnswerSolve 1−Hb(D)=0.251 - H_b(D) = 0.25, so Hb(D)=0.75H_b(D) = 0.75 and D=0.2145D = 0.2145. Store-or-guess: 1−2D=0.251 - 2D = 0.25 gives D=0.375D = 0.375.
    2. A Gaussian source with σ2=4\sigma^2 = 4 and squared error. What MSE can you reach with 3 bits per sample?
      AnswerD=σ22−2R=4⋅2−6=116=0.0625D = \sigma^2 2^{-2R} = 4 \cdot 2^{-6} = \frac1{16} = 0.0625.
    3. Why is R(D)R(D) convex?
      AnswerMix the optimal channels for D1D_1 and D2D_2 with weights λ\lambda and 1−λ1 - \lambda. The distortion is linear in the channel, so the mixture meets λD1+(1−λ)D2\lambda D_1 + (1-\lambda)D_2. I(X;X^)I(X; \hat X) is convex in the channel for a fixed source, so R(λD1+(1−λ)D2)≤λR(D1)+(1−λ)R(D2)R(\lambda D_1 + (1 - \lambda)D_2) \le \lambda R(D_1) + (1 - \lambda)R(D_2).
    4. Three independent Gaussian components have variances 4,1,0.254, 1, 0.25. With the water level θ=0.5\theta = 0.5, give each DiD_i, each rate and the totals.
      AnswerDi=min⁡(0.5,λi)=0.5,0.5,0.25D_i = \min(0.5, \lambda_i) = 0.5, 0.5, 0.25. Rates 12log⁡2(4/0.5)=1.5\frac12\log_2(4/0.5) = 1.5, 12log⁡2(1/0.5)=0.5\frac12\log_2(1/0.5) = 0.5, and 0 bits. Total R=2R = 2 bits for D=1.25D = 1.25. The third component is not sent.
    5. Prove Ex KL(q(z∣x) ∥ p(z))=Iq(X;Z)+KL(q(z) ∥ p(z))\mathbb{E}_x\,\mathrm{KL}(q(z \mid x)\,\|\,p(z)) = I_q(X; Z) + \mathrm{KL}(q(z)\,\|\,p(z)) with q(z)=Ex q(z∣x)q(z) = \mathbb{E}_x\,q(z \mid x).
      AnswerWrite log⁡q(z∣x)p(z)=log⁡q(z∣x)q(z)+log⁡q(z)p(z)\log\frac{q(z\mid x)}{p(z)} = \log\frac{q(z\mid x)}{q(z)} + \log\frac{q(z)}{p(z)} and take the expectation over pdata(x) q(z∣x)p_{\text{data}}(x)\,q(z \mid x). The first term gives Iq(X;Z)I_q(X; Z). In the second term zz has marginal q(z)q(z), so it gives KL(q(z) ∥ p(z))\mathrm{KL}(q(z)\,\|\,p(z)).
    6. A β-VAE with β≥1\beta \ge 1 and a powerful autoregressive decoder. What can happen, and why?
      AnswerPosterior collapse: the decoder can model p(x)p(x) without zz, so the optimum can set q(z∣x)=p(z)q(z \mid x) = p(z), which gives R=0R = 0 with no loss in DD. The code then carries no information. β<1\beta < 1, free bits or a weaker decoder push the rate up.
    Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
    1. Define the rate–distortion function R(D)R(D).

    2. What is R(D)R(D) for a Bernoulli(pp) source with Hamming distortion?

    3. What is R(D)R(D) for a Gaussian N(0,σ2)\mathcal N(0, \sigma^2) source with squared error?

    4. By what factor does one extra bit per sample reduce the smallest MSE of a Gaussian source?

    5. Compute R(D)R(D) for a fair coin at D=0.11D = 0.11.

    6. How does reverse water-filling share bits among independent Gaussian components?

    7. What are the two steps of the Blahut–Arimoto algorithm?

    8. Write the information bottleneck objective.

    9. Why is the β-VAE rate an upper bound on I(X;Z)I(X;Z)?

    10. In a β-VAE, what does a larger β\beta do?

    Open the review →

    9. Interview angle #

    • "What is the rate–distortion function? How is it different from channel capacity?" The minimum of I(X;X^)I(X; \hat X) over channels that meet the distortion budget; capacity maximizes II over inputs for a fixed channel.
    • "How many bits per sample does a Gaussian signal need at an SNR of 30 dB?" σ2/D=1000\sigma^2/D = 1000, so R=12log⁡21000=4.98R = \frac12\log_2 1000 = 4.98 bits.
    • "Why does a β-VAE with β>1\beta > 1 give blurrier reconstructions?" It pays more for rate, so it moves to a point with lower rate and higher distortion.
    • "What is posterior collapse in rate–distortion language?" The point R=0R = 0: the code carries no information, and the decoder alone models the data.
    • "What is the information bottleneck?" min⁡I(X;T)−βI(T;Y)\min I(X;T) - \beta I(T;Y): rate–distortion with the distortion KL(p(y∣x) ∥ p(y∣t))\mathrm{KL}(p(y \mid x)\,\|\,p(y \mid t)). Mention that the "compression phase" claim is disputed.
    • "Why do codecs transform the data before quantizing?" In decorrelated components, reverse water-filling gives the bits to high-variance components and drops the rest.

    10. Practice #

    The notebook for this lesson runs in Colab. It has five exercises, each with a check cell and a folded solution:

    1. Brute-force R(D)R(D) of a Bernoulli source over binary test channels on a grid, compared with Hb(p)−Hb(D)H_b(p) - H_b(D).
    2. blahut_arimoto(p_x, distortion, beta), then trace the whole curve with a sweep over β\beta.
    3. Gaussian R(D)R(D) and reverse water-filling on the PCA spectrum of the load_digits data set.
    4. A linear-Gaussian "VAE": rate, I(X;Z)I(X; Z) and MSE in closed form for several encoders, placed on the R(D)R(D) plane.
    5. Uniform scalar quantization of a Gaussian: entropy of the quantized values against MSE, compared with R(D)R(D) (the gap of about 0.25 bits at high rate).

    11. Watch and read #

    Rate–distortion as minimal mutual information, the Gaussian case, and the information bottleneck.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The Gaussian R(D) and reverse water-filling, from the point of view of image coding.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    A visual introduction to VAEs, including the β-VAE and its trade-off between reconstruction and the KL term.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    The information bottleneck view of deep learning, by its author; present it as one view, not a settled fact (see section 3.6).
    Open on YouTube · the player loads from youtube-nocookie.com when you press play