conditional_entropy
Computes the conditional entropy of
What does it measure?
Conditional entropy answers: how much uncertainty remains in
It quantifies the irreducible uncertainty — the part of
Two extremes:
- If
completely determines (e.g. is a function of ), there is no remaining uncertainty: . - If
and are independent, knowing tells you nothing about , so the uncertainty is unchanged: .
Formula
This is the chain rule of entropy: the joint uncertainty minus the uncertainty already accounted for by
Signature
rust
pub fn conditional_entropy<X, Y>(x: &[X], y: &[Y]) -> Result<f64, InfoError>
where
X: Eq + Hash,
Y: Eq + Hashrust
pub fn conditional_entropy_unchecked<X, Y>(x: &[X], y: &[Y]) -> f64
where
X: Eq + Hash,
Y: Eq + HashParameters
| Parameter | Description |
|---|---|
x | Observed samples of the variable whose residual uncertainty is measured |
y | Observed samples of the conditioning variable |
The x and the y are treated as a joint observation.
Returns
| Error | When |
|---|---|
InfoError::EmptyInput | Either slice is empty |
InfoError::LengthMismatch | The slices have different lengths |
Examples
rust
use entropium::{entropy, conditional_entropy};
// Knowing X perfectly eliminates its own uncertainty: H(X|X) = 0
let x = vec![0, 1, 0, 1, 1, 0];
assert!(conditional_entropy(&x, &x).unwrap() < 1e-12);
// Independent variables: H(X|Y) = H(X)
let x = vec![0, 0, 1, 1];
let y = vec![0, 1, 0, 1];
let h_x_given_y = conditional_entropy(&x, &y).unwrap();
let h_x = entropy(&x).unwrap();
assert!((h_x_given_y - h_x).abs() < 1e-12);
// Partially correlated: H(X|Y) is between 0 and H(X)
let temperature = vec![0, 0, 0, 1, 1, 1, 2, 2];
let season = vec![0, 0, 0, 1, 1, 1, 2, 3]; // season predicts temp, but not perfectly
let h = conditional_entropy(&temperature, &season).unwrap();
println!("Residual uncertainty in temperature given season: {h:.4} bits");Practical uses
- Feature selection:
measures how much uncertainty remains in the target after observing feature . Features that drive it close to zero are highly predictive. - Information gain: decision trees split on the feature
that maximises (the reduction in label uncertainty). - Lossless compression of correlated streams: if two correlated streams
and must be encoded separately and the decoder receives first, the stream can be compressed to bits per symbol instead of .
Properties
| Property | Statement |
|---|---|
| Non-negativity | |
| Zero | |
| Independence | |
| Asymmetry | |
| Chain rule | |
| Relation to MI |