Rate-Distortion Theory

Lossy compression: the best rate achievable at a given distortion. The math behind JPEG and MP3.

Rate-Distortion Theory

Lossy compression trades a little accuracy for far fewer bits. Rate-distortion theory finds the best possible trade: the fewest bits per sample for a given amount of error.

The Gaussian R(D) Curve

Drag the operating point along the curve. The rate shoots up as distortion nears zero and reaches zero at D = σ², where you just send the mean.

For a Gaussian source N(0, σ²) with squared-error distortion, R(D) = (1/2) log₂(σ²/D) for D ≤ σ², and 0 otherwise. Drag along the curve to pick an operating point.

jump to rate:
rate R
1.000 bits
distortion D
0.2500
vs raw 16 bits
16.0× smaller

At D = 0 the curve diverges — perfect reconstruction means perfect coding, which for a continuous source needs infinitely many bits per sample. This is the lossless “Shannon entropy” corner of rate-distortion. Slide right and the curve falls fast: doubling the tolerable distortion saves exactly half a bit per sample, which is why modest distortion budgets enable enormous compression ratios.

Go deeper:The math objects

Lossless coding answers the question “how few bits do I need to recover the source exactly?” The answer is the entropy H(X). Most of the world, though, does not need exact recovery. A photograph that's a fraction of a percent off pixel-by-pixel is still the same photograph; an audio signal off by a tenth of a decibel is still the same song. Lossy compression — JPEG, MP3, MPEG, every modern codec — trades a small, controlled amount of fidelity for a large reduction in bits.

Rate-distortion theory is the mathematics of that trade-off. You fix a distortion measure d(x, x̂) — typically squared error — and a tolerable average distortion D. The rate-distortion function is the smallest rate R achievable at that distortion:

R(D) = minq(x̂|x) : E[d(X,X̂)] ≤ D  I(X; X̂)

The minimum is over all conditional distributions q(x̂ | x) that meet the distortion budget; the objective is the mutual information between source and reconstruction. Lossless source coding is exactly the special case D = 0, where R(0) recovers H(X). For a Gaussian source N(0, σ²) under squared-error distortion the answer collapses to a single line:

R(D) = ½ log₂(σ² / D),  0 < D ≤ σ²;  R(D) = 0,  D > σ².

That single formula is enough to derive the half-bit rule of thumb every codec engineer carries around: doubling your tolerable distortion saves you exactly half a bit per sample.

  • Distortion measure d(x, x̂): a non-negative function on source × reconstruction pairs. Squared error (x − x̂)² is the canonical choice; Hamming distance is the workhorse for discrete sources.
  • Rate-distortion function R(D): the infimum of rates achievable at average distortion ≤ D. Always non-increasing and convex; tends to H(X) as D → 0 (discrete sources) or to ∞ (continuous sources); hits 0 at some finite Dmax.
  • Test channel q(x̂ | x): the conditional distribution that achieves the minimum. For a Gaussian source the optimal channel is itself Gaussian and easiest to write backwards: x = x̂ + N(0, D), with x̂ ~ N(0, σ²−D). The minimum is reached at the boundary where E[d(X, X̂)] = D exactly.
  • Lossless coding as a special case: setting D = 0 recovers Shannon's source-coding theorem, R(0) = H(X). Every entropy bound you have already met is a rate-distortion bound at zero distortion.
  • Operational meaning: Shannon's rate-distortion theorem says that for any δ > 0 and any rate R > R(D), there exists a code (operating on long blocks of source symbols) that achieves average distortion ≤ D + δ. Below R(D), no code can. R(D) is both the best possible rate and an achievable one.

Vector Quantization

Pick a source and a number of centres k, and let Lloyd's algorithm (k-means) place them. Sending a centre's index costs log₂ k bits, so each k gives one point on an empirical R(D) curve.
source:
rate
3.000 bits
distortion (MSE)
0.01852
codebook size
8
empirical R(D) frontier — swept over k

Lloyd's algorithm — better known as k-means — finds a set of k centres so the average squared distance from each sample to its nearest centre is locally minimised. The rate is log₂ k bits per sample because you only have to send the index of the chosen centre. As k grows, rate rises and distortion falls — this is rate-distortion in discrete form. Sweep the slider and watch your operating point trace the empirical R(D) curve below.

Transform Coding (Tiny JPEG)

Lower the quality to keep fewer DCT coefficients in each 8×8 block. Watch the rate fall, the distortion rise, and the error map show where detail is lost.

A small grayscale image is split into 8×8 blocks. Each block is run through a 2D DCT, then only the lowest-frequency coefficients are kept (in zig-zag order, as JPEG does). Drop the quality and you save bits at the cost of distortion — exactly rate-distortion in practice.

Original
Reconstructed
13 / 64 coefficients
Distortion (per pixel)
error magnitude
coeffs kept
13 / 64
rate
1.63 bits / pixel
distortion (MSE)
15.4
PSNR
36.3 dB
vs 8-bit raw
4.9× smaller
block size
8 × 8 DCT

The DCT concentrates the energy of natural images in a few low-frequency coefficients — the upper-left of each 8×8 block. Dropping the rest barely changes the picture but slashes the bit budget. The error map on the right shows where the distortion lives: edges and texture, where the high-frequency content was. JPEG, MP3, and most modern codecs are elaborate variations on this single move.

Go deeper:Practical codecs
  • Practical codecs: JPEG, MP3, AAC, MPEG, H.264, and friends are all approximations to R(D) for the relevant source. They diverge from the theoretical optimum in two ways — their distortion measure is perceptual, not squared error, and they use a bounded number of operations per symbol — but the shape of the trade-off is the same.

Key takeaways

  • R(D) is the fewest bits per symbol that reconstruct the source within distortion D.
  • For a Gaussian source, R(D) = ½ log₂(σ²/D): doubling the distortion saves half a bit.
  • Lossless coding is the D = 0 case: R(0) = H(X).
  • JPEG and MP3 approximate R(D) by keeping a few low-frequency coefficients.

Spot a mistake or have an idea?

Search