Mutual information¶
CatScorer.mutual_information(),
CatScorer.normalized_mutual_information() · symmetric · range
\([0, \infty)\) nats, or \([0, 1]\) normalized · information-theoretic
Mutual information (MI) is the amount of information two variables share: how much knowing one reduces the uncertainty about the other, on average. It is zero when they are independent. It is the numerator of Theil's U, before division by the entropy of one variable.
Definition¶
The normalized mutual information divides by the joint entropy, which bounds it to \([0, 1]\); it is the complement of Rajski's (1961) distance:
In ASymCat, both are computed on the
pair subset \(S(x, y)\), and both
tuple entries are equal. When the subset is a single cell (one \(x\) and one
\(y\)), the joint entropy is zero and NMI is 0. The entropies follow the
scorer's entropy_estimator.
Example¶
With the example data:
>>> from asymcat import CatScorer
>>> pairs = [("q", "k")] * 2 + [("c", "k")] * 6 + [("k", "k")] * 3 + [("c", "s")] * 4
>>> scorer = CatScorer(pairs)
>>> [round(i, 3) for i in scorer.mutual_information()[("c", "k")]]
[0.131, 0.131]
>>> [round(i, 3) for i in scorer.normalized_mutual_information()[("c", "k")]]
[0.1, 0.1]
>>> [round(i, 3) for i in scorer.normalized_mutual_information()[("k", "s")]]
[1.0, 1.0]
In the subset of k and /s/ (k–/k/ and c–/s/), each variable determines the
other, so NMI is 1 even though k and /s/ never co-occur.
Properties¶
- Symmetric. For the direction, divide by one entropy instead of the joint one: that is Theil's U.
- Unsigned. Avoidance shares as much information as attraction; see Pitfalls. For a signed, per-pair quantity, use PMI, whose average over the cells of a table is the mutual information.
- Biased upwards on small samples with the plug-in estimator. The bias-corrected estimators reduce this, and can return slightly negative values.
API¶
mutual_information ¶
Return a Mutual Information scorer.
Computes MI(X;Y) and MI(Y;X) for each symbol pair, measuring the
overall statistical dependence between the symbols. Entropies follow
the scorer's entropy_estimator; bias-corrected estimates can be
slightly negative on small subsets.
Returns:
| Type | Description |
|---|---|
Dict[Tuple[Any, Any], Tuple[float, float]]
|
Dictionary mapping symbol pairs to (MI(X;Y), MI(Y;X)) tuples. |
normalized_mutual_information ¶
Return a Normalized Mutual Information scorer.
Computes NMI(X;Y) and NMI(Y;X) for each symbol pair, measuring the
statistical dependence normalized by joint entropy (range [0,1] for the
plug-in estimator). Entropies follow the scorer's entropy_estimator.
Returns:
| Type | Description |
|---|---|
Dict[Tuple[Any, Any], Tuple[float, float]]
|
Dictionary mapping symbol pairs to (NMI(X;Y), NMI(Y;X)) tuples. |
References¶
- Shannon (1948); Rajski (1961); Cover & Thomas (2006). See References.