Module contents
Lesson 9 of 19Core 100 min

Discrete channels and capacity

Model noisy communication with a discrete memoryless channel, derive classical capacities, and compute capacity using convex optimization and Blahut–Arimoto.

After this lesson you can

  • Compute capacities of binary symmetric, erasure, and symmetric channels.
  • Prove mutual information concave in input and convex in the fixed-input channel.
  • Derive the capacity KKT conditions.
  • Implement Blahut–Arimoto with upper and lower bounds.
  • Interpret capacity as information radius.

Before you start

Motivation: communicating despite noise

A bit travels through a wire, radio wave, disk surface, or memory cell and does not always arrive unchanged. Suppose each bit flips independently with probability ε=0.11\varepsilon = 0.11. This binary symmetric channel is the simplest noise model, and the question is both naive and precise: how many bits of information can be sent reliably on average per channel use?

The first answer is repetition. Send each bit nn times and let the receiver take a majority vote. Error falls quickly, but so does rate, 1/n1/n bits per use. The next cell quantifies it.

[ ]Repetition code versus capacityBrowser
from math import comb, log2

eps = 0.11
h = -eps * log2(eps) - (1 - eps) * log2(1 - eps)
print(f"canal binario simétrico, eps = {eps}: C = 1 - h2(eps) = {1 - h:.4f} bits por uso")

def error_repeticion(n, eps):
    """Probabilidad de que la mayoría de n copias (n impar) llegue equivocada."""
    return sum(comb(n, k) * eps**k * (1 - eps) ** (n - k) for k in range((n + 1) // 2, n + 1))

print("  n    tasa 1/n    error por bit")
for n in [1, 3, 5, 11, 21, 31, 51]:
    print(f"{n:3d}   {1 / n:8.4f}   {error_repeticion(n, eps):.2e}")

n = 1
while error_repeticion(n, eps) > 1e-6:
    n += 2
print(f"para bajar de 1e-6 hacen falta n = {n} copias: tasa {1 / n:.3f} bits por uso, un {1 / n / (1 - h):.1%} de C")

To achieve error 10−610^{-6} per bit requires 25 copies and reduces rate to 0.040.04 bits per use. This seems the inevitable price of reliability: more safety, less information. Shannon proved in 1948 that it is not. Codes exist whose error tends to zero at a fixed positive rate arbitrarily close to a number depending only on the channel, its capacity. Here it is C=0.5001C = 0.5001 bits per use, about twelve times the repetition-code rate above. The theorem is the subject of lesson 10. This lesson builds what it needs and what makes the result useful: the channel model, capacity definition, exact classical capacities, tractable mathematical structure (a convex problem), and an algorithm with guarantees.

“Channel” is more general than a wire. It is any process corrupting a variable without complete recovery:

  • Noisy labels. If an annotator changes true class according to a transition matrix, that matrix is a channel, and information each label retains about the true class never exceeds capacity.
  • Privacy mechanisms. A randomized mechanism publishing a noisy sensitive datum is a channel; its leakage is bounded by capacity (revisited in module 30).
  • Bottlenecks. A quantizer, sensor, or information-discarding network layer is a channel. Lesson 19 uses channels to describe what a representation should retain.

Blahut–Arimoto, the capacity algorithm, is a canonical example of alternating maximization with guarantees and recurs in rate–distortion theory (lesson 14) and the iterative bottleneck. Unless stated otherwise, log⁡\log is base-2 logarithm and information is measured in bits.

The discrete memoryless channel

A channel has input alphabet X\mathcal{X}, output alphabet Y\mathcal{Y} (both finite here), and a probabilistic rule for what output each input produces.

If the sender uses input distribution p(x)p(x), the joint distribution is p(x) W(y∣x)p(x)\,W(y \mid x) and output is the linear combination of rows

q(y)=∑xp(x) W(y∣x),es decir,q=p W=∑xp(x) Wx.q(y) = \sum_{x} p(x)\, W(y \mid x), \qquad \text{es decir,}\quad q = p\,\mat{W} = \sum_x p(x)\, W_x .

This gives a useful geometric interpretation. Each input xx is a point WxW_x in the output-distribution simplex, and a channel is a set of ∣X∣\abs{\mathcal{X}} points in that simplex. Noise is how close the points are: identical rows make those inputs indistinguishable to the receiver. Choosing pp chooses a point qq within the rows’ convex hull.

The channels used here are (rows are inputs):

ChannelParameterMatrix W\mat{W}Outputs
Binary symmetric, BSC(ε)\mathrm{BSC}(\varepsilon)ε\varepsilon[1−εεε1−ε]\begin{bmatrix} 1-\varepsilon & \varepsilon \\ \varepsilon & 1-\varepsilon \end{bmatrix}{0,1}\{0, 1\}
Erasure, BEC(α)\mathrm{BEC}(\alpha)α\alpha[1−αα00α1−α]\begin{bmatrix} 1-\alpha & \alpha & 0 \\ 0 & \alpha & 1-\alpha \end{bmatrix}{0,e,1}\{0, \mathrm{e}, 1\}
Z, Z(δ)\mathrm{Z}(\delta)δ\delta[10δ1−δ]\begin{bmatrix} 1 & 0 \\ \delta & 1-\delta \end{bmatrix}{0,1}\{0, 1\}
Noisy typewriter26 letterseach letter outputs itself or the next with probability 12\tfrac1226 letters

In the erasure channel the receiver knows which positions are lost (output e\mathrm{e}), unlike the symmetric channel where flipped positions are unknown. In the Z channel 00 is never corrupted and 11 arrives as 00 with probability δ\delta: it models, for example, an optical detector that sometimes misses light but never confuses darkness with light.

Recall from lesson 3 that mutual information between input and output has three equivalent forms, the third governing everything here:

I(X;Y)=H(Y)−H(Y∣X)=∑x,yp(x)W(y∣x)log⁡W(y∣x)q(y)=∑xp(x) KL⁡(Wx ∥ q).I(X;Y) = H(Y) - H(Y \mid X) = \sum_{x, y} p(x) W(y \mid x) \log \frac{W(y \mid x)}{q(y)} = \sum_{x} p(x)\, \KL\big(W_x \,\|\, q\big).

The last equality is the KL chain rule applied to p(x)W(y∣x)p(x)W(y \mid x) versus product p(x)q(y)p(x)q(y): mutual information is the average divergence between each channel row and mean output. Rows unlike the mean output (inputs easily identified by the receiver) contribute most information. Write I(p,W)I(p, \mat{W}) to emphasize dependence and KL⁡(Wx ∥ q)\KL(W_x\,\|\,q) for divergence of row xx.

Capacity: maximize over the input

The channel is given, not chosen. The sender controls how to use it, namely input distribution pp (in practice, code design). Capacity is the best attainable value.

Here CC is a definition: a maximum of information. That it is also the largest communication rate with vanishing error (operational capacity) is the next lesson’s theorem. We can already check the result makes sense: it cannot exceed what fits in input or output and is zero only for a useless channel.

Proof

For every pp, I(X;Y)=H(X)−H(X∣Y)≤H(X)≤log⁡∣X∣I(X;Y) = H(X) - H(X \mid Y) \le H(X) \le \log\abs{\mathcal{X}} and I(X;Y)=H(Y)−H(Y∣X)≤H(Y)≤log⁡∣Y∣I(X;Y) = H(Y) - H(Y \mid X) \le H(Y) \le \log\abs{\mathcal{Y}}, since conditional entropies are nonnegative. This upper-bounds CC, and I≥0I \ge 0 gives C≥0C \ge 0.

If all rows equal rr, then q=∑xp(x)r=rq = \sum_x p(x) r = r for every pp and I=∑xp(x)KL⁡(r ∥ r)=0I = \sum_x p(x)\KL(r\,\|\,r) = 0, so C=0C = 0. Conversely, if two rows Wx≠Wx′W_x \ne W_{x'} differ, take pp uniform on {x,x′}\{x, x'\}: output is q=12(Wx+Wx′)q = \tfrac12(W_x + W_{x'}) and I=12KL⁡(Wx ∥ q)+12KL⁡(Wx′ ∥ q)I = \tfrac12\KL(W_x\,\|\,q) + \tfrac12\KL(W_{x'}\,\|\,q). If both terms vanished, Gibbs’ inequality would force Wx=q=Wx′W_x = q = W_{x'}, contrary to assumption. Thus I>0I > 0 and C>0C > 0.

∎

Before calculating, explore a binary channel. For each channel the figure plots II against p=P(X=1)p = \Pr(X = 1) and marks the maximum.

InteractiveCapacity is the maximum of I(X;Y)
X = 0p = 0.80X = 1p = 0.20Y = 0q = 0.73Y = 1q = 0.27band width = p(x) · W(y | x)
  • I(p)I(p)
  • capacity CC and p∗p^*
Channel
0.11
0.200
I(X;Y)I(X;Y) for this pp0.336 bits
H(Y)H(Y)0.836 bits
H(Y∣X)H(Y \mid X)0.500 bits
Capacity C=max⁡pIC = \max_p I0.5001 bits
Optimal input p∗p^*0.500
Loss with uniform input0.0000 bits
Closed form (0.5001)1−h2(ε)1-h_2(\varepsilon)
Symmetric channel: the maximum is at the uniform input, p∗=1/2p^* = 1/2.
Left: probability flow through the channel; node height is p(x)p(x) or q(y)q(y) and band thickness is p(x)W(y∣x)p(x)W(y \mid x). Right: the I(p)I(p) curve and its maximum, capacity. Start with the symmetric channel and ε=0.11\varepsilon = 0.11, move pp, and check that the maximum is at p=1/2p = 1/2. Enable ‘Decompose’ to see I=H(Y)−H(Y∣X)I = H(Y) - H(Y \mid X): why is one curve a line? Switch to Z: where is the maximum now? How much does uniform input lose? For the asymmetric channel set W(1∣0)W(1 \mid 0) and W(0∣1)W(0 \mid 1) to 0.50.5, then set symmetric ε\varepsilon to 11.

What to take from the figure and the following proofs:

  1. The curve is concave and has a unique maximum. At p=0p = 0 and p=1p = 1 it is zero: deterministic input communicates nothing because the receiver already knows what arrived. Concavity is proved below and makes the problem tractable.
  2. H(Y)H(Y) is a dome and H(Y∣X)H(Y \mid X) a line. H(Y∣X)=∑xp(x)H(Wx)H(Y \mid X) = \sum_x p(x) H(W_x) is linear in pp because each row’s entropy is independent of pp. In the symmetric channel the line is horizontal (H(Wx)=h2(ε)H(W_x) = h_2(\varepsilon) for both rows), and the maximum of II matches the dome’s at p=1/2p = 1/2. In the Z channel rows have different entropies (row 00 has zero), so the line tilts and the maximum shifts. With δ=0.5\delta = 0.5 it lies at p∗=0.4p^* = 0.4.
  3. Uniform input is not always optimal. For Z with δ=0.5\delta = 0.5, uniform transmits 0.31130.3113 bits and optimal 0.32190.3219. The difference is small (3%3\%), but distinguishes a capacity-achieving code from one that is not.
  4. A channel with ε=1\varepsilon = 1 has maximum capacity. A channel always flipping a bit loses nothing: the receiver flips back. Capacity is 1−h2(ε)1 - h_2(\varepsilon), symmetric in ε↔1−ε\varepsilon \leftrightarrow 1 - \varepsilon, and vanishes at ε=1/2\varepsilon = 1/2, where output is a coin independent of input.

Capacity is additive under extension

Before formulas, a property justifying “bits per use.” Using the channel nn times, even with correlated inputs, yields at most nn times capacity.

Proof

Let p(xn)p(x^n) be any joint input distribution. Memorylessness gives p(yn∣xn)=∏iW(yi∣xi)p(y^n \mid x^n) = \prod_i W(y_i \mid x_i) and, by the entropy chain rule, H(Yn∣Xn)=∑iH(Yi∣Yi−1,Xn)=∑iH(Yi∣Xi)H(Y^n \mid X^n) = \sum_i H(Y_i \mid Y^{i-1}, X^n) = \sum_i H(Y_i \mid X_i), because given XiX_i symbol YiY_i is independent of everything else. Also H(Yn)≤∑iH(Yi)H(Y^n) \le \sum_i H(Y_i). Subtracting gives I(Xn;Yn)≤∑iI(Xi;Yi)≤nCI(X^n; Y^n) \le \sum_i I(X_i; Y_i) \le nC. Equality is achieved by XiX_i independent and identically distributed according to an optimal p∗p^*.

∎

Thus using the channel nn times cannot exceed nCnC, regardless of input correlation: correlation does not help with independent noise. Lesson 10’s theorem also says nCnC is achievable with vanishing error.

Closed-form capacities

Using I=H(Y)−H(Y∣X)I = H(Y) - H(Y \mid X), classical channel capacities take a few lines. The common idea is to upper-bound H(Y)H(Y) and show uniform input attains it.

Proof

For each input, WxW_x is a distribution on two symbols with probabilities {ε,1−ε}\{\varepsilon, 1 - \varepsilon\}, so H(Y∣X)=h2(ε)H(Y \mid X) = h_2(\varepsilon) regardless of pp. Then I=H(Y)−h2(ε)≤1−h2(ε)I = H(Y) - h_2(\varepsilon) \le 1 - h_2(\varepsilon) because YY is binary. With uniform pp output is q=(12,12)q = (\tfrac12, \tfrac12) and H(Y)=1H(Y) = 1: the bound is attained.

∎

With ε=0.11\varepsilon = 0.11, h2(0.11)=0.4999h_2(0.11) = 0.4999 and C=0.5001C = 0.5001 bits. Their near equality is a numerical coincidence at this ε\varepsilon, not an identity: C=1−h2(ε)C = 1 - h_2(\varepsilon), not h2(ε)h_2(\varepsilon).

Proof

Let E=1[Y=e]E = \ind[Y = \mathrm{e}] indicate erasure. With probability α\alpha, independently of XX, input is erased; otherwise Y=XY = X. Since EE is a function of YY, H(Y)=H(Y,E)=H(E)+H(Y∣E)=h2(α)+(1−α) H(X)H(Y) = H(Y, E) = H(E) + H(Y \mid E) = h_2(\alpha) + (1 - \alpha)\,H(X): given E=1E = 1 output is deterministic, and given E=0E = 0 it is XX. Also H(Y∣X)=h2(α)H(Y \mid X) = h_2(\alpha). Subtraction yields I(X;Y)=(1−α) H(X)≤1−αI(X;Y) = (1-\alpha)\,H(X) \le 1 - \alpha, with equality for uniform XX.

∎

The result reads cleanly: of 100100 symbols, 100(1−α)100(1 - \alpha) arrive intact, each carrying at most one bit. Capacity is exactly the surviving fraction, as though the sender knew in advance which would be erased and used all survivors for data. With α=0.3\alpha = 0.3 it is 0.70.7 bits per use.

Symmetric channels

The symmetric-channel argument used only two properties: every row has equal entropy and uniform input yields uniform output. A broad class satisfies them.

Proof

Rows are permutations, so H(Wx)=H(r)H(W_x) = H(r) for every xx and H(Y∣X)=H(r)H(Y \mid X) = H(r) for any pp. Thus I≤log⁡∣Y∣−H(r)I \le \log\abs{\mathcal{Y}} - H(r). With uniform pp, q(y)=1∣X∣∑xW(y∣x)q(y) = \frac{1}{\abs{\mathcal{X}}}\sum_x W(y \mid x) is column yy‘s sum divided by ∣X∣\abs{\mathcal{X}}. All column sums agree and the total is ∣X∣\abs{\mathcal{X}}, so each sum is ∣X∣/∣Y∣\abs{\mathcal{X}}/\abs{\mathcal{Y}} and qq is uniform: H(Y)=log⁡∣Y∣H(Y) = \log\abs{\mathcal{Y}} and the bound is attained.

∎

The Z channel: uniform input is not optimal

The Z channel is not symmetric (rows are not permutations) and shows uniform input can fail. Let p=P(X=1)p = \Pr(X = 1). Then P(Y=1)=p(1−δ)\Pr(Y = 1) = p(1 - \delta), H(Y∣X)=p h2(δ)H(Y \mid X) = p\,h_2(\delta) (only row 11 has uncertainty), and

I(p)=h2(p(1−δ))−p h2(δ).I(p) = h_2\big(p(1-\delta)\big) - p\,h_2(\delta).

This function is concave, so set its derivative to zero. With y=p(1−δ)y = p(1-\delta) obtain (1−δ) h2′(y)=h2(δ)(1-\delta)\,h_2'(y) = h_2(\delta), and since h2′(y)=log⁡1−yyh_2'(y) = \log\frac{1-y}{y},

log⁡1−yy=h2(δ)1−δ=:t⟹y=11+2t,p∗=y1−δ.\log\frac{1-y}{y} = \frac{h_2(\delta)}{1-\delta} =: t \quad\Longrightarrow\quad y = \frac{1}{1 + 2^{t}}, \qquad p^* = \frac{y}{1-\delta}.

For capacity use h2(y)=−log⁡(1−y)+ylog⁡1−yy=−log⁡(1−y)+y th_2(y) = -\log(1-y) + y\log\frac{1-y}{y} = -\log(1-y) + y\,t and p∗h2(δ)=y tp^* h_2(\delta) = y\,t (because p∗h2(δ)=y1−δh2(δ)=ytp^* h_2(\delta) = \frac{y}{1-\delta} h_2(\delta) = y t). The two terms containing ytyt cancel, leaving

C=−log⁡(1−y)=log⁡(1+2−t)=log⁡2 ⁣(1+2−h2(δ)/(1−δ)).C = -\log(1 - y) = \log\big(1 + 2^{-t}\big) = \log_2\!\Big(1 + 2^{-h_2(\delta)/(1-\delta)}\Big).

With δ=12\delta = \tfrac12: t=2t = 2, y=0.2y = 0.2, p∗=0.4p^* = 0.4, and C=log⁡254=0.3219C = \log_2\tfrac54 = 0.3219 bits, versus I(12)=h2(14)−12=0.3113I(\tfrac12) = h_2(\tfrac14) - \tfrac12 = 0.3113 under uniform input. p∗p^* is always less than 12\tfrac12 and, when δ→1\delta \to 1, tends to 1/e≈0.3681/e \approx 0.368. Intuitively 11 is unreliable and used less than half the time; but not abandoned, because arriving 11 certifies that 11 was sent, and this unambiguous signal carries the most information.

Concavity and convexity: a convex optimization problem

The figure’s curve is concave. This general fact structures what follows.

Proof

(1) Write I=H(Y)−H(Y∣X)I = H(Y) - H(Y \mid X). Output q=p Wq = p\,\mat{W} is linear in pp. Entropy is concave because H(q)=log⁡∣Y∣−KL⁡(q ∥ u)H(q) = \log\abs{\mathcal{Y}} - \KL(q\,\|\,u) with uniform uu and divergence is convex in its first argument. Composition of a concave function with a linear map is concave, so p↦H(p W)p \mapsto H(p\,\mat{W}) is concave. The second term H(Y∣X)=∑xp(x)H(Wx)H(Y \mid X) = \sum_x p(x) H(W_x) is linear in pp. Concave minus linear is concave.

(2) Use form I=∑xp(x) KL⁡(Wx ∥ q)I = \sum_x p(x)\,\KL(W_x\,\|\,q). Let W1,W2\mat{W}^{1}, \mat{W}^{2} be two channels and Wλ=λW1+(1−λ)W2\mat{W}^\lambda = \lambda\mat{W}^{1} + (1-\lambda)\mat{W}^{2} their rowwise mixture. Each mixed row is Wxλ=λWx1+(1−λ)Wx2W^\lambda_x = \lambda W^1_x + (1-\lambda)W^2_x and mixed output qλ=λq1+(1−λ)q2q^\lambda = \lambda q^1 + (1-\lambda) q^2, with qi=p Wiq^i = p\,\mat{W}^i. By joint convexity of divergence,

KL⁡(Wxλ ∥ qλ)≤λ KL⁡(Wx1 ∥ q1)+(1−λ) KL⁡(Wx2 ∥ q2).\KL\big(W^\lambda_x \,\|\, q^\lambda\big) \le \lambda\,\KL\big(W^1_x \,\|\, q^1\big) + (1-\lambda)\,\KL\big(W^2_x \,\|\, q^2\big).

Multiplying by p(x)p(x) and summing over xx yields I(p,Wλ)≤λ I(p,W1)+(1−λ) I(p,W2)I(p, \mat{W}^\lambda) \le \lambda\, I(p, \mat{W}^1) + (1-\lambda)\, I(p, \mat{W}^2).

∎

Part two implies capacity C(W)=max⁡pI(p,W)C(\mat{W}) = \max_p I(p, \mat{W}) is a maximum of functions convex in W\mat{W} and therefore convex in the channel. Mixing two channels (a coin chooses one without the receiver knowing) never gives more capacity than their mean capacity. For example, mixing BSC(0.1)\mathrm{BSC}(0.1) and BSC(0.4)\mathrm{BSC}(0.4) equally gives BSC(0.25)\mathrm{BSC}(0.25), with C=0.1887C = 0.1887, below mean capacity (0.5310+0.0290)/2=0.2800(0.5310 + 0.0290)/2 = 0.2800.

Part one matters for computation. Maximizing a concave function over the simplex, a convex set, is a convex optimization problem. Three consequences follow:

  • Every local maximum is global; initialization is not a concern.
  • KKT conditions are necessary and sufficient (no constraint qualification is needed because constraints are linear).
  • Optimal inputs form a convex set. Even if there are several, optimal output is unique. If p1,p2p_1, p_2 were optimal with outputs q1≠q2q_1 \ne q_2, mean input pˉ=12(p1+p2)\bar p = \tfrac12(p_1 + p_2) would have output qˉ=12(q1+q2)\bar q = \tfrac12(q_1 + q_2) and, since HH is strictly concave, H(qˉ)>12(H(q1)+H(q2))H(\bar q) > \tfrac12\big(H(q_1) + H(q_2)\big); with H(Y∣X)H(Y \mid X) linear this yields I(pˉ)>CI(\bar p) > C, a contradiction.

Optimality conditions and information radius

Now characterize the maximum, with a clean result and geometric interpretation. First the gradient.

Proof

Differentiate I=∑xp(x)∑yW(y∣x)log⁡W(y∣x)q(y)I = \sum_{x}p(x)\sum_{y} W(y \mid x)\log\frac{W(y \mid x)}{q(y)} with respect to p(x′)p(x'): the term where x=x′x = x' contributes ∑yW(y∣x′)log⁡W(y∣x′)q(y)=KL⁡(Wx′ ∥ q)\sum_y W(y \mid x')\log\frac{W(y \mid x')}{q(y)} = \KL(W_{x'}\,\|\,q), and dependence of q(y)q(y) on p(x′)p(x') (which is W(y∣x′)W(y \mid x')) contributes −log⁡e∑xp(x)∑yW(y∣x)W(y∣x′)q(y)-\log e \sum_{x}p(x)\sum_y W(y \mid x)\frac{W(y \mid x')}{q(y)}. Since ∑xp(x)W(y∣x)=q(y)\sum_x p(x)W(y \mid x) = q(y) this simplifies to −log⁡e∑yW(y∣x′)=−log⁡e-\log e\sum_y W(y \mid x') = -\log e.

∎

Two identities do the rest. The first, the compensation identity, relates mean divergence to an arbitrary point q′q' to mutual information: for every pp and q′q',

∑xp(x) KL⁡(Wx ∥ q′)=I(p,W)+KL⁡(q ∥ q′),q=p W.\sum_x p(x)\,\KL(W_x\,\|\,q') = I(p, \mat{W}) + \KL(q\,\|\,q'), \qquad q = p\,\mat{W}.

Substitute log⁡W(y∣x)q′(y)=log⁡W(y∣x)q(y)+log⁡q(y)q′(y)\log\frac{W(y \mid x)}{q'(y)} = \log\frac{W(y \mid x)}{q(y)} + \log\frac{q(y)}{q'(y)}: the first term gives II and the second, after summing over xx, KL⁡(q ∥ q′)\KL(q\,\|\,q'). The latter divergence is nonnegative (Gibbs), so I(p,W)=min⁡q′∑xp(x)KL⁡(Wx ∥ q′)I(p, \mat{W}) = \min_{q'} \sum_x p(x)\KL(W_x\,\|\,q'): true output qq minimizes mean divergence. The second identity is trivial: a weighted mean is at most the maximum, ∑xp(x) KL⁡(Wx ∥ q′)≤max⁡xKL⁡(Wx ∥ q′)\sum_x p(x)\,\KL(W_x\,\|\,q') \le \max_x \KL(W_x\,\|\,q').

Proof

(1) ⇒ (2). Maximize a concave function on the simplex. Lagrangian L(p,λ,μ)=I(p)−λ(∑xp(x)−1)+∑xμxp(x)\mathcal{L}(p, \lambda, \mu) = I(p) - \lambda(\sum_x p(x) - 1) + \sum_x \mu_x p(x) has, by the gradient lemma, stationarity KL⁡(Wx ∥ q∗)−log⁡e−λ+μx=0\KL(W_x\,\|\,q^*) - \log e - \lambda + \mu_x = 0, with μx≥0\mu_x \ge 0 and μxp∗(x)=0\mu_x p^*(x) = 0 (complementary slackness). For p∗(x)>0p^*(x) > 0, μx=0\mu_x = 0 and KL⁡(Wx ∥ q∗)=λ+log⁡e=:c\KL(W_x\,\|\,q^*) = \lambda + \log e =: c; for p∗(x)=0p^*(x) = 0, μx≥0\mu_x \ge 0 gives KL⁡(Wx ∥ q∗)≤c\KL(W_x\,\|\,q^*) \le c. Averaging with weights p∗p^* yields I(p∗)=∑xp∗(x)KL⁡(Wx ∥ q∗)=cI(p^*) = \sum_x p^*(x)\KL(W_x\,\|\,q^*) = c, hence c=Cc = C. (If KL⁡(Wx ∥ q∗)=∞\KL(W_x\,\|\,q^*) = \infty for some xx, the same calculation yields directional derivative +∞+\infty when moving mass to xx and p∗p^* would not be optimal.)

(2) ⇒ (3) is immediate: cc is the maximum divergence and by the previous average equals I(p∗)I(p^*).

(3) ⇒ (1). For any pp, the compensation identity with q′=q∗q' = q^* gives I(p)≤∑xp(x)KL⁡(Wx ∥ q∗)≤max⁡xKL⁡(Wx ∥ q∗)=I(p∗)I(p) \le \sum_x p(x)\KL(W_x\,\|\,q^*) \le \max_x \KL(W_x\,\|\,q^*) = I(p^*). Thus p∗p^* is optimal.

Radius. For any qq, C=max⁡pI(p)≤max⁡p∑xp(x)KL⁡(Wx ∥ q)=max⁡xKL⁡(Wx ∥ q)C = \max_p I(p) \le \max_p \sum_x p(x)\KL(W_x\,\|\,q) = \max_x \KL(W_x\,\|\,q), and q=q∗q = q^* achieves equality by (3): C=min⁡qmax⁡xKL⁡(Wx ∥ q)C = \min_q \max_x \KL(W_x\,\|\,q). If another q′q' also achieves maximum CC, compensation applied to p∗p^* gives ∑xp∗(x)KL⁡(Wx ∥ q′)=C+KL⁡(q∗ ∥ q′)\sum_x p^*(x)\KL(W_x\,\|\,q') = C + \KL(q^*\,\|\,q'), and the left side is at most max⁡xKL⁡(Wx ∥ q′)=C\max_x \KL(W_x\,\|\,q') = C. Hence KL⁡(q∗ ∥ q′)≤0\KL(q^*\,\|\,q') \le 0 and by Gibbs q′=q∗q' = q^*.

∎

Condition (2) resembles “all active players are indifferent”: at optimum all used inputs transmit the same information per symbol, KL⁡(Wx ∥ q∗)=C\KL(W_x\,\|\,q^*) = C, and unused ones would transmit less. If an input could transmit more than CC per symbol, it would be worth assigning more mass. For example, in the Z channel with δ=12\delta = \tfrac12, optimum p∗=(0.6,0.4)p^* = (0.6, 0.4) yields q∗=(0.8,0.2)q^* = (0.8, 0.2) and

KL⁡(W0 ∥ q∗)=log⁡10.8=0.3219,KL⁡(W1 ∥ q∗)=12log⁡0.50.8+12log⁡0.50.2=0.3219,\KL(W_0\,\|\,q^*) = \log\tfrac{1}{0.8} = 0.3219, \qquad \KL(W_1\,\|\,q^*) = \tfrac12\log\tfrac{0.5}{0.8} + \tfrac12\log\tfrac{0.5}{0.2} = 0.3219,

equal to each other and CC, while under uniform q=(0.75,0.25)q = (0.75, 0.25) they are 0.41500.4150 and 0.20750.2075, unequal: input 00 “yields more” and should be used more.

Information radius

The second statement is geometric. Each row WxW_x is a point of the output simplex and KL⁡(Wx ∥ q)\KL(W_x\,\|\,q) acts as a “distance” from point WxW_x to center qq. Then max⁡xKL⁡(Wx ∥ q)\max_x \KL(W_x\,\|\,q) is the radius of the smallest “ball” centered at qq containing every row, and capacity is the smallest possible radius, analogous to the minimum enclosing ball. Rows touching its boundary are used inputs, center q∗q^* is optimal output, and q∗q^* lies in the convex hull of used rows because it is ∑xp∗(x)Wx\sum_x p^*(x) W_x. Since the hull lies in a simplex of dimension ∣Y∣−1\abs{\mathcal{Y}} - 1, Carathéodory’s theorem guarantees an optimal input using at most ∣Y∣\abs{\mathcal{Y}} symbols, however many channel inputs exist.

InteractiveCapacity as information radius
D(Wx ∥ q′)=rD(W_x\,\|\,q') = r for each rowregion {q′:max⁡xD≤r}\{q' : \max_x D \le r\}q∗q^* (the center)Large row = input used (p∗>0p^* > 0)
Number of inputs
Radius max⁡xD(Wx ∥ q)\max_x D(W_x\,\|\,q)0.7013 bits
Capacity CC (minimum radius)0.4075 bits
Excess over CC0.2938 bits
D(Wx1 ∥ q)D(W_{x_1}\,\|\,q), p1∗=0.377p^*_1 = 0.3770.701 bits
D(Wx2 ∥ q)D(W_{x_2}\,\|\,q), p2∗=0.305p^*_2 = 0.3050.127 bits
D(Wx3 ∥ q)D(W_{x_3}\,\|\,q), p3∗=0.318p^*_3 = 0.3180.577 bits
D(Wx4 ∥ q)D(W_{x_4}\,\|\,q), p4∗=0.000p^*_4 = 0.0000.215 bits
The limiting row is x1x_1: its contour passes through qq. Move qq closer to it and it will decrease, but the others will increase. The minimum of the maximum is C=0.407C = 0.407.
Channel rows (colored points) and qq (magenta) lie in the output-distribution simplex. For each row the curve is where KL⁡(Wx ∥ q′)=r\KL(W_x \,\|\, q') = r, with r=max⁡xKL⁡(Wx ∥ q)r = \max_x \KL(W_x \,\|\, q): qq lies on the controlling row's curve. Shading marks centers q′q' with radius ≤r\le r. Drag qq to reduce radius: when does it stop falling? Press ‘Move qq to center’ and observe the region shrink to a point, large-row curves pass through it together, and it remains inside the small-row curve. Move rows (with 2 inputs q∗q^* lies on their segment; with 4 only some are used), then switch to 3.

Three points to observe:

  • The figure draws the ball’s dual image. Row WxW_x lies in the radius-rr ball centered at qq exactly when qq lies inside curve {q′:KL⁡(Wx ∥ q′)=r}\{q' : \KL(W_x\,\|\,q') = r\} around the row. Valid centers are the intersection of these regions (shading), and minimum radius is rr when the intersection becomes a point. The curves are not circles: they stretch toward low row mass. The row is the first argument: divergence measures surprise of qq when data come from the row.
  • Only boundary rows count. A row strictly inside the minimum ball (the small one in the figure, with p∗=0p^* = 0, whose curve contains q∗q^*) can move slightly without changing capacity. A “blurred” or redundant input does not help because it lies within the radius already fixed by others.
  • It is a minimum-of-the-maximum problem, resembling a game. The sender chooses pp to maximize information; the “adversary” chooses qq to minimize divergence attributable to the worst input. At equilibrium (p∗,q∗p^*, q^*) neither gains by moving: a saddle point of ∑xp(x)KL⁡(Wx ∥ q)\sum_x p(x)\KL(W_x\,\|\,q).

The characterization provides certificates. For any pp, I(p)≤CI(p) \le C (lower bound on CC); for any qq, max⁡xKL⁡(Wx ∥ q)≥C\max_x\KL(W_x\,\|\,q) \ge C (upper bound). If bounds nearly agree, we know we are done. The next algorithm exploits this.

The Blahut–Arimoto algorithm

Computing CC maximizes a concave function over a simplex, so any optimizer could be used. Blahut and Arimoto independently observed in 1972 that it admits alternating maximization with closed-form steps. Introduce auxiliary variable φ(x∣y)\varphi(x \mid y), a “reverse channel” (a distribution over inputs for each output yy), and functional

J(p,φ)=∑x,yp(x) W(y∣x) log⁡φ(x∣y)p(x).J(p, \varphi) = \sum_{x, y} p(x)\,W(y \mid x)\,\log\frac{\varphi(x \mid y)}{p(x)} .
Proof

(1) Verify I(p)−J(p,φ)=∑yq(y) KL⁡(φp(⋅∣y) ∥ φ(⋅∣y))≥0I(p) - J(p, \varphi) = \sum_y q(y)\,\KL\big(\varphi_p(\cdot \mid y)\,\|\,\varphi(\cdot \mid y)\big) \ge 0, with equality only if φ=φp\varphi = \varphi_p at every output with q(y)>0q(y) > 0 (Gibbs).

(2) Rewrite J=∑xp(x)[log⁡r(x)−log⁡p(x)]=log⁡∑x′r(x′)−KL⁡(p ∥ r~)J = \sum_x p(x)\big[\log r(x) - \log p(x)\big] = \log\sum_{x'} r(x') - \KL\big(p\,\|\,\tilde r\big) with r~=r/∑r\tilde r = r/\sum r. The final term is nonnegative and vanishes at p=r~p = \tilde r.

∎

Since max⁡φJ(p,φ)=I(p)\max_\varphi J(p, \varphi) = I(p), capacity is C=max⁡p,φJ(p,φ)C = \max_{p, \varphi} J(p, \varphi) and can be maximized by alternating variables with exact block maximization (block coordinate descent, here ascent). Starting from pkp_k, the best φ\varphi is φk=φpk\varphi_k = \varphi_{p_k}, and then log⁡φk(x∣y)=log⁡pk(x)+log⁡W(y∣x)−log⁡qk(y)\log\varphi_k(x \mid y) = \log p_k(x) + \log W(y \mid x) - \log q_k(y), so ∑yW(y∣x)log⁡φk(x∣y)=log⁡pk(x)+KL⁡(Wx ∥ qk)\sum_y W(y \mid x)\log\varphi_k(x \mid y) = \log p_k(x) + \KL(W_x\,\|\,q_k) and r(x)=pk(x) 2KL⁡(Wx ∥ qk)r(x) = p_k(x)\,2^{\KL(W_x\,\|\,q_k)}. The algorithm follows:

This multiplicative update multiplies each input by 2Dk(x)2^{D_k(x)} and renormalizes: pk(x)p_k(x) is multiplied by factor 2Dk(x)−Lk2^{D_k(x) - L_k}. Inputs with Dk(x)>LkD_k(x) > L_k gain mass and those below lose it. Threshold LkL_k is an exponential average of Dk(x)D_k(x) and by Jensen is slightly above arithmetic mean ∑xpk(x)Dk(x)=I(pk)\sum_x p_k(x)D_k(x) = I(p_k). A fixed point requires D(x)D(x) constant where p(x)>0p(x) > 0: KKT equality, but not the inequality off support (every simplex vertex is a fixed point because zero mass is never regained). Thus start with full support.

Proof

(1) With φk=φpk\varphi_k = \varphi_{p_k} we have J(pk,φk)=I(pk)J(p_k, \varphi_k) = I(p_k). The pp step maximizes J(⋅,φk)J(\cdot, \varphi_k) and by the lemma equals J(pk+1,φk)=Lk≥J(pk,φk)=I(pk)J(p_{k+1}, \varphi_k) = L_k \ge J(p_k, \varphi_k) = I(p_k). The φ\varphi step gives I(pk+1)=J(pk+1,φk+1)≥J(pk+1,φk)=LkI(p_{k+1}) = J(p_{k+1}, \varphi_{k+1}) \ge J(p_{k+1}, \varphi_k) = L_k. Also I≤CI \le C, and Uk≥CU_k \ge C by information radius. Lk≤I(pk+1)≤Lk+1L_k \le I(p_{k+1}) \le L_{k+1} gives monotonicity of LkL_k.

(2) Let p∗p^* be optimal. Since p0p_0 has full support, every pkp_k does too and KL⁡(p∗ ∥ pk)\KL(p^*\,\|\,p_k) is finite. Then

KL⁡(p∗ ∥ pk+1)−KL⁡(p∗ ∥ pk)=∑xp∗(x)log⁡pk(x)pk+1(x)=Lk−∑xp∗(x)Dk(x).\KL(p^*\,\|\,p_{k+1}) - \KL(p^*\,\|\,p_k) = \sum_x p^*(x)\log\frac{p_k(x)}{p_{k+1}(x)} = L_k - \sum_x p^*(x) D_k(x).

By compensation, ∑xp∗(x)Dk(x)=I(p∗)+KL⁡(q∗ ∥ qk)≥C\sum_x p^*(x)D_k(x) = I(p^*) + \KL(q^*\,\|\,q_k) \ge C, so the difference is ≤Lk−C\le L_k - C, namely C−Lk≤KL⁡(p∗ ∥ pk)−KL⁡(p∗ ∥ pk+1)C - L_k \le \KL(p^*\,\|\,p_k) - \KL(p^*\,\|\,p_{k+1}). Summing from 00 to n−1n-1 telescopes: ∑k<n(C−Lk)≤KL⁡(p∗ ∥ p0)≤log⁡∣X∣\sum_{k<n}(C - L_k) \le \KL(p^*\,\|\,p_0) \le \log\abs{\mathcal{X}}. Since LkL_k is nondecreasing, n (C−Ln−1)≤log⁡∣X∣n\,(C - L_{n-1}) \le \log\abs{\mathcal{X}}.

(3) By (2), I(pk)→CI(p_k) \to C. Every accumulation point of (pk)(p_k) is optimal, and the optimal output is unique, so qk→q∗q_k \to q^*. If q∗(y)=0q^*(y) = 0 no row has W(y∣x)>0W(y \mid x) > 0 (that row would have KL⁡(Wx ∥ q∗)=∞>C\KL(W_x\,\|\,q^*) = \infty > C, contradicting optimality conditions), so each Dk(x)D_k(x) is continuous at q∗q^* and Dk(x)→KL⁡(Wx ∥ q∗)D_k(x) \to \KL(W_x\,\|\,q^*). Then Uk→max⁡xKL⁡(Wx ∥ q∗)=CU_k \to \max_x \KL(W_x\,\|\,q^*) = C and Lk→CL_k \to C. The rest follows from (1).

∎

Gap Uk−LkU_k - L_k is a certificate: knowing CC is unnecessary to bound distance. This differs from general optimizers stopping on a small step or gradient and is the code’s criterion. The next figure shows the algorithm.

InteractiveBlahut–Arimoto step by step
Input distributions and contours of I(p)I(p)
Ring: p∗p^* (an optimum). Black point and trail: pkp_k. More information toward the center of the contours.
Gap Uk−LkU_k - L_k (logarithmic scale)
Contribution of each input: Dk(x)=D(W(⋅∣x) ∥ qk)D_k(x) = D(W(\cdot\mid x)\,\|\,q_k) versus LkL_k
D − L (bits)−0.18−0.090.090.18D = 0.719x₁p = 0.333×1.13D = 0.359x₂p = 0.333×0.88D = 0.529x₃p = 0.333×0.99
Magenta line = LkL_k. Below each bar: pk(x)p_k(x) and the factor ×2Dk(x)−Lk2^{D_k(x)-L_k} for the next step (greater than 1 if the bar rises).
Bounds on CC at each iteration (bits)
  • Upper bound UkU_k
  • Lower bound LkL_k
  • I(pk)I(p_k)
  • Capacity CC
k = 0
CHANNEL MATRIX (ROW = INPUT, COLUMN = OUTPUT)
Iteration kk0
I(pk)I(p_k)0.5358 bits
Lower bound LkL_k0.5433 bits
Upper bound UkU_k0.7194 bits
Gap Uk−LkU_k - L_k0.1761 bits
Capacity CC0.5562 bits
pkp_k(0.333, 0.333, 0.333)
Steps until gap <10−3< 10^{-3}19
Inputs with bars above LkL_k gain mass at the next step; those below lose it. LkL_k is an exponential mean of the Dk(x)D_k(x), slightly larger than the arithmetic mean I(pk)I(p_k).
A 3-input, 3-output channel (edit the matrix; changing a cell rescales the rest of its row to sum to 1). Upper left: input simplex with I(p)I(p) contours (information rises toward the center): pkp_k climbs toward p∗p^* from draggable p0p_0 (magenta), with gap Uk−LkU_k - L_k below on a log scale. Right: each input's yield Dk(x)D_k(x) relative to bound LkL_k (magenta line is zero): a rising bar gains mass and factor ×2Dk(x)−Lk2^{D_k(x) - L_k} says how much; bounds LkL_k and UkU_k are below. Try ‘An input is abandoned’: what happens to its bar? With ‘Two equal rows’, drag p0p_0: do p∗p^* or CC change?

What to look for:

  • Bars flatten against zero. Initially the three inputs yield differently: some above LkL_k and others below. Each step moves mass toward the former, and LkL_k rises. At optimum used-input bars vanish, all yielding CC and Lk→CL_k \to C: KKT made visible. For the abandoned input, the x2x_2 bar stays below zero (D<CD < C) and its probability approaches 00 geometrically, with factor near 20.2054−0.3329≈0.922^{0.2054 - 0.3329} \approx 0.92 per step.
  • Bounds close. LkL_k rises, UkU_k falls, and CC remains between them. On a log plot the gap falls nearly linearly: convergence is geometric in these examples, much faster than provable bound log⁡∣X∣/(k+1)\log\abs{\mathcal{X}}/(k+1). For the initial asymmetric channel, C=0.5562C = 0.5562 bits, the gap falls below 10−310^{-3} at 19 iterations and 10−910^{-9} at 84.
  • Optimal input can be nonunique; output cannot. With x2x_2 and x3x_3 rows equal, only their combined mass matters; starting points reach different p∗p^* with the same q∗q^* and C=0.4471C = 0.4471.
  • A symmetric channel solves in one step: uniform input is already optimal, the gap is zero, and the algorithm stops.

Channels with input cost

Many real channels have unequal input costs: higher amplitude consumes more energy. Cost b(x)≥0b(x) \ge 0 per symbol and budget β\beta change the problem to

C(β)=max⁡p: Ep[b(X)]≤β I(X;Y).C(\beta) = \max_{p:\ \E_p[b(X)] \le \beta}\ I(X;Y).

Function C(β)C(\beta) is nondecreasing (more budget, more choices) and concave: if p1p_1 and p2p_2 are feasible for β1\beta_1 and β2\beta_2, mixture λp1+(1−λ)p2\lambda p_1 + (1-\lambda)p_2 is feasible for λβ1+(1−λ)β2\lambda\beta_1 + (1-\lambda)\beta_2 and II is concave in pp. With multiplier s≥0s \ge 0 (bits per cost unit), move to max⁡p I(p)−s Ep[b(X)]\max_p\, I(p) - s\,\E_p[b(X)]. Everything above transfers with a small change. KKT becomes KL⁡(Wx ∥ q∗)−s b(x)=c\KL(W_x\,\|\,q^*) - s\,b(x) = c on support and ≤c\le c outside. Blahut–Arimoto retains its structure:

pk+1(x)∝pk(x) 2Dk(x)−s b(x),p_{k+1}(x) \propto p_k(x)\, 2^{D_k(x) - s\,b(x)},

with bounds Lk=log⁡∑xpk(x) 2Dk(x)−s b(x)L_k = \log\sum_x p_k(x)\,2^{D_k(x) - s\,b(x)} and Uk=max⁡x(Dk(x)−s b(x))U_k = \max_x\big(D_k(x) - s\,b(x)\big) on the Lagrangian value. Multiplier ss is slope C′(β)C'(\beta) at budget β=Ep∗[b(X)]\beta = \E_{p^*}[b(X)] attained by the solution (where CC is differentiable; at a corner any intermediate slope), so sweeping ss traces C(β)C(\beta). This anticipates the Gaussian channel in lesson 11, with continuous inputs, cost b(x)=x2b(x) = x^2 (power), and a solution yielding 12log⁡(1+P/N)\tfrac12\log(1 + P/N) and power allocation (water-filling). The code checks a discrete example.

Implementation from scratch

First mutual information with support conventions (0log⁡0=00 \log 0 = 0, without adding ϵ\epsilon) and Blahut–Arimoto with gap stopping. Verify against closed forms for symmetric, erasure, and Z channels, watch bounds close, check KKT for a channel with an abandoned input, and confirm a channel extension has double capacity.

[ ]Blahut–Arimoto from scratch with boundsBrowser
import numpy as np

def info_mutua(p, W):
    """I(X;Y) en bits para la entrada p y el canal W (filas = entradas, filas suman 1)."""
    p = np.asarray(p, float)
    W = np.asarray(W, float)
    q = p @ W
    with np.errstate(divide="ignore", invalid="ignore"):
        t = np.where(W > 0, W * np.log2(W / q), 0.0)     # 0 log 0 = 0: solo cuentan las transiciones posibles
    return float(p @ t.sum(axis=1))

def divergencias_filas(W, q):
    """D(W(.|x) || q) en bits para cada entrada x."""
    with np.errstate(divide="ignore", invalid="ignore"):
        t = np.where(W > 0, W * np.log2(W / q), 0.0)
    return t.sum(axis=1)

def blahut_arimoto(W, tol=1e-9, max_iter=10_000):
    W = np.asarray(W, float)
    if W.ndim != 2 or np.any(W < 0) or not np.allclose(W.sum(axis=1), 1):
        raise ValueError("W debe tener una distribución de probabilidad por fila")
    p = np.full(W.shape[0], 1 / W.shape[0])               # soporte completo
    historia = []
    for k in range(max_iter):
        q = p @ W
        D = divergencias_filas(W, q)
        inf = float(np.log2(np.sum(p * 2**D)))           # cota inferior L_k
        sup = float(D.max())                              # cota superior U_k
        historia.append((inf, sup))
        p = p * 2**D                                      # actualización multiplicativa
        p = p / p.sum()
        if sup - inf < tol:                               # parada por la brecha, no por el cambio en p
            break
    return {"C": (inf + sup) / 2, "p": p, "q": p @ W, "iter": k, "historia": historia}

def h2(x):
    return -x * np.log2(x) - (1 - x) * np.log2(1 - x)

bsc = lambda e: np.array([[1 - e, e], [e, 1 - e]])
bec = lambda a: np.array([[1 - a, a, 0], [0, a, 1 - a]])
zch = lambda d: np.array([[1, 0], [d, 1 - d]])

r = blahut_arimoto(bsc(0.11)); print(f"BSC(0.11): C = {r['C']:.6f}   1 - h2 = {1 - h2(0.11):.6f}   p* = {r['p']}")
r = blahut_arimoto(bec(0.3));  print(f"BEC(0.3):  C = {r['C']:.6f}   1 - alfa = {0.7:.6f}   p* = {r['p']}")
d = 0.5
r = blahut_arimoto(zch(d))
cerrada = np.log2(1 + 2 ** (-h2(d) / (1 - d)))
print(f"Z(0.5):    C = {r['C']:.6f}   cerrada = {cerrada:.6f}   p* = {np.round(r['p'], 4)}   iteraciones = {r['iter']}")
print(f"           I(uniforme) = {info_mutua([.5, .5], zch(d)):.6f}")
for k in [0, 1, 2, 5, 10]:
    inf, sup = r["historia"][k]
    print(f"   k = {k:2d}:  {inf:.6f} <= C <= {sup:.6f}   brecha {sup - inf:.1e}")

# una entrada se abandona: KKT con desigualdad en la tercera fila de la figura
W3 = np.array([[0.6, 0.3, 0.1], [0.5, 0.35, 0.15], [0.1, 0.2, 0.7]])
r = blahut_arimoto(W3)
print("\nentrada abandonada: C =", round(r["C"], 6), " p* =", np.round(r["p"], 4), " iteraciones =", r["iter"])
print("   D(W_x || q*) =", np.round(divergencias_filas(W3, r["q"]), 4), "  (la segunda queda por debajo de C)")

# la extensión de un canal: C(W x W) = 2 C(W), con p* = p* x p*
W2 = np.kron(zch(0.5), zch(0.5))
r2 = blahut_arimoto(W2)
print(f"\nextensión 2ª del Z(0.5): C = {r2['C']:.6f}   2 C = {2 * cerrada:.6f}   p* = {np.round(r2['p'], 4)}   (0.6 x 0.6 = 0.36)")

All three capacities match closed forms to six digits, and Z takes 40 iterations to close the gap below 10−910^{-9}. At k=0k = 0 the gap is 0.10.1 bits and at k=10k = 10 9⋅10−49 \cdot 10^{-4}: roughly one order of magnitude every five steps. With an abandoned input, D(W2 ∥ q∗)=0.2054<C=0.3329D(W_2 \,\|\, q^*) = 0.2054 < C = 0.3329: the KKT inequality. The Z channel’s second extension has capacity 2C2C and optimal input (0.36,0.24,0.24,0.16)(0.36, 0.24, 0.24, 0.16), the product of p∗p^* with itself, as additivity predicts.

Now the theorem’s rate guarantee: C−Lk≤log⁡∣X∣/(k+1)C - L_k \le \log\abs{\mathcal{X}}/(k+1). To check without exact CC use final upper bound UU (at least CC): if the inequality holds there, it also holds with CC. Monotonicity of LkL_k is checked on every random channel.

[ ]Monotonicity and the log|X| / (k+1) bound on random channelsBrowser
import numpy as np

def divergencias_filas(W, q):
    with np.errstate(divide="ignore", invalid="ignore"):
        t = np.where(W > 0, W * np.log2(W / q), 0.0)
    return t.sum(axis=1)

def trayectoria(W, tol=1e-9, max_iter=400):
    p = np.full(W.shape[0], 1 / W.shape[0])
    inf, sup = [], []
    for _ in range(max_iter):
        D = divergencias_filas(W, p @ W)
        inf.append(np.log2(np.sum(p * 2**D)))
        sup.append(D.max())
        if sup[-1] - inf[-1] < tol:
            break
        p = p * 2**D
        p = p / p.sum()
    return np.array(inf), np.array(sup)

rng = np.random.default_rng(0)
peor, monotona, canales = 0.0, True, 60
for _ in range(canales):
    nx, ny = rng.integers(2, 7), rng.integers(2, 7)
    W = rng.dirichlet(np.ones(ny) * 0.5, nx)
    L, U = trayectoria(W)
    cotaC = U[-1]                                  # U_final >= C: si la cota vale con ella, vale con C
    monotona &= bool(np.all(np.diff(L) >= -1e-12))
    for k in [0, 4, 19, 99]:
        if k < len(L):
            peor = max(peor, (cotaC - L[k]) * (k + 1) / np.log2(nx))
print(f"{canales} canales aleatorios: L_k monótona = {monotona}")
print(f"mayor valor de (U_final - L_k) (k+1) / log2|X| = {peor:.3f}   (el teorema exige <= 1)")

The theoretical bound holds with wide margin. It is a sublinear worst-case bound; practical convergence is much faster.

Using libraries

scipy.optimize solves the same problem without exploiting structure. Parameterize input with softmax p=softmax⁡(θ)p = \softmax(\theta) to eliminate the simplex constraint and maximize I(p)I(p) with BFGS. Gradient with respect to θ\theta follows from the lemma: ∂I/∂θ=p⊙(g−p⊤g)\partial I/\partial\theta = p \odot (g - p\T g) with gx=KL⁡(Wx ∥ q)−log⁡eg_x = \KL(W_x\,\|\,q) - \log e. Compare with Blahut–Arimoto on a random 8×88 \times 8 channel, counting function evaluations because Pyodide’s clock is unreliable.

[ ]Capacity with scipy.optimize versus Blahut–ArimotoBrowser
import numpy as np
from scipy.optimize import minimize
from scipy.special import softmax

def divergencias_filas(W, q):
    with np.errstate(divide="ignore", invalid="ignore"):
        t = np.where(W > 0, W * np.log2(W / q), 0.0)
    return t.sum(axis=1)

def info_mutua(p, W):
    return float(p @ divergencias_filas(W, p @ W))

def blahut_arimoto(W, tol=1e-10, max_iter=20_000):
    p = np.full(W.shape[0], 1 / W.shape[0])
    for k in range(max_iter):
        D = divergencias_filas(W, p @ W)
        inf, sup = np.log2(np.sum(p * 2**D)), D.max()
        p = p * 2**D
        p = p / p.sum()
        if sup - inf < tol:
            break
    return (inf + sup) / 2, k + 1

def menos_info(theta, W):
    return -info_mutua(softmax(theta), W)

def menos_info_grad(theta, W):
    p = softmax(theta)
    g = divergencias_filas(W, p @ W) - np.log2(np.e)
    return -(p * (g - p @ g))

rng = np.random.default_rng(3)
W = rng.dirichlet(np.ones(8) * 0.4, 8)
C_ba, n_ba = blahut_arimoto(W)
print(f"Blahut-Arimoto:           C = {C_ba:.10f}   iteraciones = {n_ba}   (con certificado: brecha < 1e-10)")

res = minimize(menos_info, np.zeros(8), args=(W,), jac=menos_info_grad, method="BFGS", options={"gtol": 1e-10})
print(f"BFGS con gradiente:       C = {-res.fun:.10f}   evaluaciones = {res.nfev}   error = {abs(-res.fun - C_ba):.1e}")
p_bfgs = softmax(res.x)
certificado = divergencias_filas(W, p_bfgs @ W).max() - info_mutua(p_bfgs, W)
print(f"   certificado a posteriori para la p de BFGS: max_x D - I(p) = {certificado:.1e}")
res = minimize(menos_info, np.zeros(8), args=(W,), method="BFGS")
print(f"BFGS sin gradiente:       C = {-res.fun:.10f}   evaluaciones = {res.nfev}   error = {abs(-res.fun - C_ba):.1e}")

The result is nuanced. BFGS with analytic gradient needs about 100 evaluations versus over 1000 Blahut–Arimoto iterations on this channel (two of eight inputs are abandoned, and near optimum an abandoned input’s mass decays by factor 2D(x)−C2^{D(x) - C} per step, 0.980.98 for one); without the gradient, about 600. The two BFGS values differ from Blahut–Arimoto by 5⋅10−115 \cdot 10^{-11} and 10−810^{-8}. The fundamental difference is the guarantee. Blahut–Arimoto stops when gap Uk−LkU_k - L_k proves the value is within 10−1010^{-10} of CC; BFGS stops on small gradient without knowing distance. The information-radius certificate works for any pp, including BFGS output: evaluate max⁡xKL⁡(Wx ∥ pW)−I(p)\max_x \KL(W_x\,\|\,p\mat{W}) - I(p), which is worth always doing. Here it is of order 10−710^{-7}, far looser than actual error, because softmax never brings abandoned inputs to zero and gradient barely pushes them. Each method has a place: Blahut–Arimoto is short, robust (no step size or risk of leaving the simplex), and has a built-in certificate; a second-order optimizer may be faster on large channels when the former drags.

Finally, an input-cost example. Four amplitude levels x∈{0,1,2,3}x \in \{0, 1, 2, 3\} with discretized Gaussian noise (standard deviation 0.70.7 levels) and cost b(x)=x2b(x) = x^2, “energy.” Sweep multiplier ss and show curve (β,C(β))(\beta, C(\beta)).

[ ]Input-cost channel: the C(beta) curveBrowser
import numpy as np

def divergencias_filas(W, q):
    with np.errstate(divide="ignore", invalid="ignore"):
        t = np.where(W > 0, W * np.log2(W / q), 0.0)
    return t.sum(axis=1)

def ba_coste(W, b, s, tol=1e-9, max_iter=20_000):
    """max_p I(p) - s E_p[b(X)] por Blahut-Arimoto con coste. Devuelve p, I(p), E[b]."""
    p = np.full(W.shape[0], 1 / W.shape[0])
    for _ in range(max_iter):
        D = divergencias_filas(W, p @ W) - s * b
        inf, sup = np.log2(np.sum(p * 2**D)), D.max()
        p = p * 2**D
        p = p / p.sum()
        if sup - inf < tol:
            break
    I = float(p @ divergencias_filas(W, p @ W))
    return p, I, float(p @ b)

niveles = np.arange(4.0)
W = np.exp(-((niveles[None, :] - niveles[:, None]) ** 2) / (2 * 0.7**2))
W /= W.sum(axis=1, keepdims=True)
b = niveles**2

print(" s (bits/coste)   coste medio   C(beta)      p*")
curva = []
for s in [0, 0.05, 0.1, 0.2, 0.4, 0.8]:
    p, I, coste = ba_coste(W, b, s)
    curva.append((coste, I))
    print(f"     {s:4.2f}         {coste:7.3f}     {I:7.4f}    {np.round(p, 3)}")

curva = sorted(curva)
pend = [(curva[i + 1][1] - curva[i][1]) / (curva[i + 1][0] - curva[i][0]) for i in range(len(curva) - 1)]
print("pendientes de la curva (decrecen: C(beta) es cóncava):", np.round(pend, 3))

With s=0s = 0 (no cost), the solution mainly uses extreme levels 00 and 33, easiest to distinguish, yielding 0.93470.9347 bits at mean cost 4.314.31. Increasing ss reduces both cost and information, but information falls much more slowly: at mean cost 0.700.70 (84% less energy), 0.450.45 bits still get through. Slopes decrease as concavity requires, each between ss values of the two points joined: the multiplier is the slope of C(β)C(\beta).

Common mistakes

Exercises

NumericBinary symmetric channel capacity
Calculate capacity in bits per use of a binary symmetric channel with error probability ε=0.11\varepsilon = 0.11.
NumericErasure channel capacity
An erasure channel erases each symbol with probability α=0.3\alpha = 0.3. What is its capacity in bits per use?
NumericThe Z channel with optimal input
For a Z channel with δ=0.5\delta = 0.5 (0 always arrives correctly and 1 arrives as 0 with probability 0.50.5), what is capacity in bits per use?
NumericA symmetric four-symbol channel
A channel with 4 inputs and 4 outputs delivers the correct input with probability 0.70.7 and each other symbol with probability 0.10.1. What is capacity in bits per use?
NumericThe first upper bound
For Z with δ=0.5\delta = 0.5 and uniform input p0=(0.5,0.5)p_0 = (0.5, 0.5), compute Blahut–Arimoto upper bound U0=max⁡xKL⁡(Wx ∥ q0)U_0 = \max_x \KL(W_x\,\|\,q_0) in bits.
QuizA channel that always errs
What is binary symmetric channel capacity with ε=1\varepsilon = 1 (every bit always flips), and why?
QuizWhere is uniform input optimal?
Mark the channels where uniform input achieves capacity.

More than one answer may be correct.

QuizAn unused input
A 3-input channel has optimum p∗=(0.5,0.5,0)p^* = (0.5, 0.5, 0), optimal output q∗q^*, and capacity CC. What do KKT conditions say about the third input?
QuizWhen to stop Blahut–Arimoto?
Which stopping criterion guarantees returned value within τ\tau of capacity?
ProofMutual information is concave in input
Prove: For fixed channel W\mat{W}, map p↦I(p,W)p \mapsto I(p, \mat{W}) is concave on the input-distribution simplex.
0
Write I(p)=H(Y)−H(Y∣X)I(p) = H(Y) - H(Y \mid X) with Y∼q=p WY \sim q = p\,\mat{W}.

Step 1 of 4. How does H(Y∣X)H(Y \mid X) depend on pp?

ProofBlahut–Arimoto updates
Prove: With J(p,φ)=∑x,yp(x)W(y∣x)log⁡φ(x∣y)p(x)J(p, \varphi) = \sum_{x, y} p(x)W(y \mid x)\log\frac{\varphi(x \mid y)}{p(x)}, each Blahut–Arimoto step is an exact maximization: max⁡φJ(p,φ)=I(p)\max_\varphi J(p, \varphi) = I(p) at φp=p(x)W(y∣x)/q(y)\varphi_p = p(x)W(y \mid x)/q(y), and for fixed φ\varphi the maximum in pp is p(x)∝pk(x) 2KL⁡(Wx∥qk)p(x) \propto p_k(x)\,2^{\KL(W_x\|q_k)} when φ=φpk\varphi = \varphi_{p_k}.
0
Work with q=p Wq = p\,\mat{W} and base-2 logarithms.

Step 1 of 4. For fixed pp, how do you prove φp\varphi_p maximizes JJ?

CodeImplement capacity with Blahut–Arimoto
Implement channel_capacity(W, tol=1e-9, max_iter=20000) with Blahut–Arimoto (in bits). W is the channel matrix (one input per row, rows summing to 1); return (C, p), where C is the midpoint of bounds LkL_k and UkU_k from the last iteration and p the resulting input distribution. Stop when Uk−Lk<U_k - L_k < tol (not on change in p), mask zeros of W (no nan or epsilons), and raise ValueError if rows do not sum to 1. Handle repeated rows, useless inputs, unreachable outputs (zero columns), and zero-capacity channels.
import numpy as np

def channel_capacity(W, tol=1e-9, max_iter=20000):
  """Capacidad (bits) de un canal W por Blahut-Arimoto. Devuelve (C, p)."""
  W = np.asarray(W, dtype=float)
  # tu código: valida W, itera p -> p * 2**D / suma y para con la brecha U - L
  return 0.0, np.zeros(W.shape[0])
Shift+Enter to run

Summary

Key idea
Capacity C=max⁡pI(X;Y)C = \max_p I(X;Y) measures information per use across a noisy channel. Since II is concave in input, computing it is a convex problem with a clean characterization: at optimum all used inputs contribute exactly CC and none more, and CC is information radius min⁡qmax⁡xKL⁡(Wx ∥ q)\min_q\max_x\KL(W_x\,\|\,q). Blahut–Arimoto alternates exact maximizations and provides lower and upper certificates at each step.
  • Channel. Row-stochastic matrix W(y∣x)W(y \mid x); memorylessness means noise acts symbolwise, Wn=∏iWW^n = \prod_i W. Each row is a point in the output simplex.
  • Capacity. C=max⁡pI(X;Y)C = \max_p I(X;Y), with I=H(Y)−H(Y∣X)=∑xp(x)KL⁡(Wx ∥ q)I = H(Y) - H(Y \mid X) = \sum_x p(x)\KL(W_x\,\|\,q). Bounds: 0≤C≤min⁡{log⁡∣X∣,log⁡∣Y∣}0 \le C \le \min\{\log\abs{\mathcal{X}}, \log\abs{\mathcal{Y}}\}; it is additive under extension, max⁡I(Xn;Yn)=nC\max I(X^n;Y^n) = nC. Operational meaning (maximum rate with vanishing error) is lesson 10’s theorem.
  • Closed forms. BSC(ε)\mathrm{BSC}(\varepsilon): 1−h2(ε)1 - h_2(\varepsilon). BEC(α)\mathrm{BEC}(\alpha): 1−α1 - \alpha. Weakly symmetric channels: log⁡∣Y∣−H(r)\log\abs{\mathcal{Y}} - H(r) with uniform input. Z channel: log⁡(1+2−h2(δ)/(1−δ))\log\big(1 + 2^{-h_2(\delta)/(1-\delta)}\big) with p∗≠12p^* \ne \tfrac12.
  • Convexity. II is concave in pp and convex in W\mat{W}; hence C(W)C(\mat{W}) is convex in the channel, every local maximum is global, and optimal output q∗q^* is unique.
  • KKT and radius. ∂I/∂p(x)=KL⁡(Wx ∥ q)−log⁡e\partial I/\partial p(x) = \KL(W_x\,\|\,q) - \log e. Optimal p∗p^* has KL⁡(Wx ∥ q∗)=C\KL(W_x\,\|\,q^*) = C on support and ≤C\le C outside, and C=min⁡qmax⁡xKL⁡(Wx ∥ q)C = \min_q\max_x\KL(W_x\,\|\,q): the smallest KL ball containing rows. An optimal input uses at most ∣Y∣\abs{\mathcal{Y}} symbols.
  • Blahut–Arimoto. pk+1(x)∝pk(x) 2KL⁡(Wx∥qk)p_{k+1}(x) \propto p_k(x)\,2^{\KL(W_x\|q_k)}, with I(pk)≤Lk≤I(pk+1)≤C≤UkI(p_k) \le L_k \le I(p_{k+1}) \le C \le U_k, C−Lk≤log⁡∣X∣/(k+1)C - L_k \le \log\abs{\mathcal{X}}/(k+1) and gap stopping Uk−LkU_k - L_k. It is block ascent on (p,φ)(p, \varphi) with exact maximization per block.
  • With cost. C(β)=max⁡Eb≤βIC(\beta) = \max_{\E b \le \beta} I is concave and nondecreasing; multiplier ss, slope of C(β)C(\beta), enters the update as 2Dk(x)−s b(x)2^{D_k(x) - s\,b(x)}. This anticipates the Gaussian channel.
  • Practice. Mask zeros rather than add epsilons; rows sum to 1 (not columns); stop on gap, not ∥Δp∥\norm{\Delta p}; distinguish bits from nats.