Quiz 2

Information Theory: Entropy, KL Divergence, Mutual Information, and Cross-Entropy

3955 words
20 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Information Theory: Entropy, KL Divergence, Mutual Information, and Cross-Entropy ## 🎯 Learning Objectives - Define entropy and interpret it as a measure of uncertainty - Derive and apply KL divergence for comparing probability distributions - Compute mutual information between random variables - Understand the r...

Information Theory: Entropy, KL Divergence, Mutual Information, and Cross-Entropy

🎯 Learning Objectives

  • Define entropy and interpret it as a measure of uncertainty
  • Derive and apply KL divergence for comparing probability distributions
  • Compute mutual information between random variables
  • Understand the relationship between cross-entropy, KL divergence, and log-likelihood
  • Apply information-theoretic concepts to generative model analysis
  • Explain how information theory connects to ELBO, GAN training, and diffusion models

📋 Prerequisites

  • Probability basics: Random variables, PDF/PMF, expectation
  • Generative Models Overview (Week 1): Likelihood, model distributions
  • Basic calculus: Logarithms, differentiation

1. 📖 Core Content

1.1 Intuition: What is Information?

Information theory answers: "How much information does a random event convey?" An event with low probability carries high information:
  • "The sun rose this morning" — highly probable, low information
  • "An earthquake hit Mumbai this morning" — low probability, high information An event with certainty carries zero information:
  • "A fair coin will land either heads or tails" — 100% certain, 0 bits of information In generative modeling, information theory quantifies:
  • How surprised is the model by new data? (cross-entropy)
  • How different is the learned distribution from the real one? (KL divergence)
  • How much does the input inform the output? (mutual information)

1.2 Self-Information

For an event xx with probability p(x)p(x), the self-information is:
I(x)=logp(x)I(x) = -\log p(x)
The base of the logarithm determines the unit:
  • Base 2: bits (most common in information theory)
  • Base ee: nats (most common in ML, because gradients are easier)
  • Base 10: dits (rare)

Worked Example 1: Computing Self-Information

Fair coin flip (p(heads) = 0.5):
I(heads)=log2(0.5)=log2(21)=1 bitI(\text{heads}) = -\log_2(0.5) = -\log_2(2^{-1}) = 1 \text{ bit}
Loaded coin (p(heads) = 0.95):
I(heads)=log2(0.95)0.07 bitsI(\text{heads}) = -\log_2(0.95) \approx 0.07 \text{ bits} I(tails)=log2(0.05)4.32 bitsI(\text{tails}) = -\log_2(0.05) \approx 4.32 \text{ bits}
The tails outcome carries much more information because it's rare.

1.3 Entropy: Expected Information

Entropy is the average self-information of a random variable:
H(p)=Exp[logp(x)]=xp(x)logp(x)H(p) = \mathbb{E}_{x \sim p}[-\log p(x)] = -\sum_{x} p(x) \log p(x)
For continuous distributions (differential entropy):
H(p)=p(x)logp(x)dxH(p) = -\int p(x) \log p(x) dx

1.3.1 Interpretation

Entropy measures uncertainty or unpredictability:
  • High entropy → Many possible outcomes, roughly equally likely
  • Low entropy → Outcome is fairly predictable

Worked Example 2: Comparing Entropies

Fair coin (p = 0.5):
H=0.5log2(0.5)0.5log2(0.5)=1 bitH = -0.5\log_2(0.5) - 0.5\log_2(0.5) = 1 \text{ bit}
Loaded coin (p = 0.95):
H=0.95log2(0.95)0.05log2(0.05)0.286 bitsH = -0.95\log_2(0.95) - 0.05\log_2(0.05) \approx 0.286 \text{ bits}
4-sided fair die:
H=4×14log2(14)=2 bitsH = -4 \times \frac{1}{4}\log_2(\frac{1}{4}) = 2 \text{ bits}
Uniform over 256 values (like pixel intensities):
H=i=02551256log2(1256)=log2(256)=8 bitsH = -\sum_{i=0}^{255} \frac{1}{256}\log_2(\frac{1}{256}) = \log_2(256) = 8 \text{ bits}
The uniform distribution has maximum entropy; any deviation from uniformity reduces entropy.

1.3.2 Maximum Entropy Principle

Among all distributions with a given mean and variance, the Gaussian distribution has maximum entropy. This is why:
  • Gaussian noise models "maximum ignorance" — it's the least informative noise given first and second moments
  • Diffusion models add Gaussian noise because it's the most entropic (most destructive) noise

1.4 KL Divergence: Measuring Distribution Difference

The Kullback-Leibler (KL) divergence measures how one probability distribution diverges from another:
DKL(pq)=Exp[logp(x)q(x)]=xp(x)logp(x)q(x)D_{KL}(p \| q) = \mathbb{E}_{x \sim p}\left[\log \frac{p(x)}{q(x)}\right] = \sum_x p(x) \log \frac{p(x)}{q(x)}

1.4.1 Key Properties

  1. Non-negativity: DKL(pq)0D_{KL}(p \| q) \geq 0 (Gibbs' inequality). Equality iff p=qp = q almost everywhere.
  2. Not symmetric: DKL(pq)DKL(qp)D_{KL}(p \| q) \neq D_{KL}(q \| p) in general.
  3. Not a metric: Doesn't satisfy symmetry or triangle inequality.

1.4.2 Asymmetry in Practice

Because KL divergence is asymmetric, the direction matters:
  • Forward KL DKL(pq)D_{KL}(p \| q): Average over pp of log(p/q)\log(p/q). This forces q>0q > 0 wherever p>0p > 0. Result: qq tries to cover all modes of pp (mean-seeking).
  • Reverse KL DKL(qp)D_{KL}(q \| p): Average over qq of log(q/p)\log(q/p). This forces qq to place probability mass only where p>0p > 0. Result: qq tries to fit a single mode of pp (mode-seeking).

Worked Example 3: KL Divergence Between Two Gaussians

For two univariate Gaussians p=N(μ1,σ12)p = \mathcal{N}(\mu_1, \sigma_1^2) and q=N(μ2,σ22)q = \mathcal{N}(\mu_2, \sigma_2^2):
DKL(pq)=logσ2σ1+σ12+(μ1μ2)22σ2212D_{KL}(p \| q) = \log\frac{\sigma_2}{\sigma_1} + \frac{\sigma_1^2 + (\mu_1 - \mu_2)^2}{2\sigma_2^2} - \frac{1}{2}
Let p=N(0,1)p = \mathcal{N}(0, 1) and q=N(0.5,1.5)q = \mathcal{N}(0.5, 1.5):
DKL(pq)=log1.51+1+(00.5)22×1.520.5=log(1.5)+1+0.254.50.5D_{KL}(p \| q) = \log\frac{1.5}{1} + \frac{1 + (0 - 0.5)^2}{2 \times 1.5^2} - 0.5 = \log(1.5) + \frac{1 + 0.25}{4.5} - 0.5 =0.405+0.2780.5=0.183 nats= 0.405 + 0.278 - 0.5 = 0.183 \text{ nats}

Worked Example 4: Forward vs Reverse KL for a Bimodal Distribution

Let pp be a bimodal distribution (two peaks: modes at -2 and +2). Let qq be a single Gaussian N(μ,σ2)\mathcal{N}(\mu, \sigma^2). Forward KL DKL(pq)D_{KL}(p \| q):
  • We average over pp, so qq must have support everywhere pp has mass
  • qq will try to cover both modes
  • Optimal qq: μ0\mu \approx 0, σ3\sigma \approx 3 (high variance to cover both peaks, but puts probability mass between the modes where pp has none) Reverse KL DKL(qp)D_{KL}(q \| p):
  • We average over qq, so qq tries to avoid regions where pp is very small
  • Since pp has a valley at 0, qq will choose to model a single mode
  • Optimal qq: either μ2\mu \approx -2, σ1\sigma \approx 1 (left mode) or μ2\mu \approx 2, σ1\sigma \approx 1 (right mode) This explains why:
  • VAEs minimize reverse KL (q(zx)q(z|x) is optimized to avoid areas where p(z)p(z) has low density)
  • Maximum likelihood estimation minimizes forward KL (pθ(x)p_\theta(x) must cover all modes of pdatap_{\text{data}})

1.5 Cross-Entropy

Cross-entropy measures the average number of bits needed to encode data from pp using an optimal code designed for qq:
H(p,q)=Exp[logq(x)]=xp(x)logq(x)H(p, q) = \mathbb{E}_{x \sim p}[-\log q(x)] = -\sum_x p(x) \log q(x)
Relationship to KL divergence:
H(p,q)=H(p)+DKL(pq)H(p, q) = H(p) + D_{KL}(p \| q)
Since H(p)H(p) is constant for a given data distribution, minimizing cross-entropy is equivalent to minimizing KL divergence.

1.5.1 Cross-Entropy Loss in ML

In supervised learning, the cross-entropy loss is:
LCE=1Ni=1Nlogq(y(i)x(i))\mathcal{L}_{CE} = -\frac{1}{N}\sum_{i=1}^N \log q(y^{(i)} | x^{(i)})
where q(yx)q(y|x) is the model's predicted probability for the true class. In generative modeling, the negative log-likelihood (NLL) is exactly the cross-entropy between the data distribution and the model distribution:
NLL=Expdata[logpθ(x)]=H(pdata,pθ)\text{NLL} = -\mathbb{E}_{x \sim p_{\text{data}}}[\log p_\theta(x)] = H(p_{\text{data}}, p_\theta)

1.6 Mutual Information

Mutual information (MI) measures how much knowing one variable tells you about another:
I(X;Y)=DKL(p(x,y)p(x)p(y))=x,yp(x,y)logp(x,y)p(x)p(y)I(X; Y) = D_{KL}(p(x, y) \| p(x)p(y)) = \sum_{x, y} p(x, y) \log \frac{p(x, y)}{p(x)p(y)}
Equivalently:
I(X;Y)=H(X)H(XY)=H(Y)H(YX)I(X; Y) = H(X) - H(X|Y) = H(Y) - H(Y|X)

1.6.1 Interpretation

  • I(X;Y) = 0: X and Y are independent (knowing X tells nothing about Y)
  • I(X;Y) = H(X): Y perfectly predicts X (and vice versa)
  • Higher MI → Stronger dependence between variables

Worked Example 5: Mutual Information for a Noisy Channel

Let XX be the input to a noisy communication channel, and YY be the output:
  • Input: X{0,1}X \in \{0, 1\}, P(X=0)=P(X=1)=0.5P(X=0) = P(X=1) = 0.5
  • Channel: transmits correctly with probability 0.9, flips with probability 0.1 Step 1: Compute H(X)H(X):
H(X)=0.5log2(0.5)0.5log2(0.5)=1 bitH(X) = -0.5\log_2(0.5) - 0.5\log_2(0.5) = 1 \text{ bit}
Step 2: Compute H(XY)H(X|Y):
P(Y=0)=P(X=0)0.9+P(X=1)0.1=0.5P(Y=0) = P(X=0) \cdot 0.9 + P(X=1) \cdot 0.1 = 0.5 P(Y=1)=0.5P(Y=1) = 0.5 P(X=0Y=0)=0.9,P(X=1Y=0)=0.1P(X=0|Y=0) = 0.9, P(X=1|Y=0) = 0.1 H(XY=0)=0.9log2(0.9)0.1log2(0.1)0.469H(X|Y=0) = -0.9\log_2(0.9) - 0.1\log_2(0.1) \approx 0.469 H(XY=1)=0.469 (by symmetry)H(X|Y=1) = 0.469 \text{ (by symmetry)} H(XY)=0.50.469+0.50.469=0.469H(X|Y) = 0.5 \cdot 0.469 + 0.5 \cdot 0.469 = 0.469
Step 3: Mutual information:
I(X;Y)=H(X)H(XY)=10.469=0.531 bitsI(X;Y) = H(X) - H(X|Y) = 1 - 0.469 = 0.531 \text{ bits}
The mutual information is 0.531 bits, which is less than the 1 bit of input entropy because the noisy channel loses some information.

1.7 Applications in Generative Models

1.7.1 ELBO Decomposition

The VAE's evidence lower bound can be written in terms of KL divergence:
logp(x)=DKL(qϕ(zx)pθ(zx))+L(x;θ,ϕ)\log p(x) = D_{KL}(q_\phi(z|x) \| p_\theta(z|x)) + \mathcal{L}(x; \theta, \phi) L(x;θ,ϕ)=Eqϕ(zx)[logpθ(xz)]ReconstructionDKL(qϕ(zx)p(z))KL regularization\mathcal{L}(x; \theta, \phi) = \underbrace{\mathbb{E}_{q_\phi(z|x)}[\log p_\theta(x|z)]}_{\text{Reconstruction}} - \underbrace{D_{KL}(q_\phi(z|x) \| p(z))}_{\text{KL regularization}}
The KL term pushes the approximate posterior qϕ(zx)q_\phi(z|x) toward the prior p(z)p(z), acting as a regularizer. This is reverse KL because we average over qq.

1.7.2 InfoGAN: Maximizing Mutual Information

InfoGAN (Chen et al., 2016) adds a term to the GAN objective to encourage disentangled representations:
minGmaxDV(D,G)λI(c;G(z,c))\min_G \max_D V(D, G) - \lambda I(c; G(z, c))
where cc is a latent code and I(c;G(z,c))I(c; G(z, c)) is the mutual information between cc and the generated image. By maximizing MI, InfoGAN ensures the latent code cc has a meaningful effect on the output (e.g., c1c_1 controls digit identity, c2c_2 controls rotation). In practice, the mutual information is approximated using a variational lower bound:
I(c;G(z,c))ExG(z,c)[logq(cx)]+H(c)I(c; G(z, c)) \geq \mathbb{E}_{x \sim G(z, c)}[\log q(c|x)] + H(c)
where q(cx)q(c|x) is a learned auxiliary distribution that approximates p(cx)p(c|x).

1.7.3 Diffusion Model ELBO

The diffusion model's variational bound can be expressed as:
LDM=t=1TEx0,ϵt[DKL(q(xt1xt,x0)pθ(xt1xt))KL between true posterior and model]\mathcal{L}_{DM} = \sum_{t=1}^T \mathbb{E}_{x_0, \epsilon_t}[\underbrace{D_{KL}(q(x_{t-1}|x_t, x_0) \| p_\theta(x_{t-1}|x_t))}_{\text{KL between true posterior and model}}]
At each timestep, the model learns to match the reverse conditional distribution. The KL between two Gaussians has a closed form, simplifying training.

1.8 Edge Cases & Gotchas

  • KL divergence can be infinite: If q(x)=0q(x) = 0 but p(x)>0p(x) > 0, then DKL(pq)=D_{KL}(p \| q) = \infty. This is why VAEs use reverse KL (where qq is the approximate posterior and we ensure it has broad support).
  • Differential entropy can be negative: Unlike discrete entropy, continuous entropy can be negative (e.g., a very narrow Gaussian has low entropy).
  • Mutual information is bounded: 0I(X;Y)min(H(X),H(Y))0 \leq I(X;Y) \leq \min(H(X), H(Y)).
  • Data processing inequality: Post-processing can't increase information. If XYZX \to Y \to Z, then I(X;Z)I(X;Y)I(X;Z) \leq I(X;Y).

1.9 Why This Matters

Information theory provides the theoretical foundation for nearly every generative model:
ModelKey Information-Theoretic Concept
VAEKL divergence (ELBO), reverse KL for posterior
GAN (InfoGAN)Mutual information for disentanglement
DiffusionKL between Gaussians, entropy of noise
AutoregressiveCross-entropy (NLL) as training loss
EvaluationBits/dim (cross-entropy per dimension)
Normalizing FlowsChange of variables and entropy
Understanding the information-theoretic roots of these losses helps you:
  1. Diagnose training failures (e.g., KL vanishing in VAEs)
  2. Design new model variants (e.g., β-VAE that weights KL)
  3. Choose appropriate evaluation metrics

2. 📐 Key Formulas / Concepts

ConceptFormulaInterpretation
EntropyH(p)=p(x)logp(x)H(p) = -\sum p(x) \log p(x)Average uncertainty
Cross-entropyH(p,q)=p(x)logq(x)H(p, q) = -\sum p(x) \log q(x)Encoding cost using wrong distribution
KL divergence$D_{KL}(p\q) = \sum p(x) \log\frac{p(x)}{q(x)}$
MI$I(X;Y) = H(X) - H(X\Y)$
Relation$H(p, q) = H(p) + D_{KL}(p\q)$
Gaussian KL$D_{KL}(\mathcal{N}_1 \\mathcal{N}_2) = \log\frac{\sigma_2}{\sigma_1} + \frac{\sigma_1^2+(\mu_1-\mu_2)^2}{2\sigma_2^2} - \frac{1}{2}$

3. ⚠️ Common Pitfalls

Pitfall 1: Forgetting KL Divergence is Asymmetric

Mistake: Using DKL(pq)D_{KL}(p \| q) and DKL(qp)D_{KL}(q \| p) interchangeably. Why: KL divergence is not symmetric. The forward KL (pqp\|q) averages over pp; reverse KL (qpq\|p) averages over qq. They have different optimization properties. Correct approach: Always check which distribution you're averaging over. In the VAE ELBO, the KL term is DKL(qϕ(zx)p(z))D_{KL}(q_\phi(z|x) \| p(z)) — reverse KL. In maximum likelihood estimation, we minimize DKL(pdatapθ)D_{KL}(p_{\text{data}} \| p_\theta) — forward KL.

Pitfall 2: Confusing Cross-Entropy with KL Divergence

Mistake: Saying "we minimize KL divergence" when actually minimizing cross-entropy. Why: Cross-entropy loss H(p,q)=plogqH(p, q) = -\sum p \log q is commonly used. Since H(p,q)=H(p)+DKL(pq)H(p, q) = H(p) + D_{KL}(p \| q), minimizing cross-entropy is equivalent to minimizing KL divergence when H(p)H(p) is constant. But the numerical values differ. Correct approach: When computing negative log-likelihood, you're computing cross-entropy, not KL divergence. The two differ by the (unknown) entropy of the data distribution, which is constant during optimization. Report NLL as cross-entropy, but understand it's equivalent to KL for model comparison.

Pitfall 3: Using Bits Instead of Nats

Mistake: Mixing bits and nats in the same formula without converting. Why: log2\log_2 gives bits; ln\ln (or loge\log_e) gives nats. Conversion: 1 nat = log2e1.44\log_2 e \approx 1.44 bits. Correct approach: Be consistent. In ML, nats are standard (natural gradient). In information theory papers, bits are common. When reporting results, specify which unit you're using.

Pitfall 4: Ignoring KL Vanishing in VAEs

Mistake: Not monitoring the KL term during VAE training. Why: The KL term can "vanish" to zero, meaning the approximate posterior qϕ(zx)q_\phi(z|x) equals the prior p(z)p(z) for all xx. This means the latent variable isn't being used — the model has collapsed to an unconditional generation model. Correct approach: Monitor DKL(qϕ(zx)p(z))D_{KL}(q_\phi(z|x) \| p(z)) during training. If it drops near zero, use KL annealing (gradually increase KL weight), β-VAE (increase β to encourage information-rich latent), or free bits (maintain minimum KL per latent dimension).

Pitfall 5: Misinterpreting Mutual Information for High-Dimensional Data

Mistake: Computing MI between two high-dimensional variables without regularization. Why: In high-dimensional spaces, I(X;Y)I(X;Y) is notoriously difficult to estimate because p(x,y)p(x,y) and p(x)p(y)p(x)p(y) require density estimation in high dimensions. Correct approach: Use variational lower bounds (InfoNCE, MINE) for MI estimation, or use lower-dimensional representations (e.g., Inception features) for computing MI between images.

4. 📝 Practice Questions

Q1: Compute the entropy of a 6-sided fair die in bits.
H=i=1616log2(16)=log2(6)2.585 bitsH = -\sum_{i=1}^6 \frac{1}{6}\log_2(\frac{1}{6}) = \log_2(6) \approx 2.585 \text{ bits}
This means on average, it takes about 2.585 bits to encode the outcome of a fair 6-sided die. Q2: Two coins: Coin A is fair (p=0.5p=0.5), Coin B is biased (p=0.99p=0.99). Which has higher entropy and why?
Coin A: H=0.5log2(0.5)0.5log2(0.5)=1.0 bitH = -0.5\log_2(0.5) - 0.5\log_2(0.5) = 1.0 \text{ bit}
Coin B: H=0.99log2(0.99)0.01log2(0.01)0.081 bitsH = -0.99\log_2(0.99) - 0.01\log_2(0.01) \approx 0.081 \text{ bits}
Coin A has higher entropy because its outcome is more uncertain. Coin B is highly predictable (almost always heads), so its entropy is near zero. Q3: Compute DKL(pq)D_{KL}(p \| q) where pp is Bernoulli(0.5) and qq is Bernoulli(0.8).
DKL(pq)=x{0,1}p(x)logp(x)q(x)D_{KL}(p \| q) = \sum_{x \in \{0,1\}} p(x) \log\frac{p(x)}{q(x)}
=0.5log0.50.8+0.5log0.50.2= 0.5 \log\frac{0.5}{0.8} + 0.5 \log\frac{0.5}{0.2}
=0.5log(0.625)+0.5log(2.5)= 0.5 \log(0.625) + 0.5 \log(2.5)
=0.5(0.470)+0.5(0.916)= 0.5(-0.470) + 0.5(0.916)
=0.235+0.458=0.223 nats= -0.235 + 0.458 = 0.223 \text{ nats}
In bits: 0.223×log2(e)0.223×1.440.321 bits0.223 \times \log_2(e) \approx 0.223 \times 1.44 \approx 0.321 \text{ bits} Q4: In the VAE loss function, why does the KL term use DKL(qϕ(zx)p(z))D_{KL}(q_\phi(z|x) \| p(z)) instead of DKL(p(z)qϕ(zx))D_{KL}(p(z) \| q_\phi(z|x))?
The ELBO derivation starts from:
logp(x)=DKL(qϕ(zx)pθ(zx))+L\log p(x) = D_{KL}(q_\phi(z|x) \| p_\theta(z|x)) + \mathcal{L}
where L\mathcal{L} is the ELBO. We want to minimize the KL between qϕ(zx)q_\phi(z|x) and the true posterior pθ(zx)p_\theta(z|x), but we can't compute pθ(zx)p_\theta(z|x) directly. So we rearrange:
L=Eqϕ(zx)[logpθ(xz)]DKL(qϕ(zx)p(z))\mathcal{L} = \mathbb{E}_{q_\phi(z|x)}[\log p_\theta(x|z)] - D_{KL}(q_\phi(z|x) \| p(z))
The KL term is DKL(qϕ(zx)p(z))D_{KL}(q_\phi(z|x) \| p(z)) — we minimize this to make the approximate posterior close to the prior. This is reverse KL because we average over the variational distribution qϕq_\phi.
Using reverse KL means qϕ(zx)q_\phi(z|x) tends to be mode-seeking — it will try to find a single good latent code for each xx rather than covering all possible latent explanations. This is actually desirable: for a given input, we want a compact, informative latent representation.
If we used forward KL DKL(p(z)qϕ(zx))D_{KL}(p(z) \| q_\phi(z|x)) instead, the KL would be -\infty wherever qϕq_\phi assigns zero probability where p(z)>0p(z) > 0, which would force qϕq_\phi to have very broad support for every input — undesirable. Q5: In InfoGAN, the mutual information I(c;G(z,c))I(c; G(z,c)) is maximized. Show how the variational lower bound I(c;x)ExG(z,c)[logq(cx)]+H(c)I(c; x) \geq \mathbb{E}_{x \sim G(z,c)}[\log q(c|x)] + H(c) is derived.
Starting from the definition:
I(c;x)=H(c)H(cx)=H(c)+ExG(z,c)[Ecp(cx)[logp(cx)]]I(c; x) = H(c) - H(c|x) = H(c) + \mathbb{E}_{x \sim G(z,c)}[\mathbb{E}_{c' \sim p(c|x)}[\log p(c'|x)]]
We introduce a variational approximation q(cx)q(c|x) to the true posterior p(cx)p(c|x):
I(c;x)=H(c)+Ex[Ecp(cx)[logp(cx)]]I(c; x) = H(c) + \mathbb{E}_{x}[\mathbb{E}_{c' \sim p(c|x)}[\log p(c'|x)]]
=H(c)+Ex[Ecp(cx)[logq(cx)]+DKL(p(cx)q(cx))]= H(c) + \mathbb{E}_{x}[\mathbb{E}_{c' \sim p(c|x)}[\log q(c'|x)] + D_{KL}(p(c|x) \| q(c|x))]
Since DKL0D_{KL} \geq 0:
I(c;x)H(c)+ExG(z,c)[logq(cx)]I(c; x) \geq H(c) + \mathbb{E}_{x \sim G(z,c)}[\log q(c|x)]
This gives a tractable lower bound on mutual information that we can optimize. q(cx)q(c|x) is an auxiliary network that tries to predict the latent code cc from the generated image xx. Q6: A Gaussian distribution N(0,0.1)\mathcal{N}(0, 0.1) has differential entropy. Compute it.
Differential entropy of a univariate Gaussian:
H(N(μ,σ2))=12ln(2πeσ2)H(\mathcal{N}(\mu, \sigma^2)) = \frac{1}{2}\ln(2\pi e \sigma^2)
For σ2=0.1\sigma^2 = 0.1:
H=12ln(2πe×0.1)=12ln(0.2πe)=12ln(1.708)12×0.536=0.268 natsH = \frac{1}{2}\ln(2\pi e \times 0.1) = \frac{1}{2}\ln(0.2\pi e) = \frac{1}{2}\ln(1.708) \approx \frac{1}{2} \times 0.536 = 0.268 \text{ nats}
This is positive (low entropy for a narrow distribution). For a very narrow Gaussian (σ0\sigma \to 0), differential entropy is -\infty. Q7: Explain why bits/dim is equivalent to cross-entropy per dimension.
Bits/dim measures the average number of bits needed to encode each dimension of the data under the model. For an image of D=H×W×CD = H \times W \times C dimensions:
bits/dim=log2pθ(x)D=1D(log2pθ(x))cross-entropy in bits\text{bits/dim} = -\frac{\log_2 p_\theta(x)}{D} = \frac{1}{D} \cdot \underbrace{(-\log_2 p_\theta(x))}_{\text{cross-entropy in bits}}
This is the cross-entropy between the true data distribution (which places a delta on xx) and the model, normalized by dimensionality.
Bits/dim allows comparison across models trained on the same dataset, regardless of image resolution. A bits/dim of 3.0 means the model compresses each pixel channel (or each data dimension) to 3 bits on average. Q8: XX is uniformly distributed over {1,2,3,4}\{1, 2, 3, 4\}. Y=X2mod4Y = X^2 \mod 4. Compute I(X;Y)I(X; Y).
Step 1: H(X)=log2(4)=2 bitsH(X) = \log_2(4) = 2 \text{ bits}
Step 2: Y=X2mod4Y = X^2 \mod 4:
  • X=1Y=1X=1 \to Y=1
  • X=2Y=0X=2 \to Y=0
  • X=3Y=1X=3 \to Y=1
  • X=4Y=0X=4 \to Y=0
So P(Y=0)=0.5P(Y=0) = 0.5, P(Y=1)=0.5P(Y=1) = 0.5
Step 3: H(Y)=1 bitH(Y) = 1 \text{ bit}
Step 4: P(XY=0)P(X|Y=0): X{2,4}X \in \{2, 4\} equally likely → H(XY=0)=1 bitH(X|Y=0) = 1 \text{ bit} P(XY=1)P(X|Y=1): X{1,3}X \in \{1, 3\} equally likely → H(XY=1)=1 bitH(X|Y=1) = 1 \text{ bit}
H(XY)=0.5×1+0.5×1=1 bitH(X|Y) = 0.5 \times 1 + 0.5 \times 1 = 1 \text{ bit}
Step 5: I(X;Y)=H(X)H(XY)=21=1 bitI(X; Y) = H(X) - H(X|Y) = 2 - 1 = 1 \text{ bit}
Knowing YY reduces the uncertainty about XX from 2 bits to 1 bit — you still don't know whether XX is the smaller or larger value in the pair. Q9: Why does adding noise increase entropy? Use this to explain the forward process in diffusion models.
Adding noise increases entropy because it makes the distribution more uncertain. In the forward diffusion process:
q(xtx0)=N(xt;αˉtx0,(1αˉt)I)q(x_t | x_0) = \mathcal{N}(x_t; \sqrt{\bar{\alpha}_t} x_0, (1-\bar{\alpha}_t)I)
As tt increases (more noise added):
  • αˉt0\bar{\alpha}_t \to 0
  • Mean goes to 0
  • Variance goes to II
The entropy of q(xtx0)q(x_t | x_0) increases from near-zero (at t=0t=0, xtx_t is nearly deterministic given x0x_0) to:
H(q(xT))D2ln(2πe)H(q(x_T)) \approx \frac{D}{2}\ln(2\pi e)
which is the maximum entropy for a DD-dimensional distribution with fixed variance — matching a standard Gaussian N(0,I)\mathcal{N}(0, I).
This increase in entropy is why diffusion models can destroy any data distribution: by gradually adding noise, we wash away the structure until only Gaussian noise remains. Q10: The β\beta-VAE modifies the VAE loss to L=Eqϕ(zx)[logpθ(xz)]βDKL(qϕ(zx)p(z))\mathcal{L} = \mathbb{E}_{q_\phi(z|x)}[\log p_\theta(x|z)] - \beta \cdot D_{KL}(q_\phi(z|x) \| p(z)). Explain why β>1\beta > 1 encourages more disentangled representations.
With β>1\beta > 1, the KL term is weighted more heavily, which pushes each latent dimension's distribution qϕ(zix)q_\phi(z_i|x) to be closer to the prior p(zi)=N(0,1)p(z_i) = \mathcal{N}(0, 1).
For disentanglement, this means:
  1. Factorized prior: The prior p(z)=ip(zi)p(z) = \prod_i p(z_i) is factorized (independent dimensions). By pushing qϕ(zx)q_\phi(z|x) toward p(z)p(z), we encourage the posterior to also be factorized.
  2. Information bottleneck: The higher KL penalty limits the total information that zz can carry about xx. The model must allocate this limited information efficiently, learning to encode only the most salient, independent factors of variation in separate dimensions.
  3. Selective pressure: Dimensions that aren't informative are "turned off" (their KL matches the prior exactly), leaving only the truly informative dimensions active.
However, β>1\beta > 1 also reduces reconstruction quality (the rate-distortion tradeoff). Higher β\beta reduces "rate" (KL) but increases "distortion" (reconstruction error). Finding the right β\beta balances disentanglement with reconstruction fidelity. Q11: Show that maximizing likelihood is equivalent to minimizing the forward KL divergence between the empirical data distribution and the model distribution.
The empirical data distribution is:
p^data(x)=1Ni=1Nδ(xx(i))\hat{p}_{\text{data}}(x) = \frac{1}{N} \sum_{i=1}^N \delta(x - x^{(i)})
where δ\delta is the Dirac delta.
Maximum likelihood estimation maximizes:
1Ni=1Nlogpθ(x(i))=Exp^data[logpθ(x)]\frac{1}{N} \sum_{i=1}^N \log p_\theta(x^{(i)}) = \mathbb{E}_{x \sim \hat{p}_{\text{data}}}[\log p_\theta(x)]
The forward KL divergence between p^data\hat{p}_{\text{data}} and pθp_\theta:
DKL(p^datapθ)=Exp^data[logp^data(x)logpθ(x)]D_{KL}(\hat{p}_{\text{data}} \| p_\theta) = \mathbb{E}_{x \sim \hat{p}_{\text{data}}}[\log \hat{p}_{\text{data}}(x) - \log p_\theta(x)]
=Exp^data[logp^data(x)]constant (entropy of empirical dist)Exp^data[logpθ(x)]log-likelihood= \underbrace{\mathbb{E}_{x \sim \hat{p}_{\text{data}}}[\log \hat{p}_{\text{data}}(x)]}_{\text{constant (entropy of empirical dist)}} - \underbrace{\mathbb{E}_{x \sim \hat{p}_{\text{data}}}[\log p_\theta(x)]}_{\text{log-likelihood}}
Since the first term is constant with respect to θ\theta, minimizing DKLD_{KL} is equivalent to maximizing the log-likelihood.
This is forward KL because we average over p^data\hat{p}_{\text{data}} — the model must assign high probability to every data point, which forces it to cover all modes of the data distribution. Q12: For the KL divergence DKL(pq)D_{KL}(p \| q) where pp is a mixture of two Gaussians and qq is a single Gaussian, sketch the result under forward KL vs reverse KL optimization. Which one would produce a better generative model for image data?
When pp is bimodal (two modes) and qq is a single Gaussian:
Forward KL (DKL(pq)D_{KL}(p \| q) minimized over qq):
  • qq spreads out to cover both modes
  • Result: high-variance Gaussian centered between the modes
  • qq has mass in the middle where pp has none
  • This is "mean-seeking" — it captures the overall spread but not the structure
Reverse KL (DKL(qp)D_{KL}(q \| p) minimized over qq):
  • qq picks one mode and fits it tightly
  • Result: a narrow Gaussian centered on one mode
  • The other mode is completely ignored
  • This is "mode-seeking" or "mode-collapse"
For image data, forward KL is generally preferred because:
  1. Real images have many modes (cats, dogs, cars, etc.)
  2. Forward KL forces the model to cover all modes (better recall)
  3. Spread-out blurry images are better than missing entire categories
However, forward KL tends to produce blurry images (the model averages over plausible outputs). This is why VAEs (trained with forward KL through MLE) produce blurry images, while GANs (which use a different loss) can produce sharp images but may suffer from mode collapse (a reverse-KL-like failure mode).
This also explains why diffusion models (trained with forward KL via NLL) can be slightly blurry with few steps but sharp with enough steps — the iterative refinement allows the model to escape the blurry mean prediction.

5. 🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.