All formulas

Information theory

Mutual information

info.mutual-informationAlso called mutual information, mi, mutual info, information gain

I(X;Y)=∑i=1m∑j=1nPijln⁡PijpiqjI(X; Y) = \sum_{i=1}^{m}\sum_{j=1}^{n} P_{ij}\ln\frac{P_{ij}}{p_i q_j}

wherepi=∑k=1nPikp_i = \sum_{k=1}^{n} P_{ik}

whereqj=∑l=1mPljq_j = \sum_{l=1}^{m} P_{lj}

Information shared by two discrete variables, from their joint probability table P, in nats: the KL divergence of the joint distribution from the product of its marginals p (rows) and q (columns).

Notation

PP

joint probability table, entries summing to one

P ∈ ℝm×n: entries > 0, summing to 1

mm

number of values of X

Size, at least 2

nn

number of values of Y

Size, at least 2

I(X;Y)I(X; Y)

Result: the mutual information, in nats

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    P=[[0.25,0.25],[0.25,0.25]]P = \left[\left[0.25, 0.25\right], \left[0.25, 0.25\right]\right]

    Result

    I(X;Y)=0\displaystyle I(X; Y) = 0
  2. Given

    P=[[3/8,1/8],[1/8,3/8]]P = \left[\left[3/8, 1/8\right], \left[1/8, 3/8\right]\right]

    Result

    I(X;Y)=−log⁡(2)4+3log⁡(32)4\displaystyle I(X; Y) = - \frac{\log{\left(2 \right)}}{4} + \frac{3 \log{\left(\frac{3}{2} \right)}}{4}

    ≈ 0.130812035941

  3. Given

    P=[[1/8,1/8],[1/4,1/2]]P = \left[\left[1/8, 1/8\right], \left[1/4, 1/2\right]\right]

    Result

    I(X;Y)=log⁡(89)4+log⁡(45)8+log⁡(1615)2+log⁡(43)8\displaystyle I(X; Y) = \frac{\log{\left(\frac{8}{9} \right)}}{4} + \frac{\log{\left(\frac{4}{5} \right)}}{8} + \frac{\log{\left(\frac{16}{15} \right)}}{2} + \frac{\log{\left(\frac{4}{3} \right)}}{8}

    ≈ 0.0108908167969

  4. Given

    P=[[1/6,1/6,1/6],[1/12,1/4,1/6]]P = \left[\left[1/6, 1/6, 1/6\right], \left[1/12, 1/4, 1/6\right]\right]

    Result

    I(X;Y)=log⁡(45)6+log⁡(23)12+log⁡(65)4+log⁡(43)6\displaystyle I(X; Y) = \frac{\log{\left(\frac{4}{5} \right)}}{6} + \frac{\log{\left(\frac{2}{3} \right)}}{12} + \frac{\log{\left(\frac{6}{5} \right)}}{4} + \frac{\log{\left(\frac{4}{3} \right)}}{6}

    ≈ 0.0225480503791

Common mistakes

  • Uses log base 2

    The result is in bits.

    Fix: Use the natural logarithm, or multiply by ln 2.

Source

  • Cover and Thomas 2006

    Cover, Thomas M.; Thomas, Joy A. Elements of Information Theory. 2nd ed. Wiley-Interscience, 2006. doi:10.1002/047174882X

    doi.org