TExcelTAD
Home › Information Theory › Computing Capacity: Blahut-Arimoto

Computing Capacity: Blahut-Arimoto

For a binary input, capacity is a one-dimensional maximization. For larger alphabets we need an algorithm. The Blahut-Arimoto algorithm (1972) computes the capacity of any discrete memoryless channel with simple alternating updates, each of which has a closed form. It is an example of alternating maximization, like the EM algorithm (The EM Algorithm).

The idea

Mutual information can be written as a maximum over an auxiliary "backward channel" Φ(x∣y)\Phi(x \mid y):

I(X;Y)=max⁡Φ∑x,yP(x)Q(y∣x)log⁡2Φ(x∣y)P(x)I(X; Y) = \max_{\Phi} \sum_{x, y} P(x)Q(y \mid x)\log_2 \frac{\Phi(x \mid y)}{P(x)}

with the maximum reached at the true posterior Φ(x∣y)=P(x∣y)\Phi(x \mid y) = P(x \mid y). So capacity is a maximum over two things, PP and Φ\Phi, and we can alternate:

  1. Fix PP, update Φ\Phi: set Φ\Phi to the posterior, Φ(x∣y)∝P(x)Q(y∣x)\Phi(x \mid y) \propto P(x)Q(y \mid x).
  2. Fix Φ\Phi, update PP: P(x)∝exp⁡(∑yQ(y∣x)ln⁡Φ(x∣y))P(x) \propto \exp\left(\sum_y Q(y \mid x)\ln \Phi(x \mid y)\right).

Combining both steps gives the usual form: P(x)←P(x) 2D(x)P(x) \leftarrow P(x)\,2^{D(x)}, normalized, where D(x)=DKL(Q(⋅∣x)∥PY)D(x) = D_{\text{KL}}(Q(\cdot \mid x) \parallel P_Y).

Bounds that tell you when to stop

At every iteration, with D(x)D(x) as above,

∑xP(x)D(x)≤C≤max⁡xD(x)\sum_x P(x)D(x) \le C \le \max_x D(x)

The lower bound is the current I(X;Y)I(X; Y); the upper bound comes from duality. Stop when the gap is below the tolerance.

python · try it yourself
import numpy as np

def blahut_arimoto(Q, tol=1e-9, max_iter=10_000):
    n = Q.shape[0]
    p = np.ones(n) / n
    for it in range(max_iter):
        py = p @ Q
        with np.errstate(divide="ignore", invalid="ignore"):
            D = np.sum(np.where(Q > 0, Q * np.log2(Q / py), 0.0), axis=1)   # KL of each row from P_Y
        lower, upper = float(p @ D), float(D.max())
        if upper - lower < tol:
            break
        p = p * np.exp2(D); p /= p.sum()
    return lower, upper, p, it

Z = np.array([[1.0, 0.0], [0.15, 0.85]])
C_low, C_up, p, it = blahut_arimoto(Z)
print(f"Z channel: {C_low:.6f} <= C <= {C_up:.6f}, input {np.round(p, 4)}, {it} iterations")
T = np.array([[0.8, 0.2, 0.0], [0.1, 0.8, 0.1], [0.0, 0.2, 0.8]])
C_low, C_up, p, it = blahut_arimoto(T)
print(f"ternary:   {C_low:.6f} <= C <= {C_up:.6f}, input {np.round(p, 4)}, {it} iterations")
Z channel: 0.685418 <= C <= 0.685418, input [0.5551 0.4449], 14 iterations
ternary:   0.826916 <= C <= 0.826916, input [0.4299 0.1402 0.4299], 73 iterations

Watching it converge

python · try it yourself
import numpy as np

Q = np.array([[0.6, 0.3, 0.1, 0.0],
              [0.0, 0.5, 0.4, 0.1],
              [0.1, 0.1, 0.1, 0.7],
              [0.25, 0.25, 0.25, 0.25]])          # the last input is useless
p = np.ones(4) / 4
for it in range(1, 41):
    py = p @ Q
    with np.errstate(divide="ignore", invalid="ignore"):
        D = np.sum(np.where(Q > 0, Q * np.log2(Q / py), 0.0), axis=1)
    if it in (1, 2, 5, 10, 20, 40):
        print(f"iter {it:2d}: lower {p @ D:.6f}, upper {D.max():.6f}, P = [{' '.join(f'{v:.4f}' for v in p)}]")
    p = p * np.exp2(D); p /= p.sum()
iter  1: lower 0.487651, upper 0.711895, P = [0.2500 0.2500 0.2500 0.2500]
iter  2: lower 0.535613, upper 0.689117, P = [0.2870 0.2702 0.2664 0.1763]
iter  5: lower 0.614005, upper 0.654694, P = [0.3478 0.3021 0.2961 0.0540]
iter 10: lower 0.644147, upper 0.648350, P = [0.3682 0.3149 0.3105 0.0063]
iter 20: lower 0.648097, upper 0.648169, P = [0.3704 0.3170 0.3126 0.0001]
iter 40: lower 0.648147, upper 0.648147, P = [0.3704 0.3170 0.3126 0.0000]

The useless input (its output does not depend on anything) gets less and less weight; the capacity-achieving distribution never uses it.

The KKT conditions

At the optimum, every input that is used has the same divergence D(x)=CD(x) = C, and unused inputs have D(x)≤CD(x) \le C. These are the KKT conditions of the concave maximization (The KKT Conditions). They give a quick check of a claimed solution.

python · try it yourself
import numpy as np

Q = np.array([[0.8, 0.2, 0.0], [0.1, 0.8, 0.1], [0.0, 0.2, 0.8]])
p = np.ones(3) / 3
for _ in range(2000):
    py = p @ Q
    with np.errstate(divide="ignore", invalid="ignore"):
        D = np.sum(np.where(Q > 0, Q * np.log2(Q / py), 0.0), axis=1)
    p = p * np.exp2(D); p /= p.sum()
print("D(x) for each input:", np.round(D, 6), " (all equal: every input is used)")
D(x) for each input: [0.826916 0.826916 0.826916]  (all equal: every input is used)

In software

  • Blahut-Arimoto needs only matrix-vector products, so it scales to channels with thousands of symbols; work in log space if some probabilities are tiny.
  • The same alternating scheme with a distortion penalty computes the rate-distortion function (Rate-Distortion Theory).

Exercises

Exercise 1: Starting point

Why does Blahut-Arimoto start from a distribution with all entries positive?

Answer

The multiplicative update can never revive an input that has probability 0.

Solution

P(x)←P(x)2D(x)P(x) \leftarrow P(x)2^{D(x)} keeps zeros at zero, so starting with a zero could miss the optimum.

Exercise 2: Symmetric channels

What does Blahut-Arimoto do on a BSC when started from the uniform distribution?

Answer

It stops at once: uniform is already optimal.

Solution

By symmetry D(0)=D(1)D(0) = D(1), so the update does not change PP and the lower and upper bounds coincide.

Exercise 3: Erasure channel check (code)

Run Blahut-Arimoto on a binary erasure channel with e=0.35e = 0.35 and compare with 1−e1 - e.

Answer

Both give 0.65.

Solution
python · try it yourself
import numpy as np

Q = np.array([[0.65, 0.35, 0.0], [0.0, 0.35, 0.65]])
p = np.array([0.3, 0.7])
for _ in range(200):
    py = p @ Q
    with np.errstate(divide="ignore", invalid="ignore"):
        D = np.sum(np.where(Q > 0, Q * np.log2(Q / py), 0.0), axis=1)
    p = p * np.exp2(D); p /= p.sum()
print(round(float(p @ D), 6), np.round(p, 4))
0.65 [0.5 0.5]

Test yourself

Blahut-Arimoto computes capacity by…

  1. alternating closed-form updates of the input distribution and a backward channel
  2. enumerating all codes
  3. gradient descent on the error probability
  4. Huffman coding the outputs

At the capacity-achieving input, every used input x has…

  1. the same divergence DKL(Q(⋅∣x)∥PY)=CD_{\text{KL}}(Q(\cdot \mid x) \parallel P_Y) = C
  2. probability 1/N
  3. zero divergence
  4. the largest entropy

Which quantity is an upper bound on capacity at every iteration?

  1. max⁡xD(x)\max_x D(x)
  2. ∑xP(x)D(x)\sum_x P(x)D(x)
  3. H(X)H(X)
  4. 0