Kiru Lab  /  The Mathematics of Learning  /  Uncertainty and Loss

Distributions and Expectation

A distribution is a statement about what you do not know. Expectation is its center of mass.

Concept  ·  about 25 minutes

A probability distribution assigns weight across possible outcomes. Its expectation is the weighted average — the value you would converge to over many draws — and its variance is how far draws typically land from that center.

E[X] = sum_x x * p(x) Var[X] = E[(X - E[X])^2]

Two kinds of uncertainty are worth separating, and conflating them causes real harm. Aleatoric uncertainty is noise inherent in the world: a coin flip stays unpredictable no matter how much data you gather. Epistemic uncertainty is ignorance that more data would fix. A model that reports high confidence on an input unlike anything in its training set is failing to represent epistemic uncertainty.

The mechanical root of a disorder

A softmax always produces a normalized distribution over the allowed outputs. It has no way to say "none of these". That architectural fact — not a training failure — is one reason models produce fluent, confident, wrong answers on out-of-distribution inputs.

Sampling

You will rarely have a distribution in closed form. Instead you draw samples and estimate. This is why running one prompt once tells you almost nothing about a model: you have a single draw from a distribution whose spread you have not measured.


Hold on to

  • Aleatoric uncertainty is irreducible; epistemic uncertainty is ignorance
  • A softmax cannot express "none of the above"
  • One sample is not a measurement of a distribution

Work through

Try each one before opening the solution. Getting it wrong first is most of where the learning happens.

  1. Estimate the mean of a skewed distribution from 10, 100, and 10,000 samples. Plot how the estimate narrows.
    Hint

    The standard error shrinks as 1/sqrt(n), so a 100x increase in samples halves it ten times over... check that claim.

    Solution

    The estimate narrows as 1/sqrt(n): going from 100 to 10,000 samples — 100x more data — reduces the spread by only 10x. That square-root law is why cutting error in half requires four times the data, and it is worth internalizing before you plan any evaluation. On a skewed distribution convergence is slower still, because rare large values dominate the mean.

    import numpy as np, matplotlib.pyplot as plt
    
    rng = np.random.default_rng(0)
    true_mean = np.exp(0.5)                      # mean of lognormal(0, 1)
    
    for n in (10, 100, 10_000):
        estimates = [rng.lognormal(size=n).mean() for _ in range(500)]
        print(f"n={n:6d}  spread={np.std(estimates):.4f}  bias={np.mean(estimates)-true_mean:+.4f}")
  2. Write two examples of aleatoric and two of epistemic uncertainty in a deployed AI system.
    Hint

    Ask whether more data of the same kind would reduce the uncertainty.

    Solution

    Aleatoric: the outcome of a fair coin flip; sensor noise in a camera at fixed exposure. More data narrows your estimate of the distribution but never makes an individual draw predictable. Epistemic: a model asked about an event after its training cutoff; a classifier shown a species absent from its training set. Both would be fixed by the right data. The failure that matters is a model reporting low uncertainty in the second case — it cannot distinguish "I know this is random" from "I have never seen this".


Related DEM-X entries

INF-HALL-01

Sign in to track your progress through the lab.