Probability

Distributions

A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.

status: publishedimportance: criticaldifficulty 2/5math: undergraduateread: 15mlive demo
Editorial probability illustration of probability mass pushed through a random variable into PMF bars and density curves.

Concept Structure

Distributions

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
1next concepts
2related links

Learning map

Distributions
BeforeRandom VariablesNow4/4 sections readyTryManipulate one control and predict the visible change.NextMaximum Likelihood

Object flow

4/4 sections readyAsk about thisResearch room
ConceptDistributionsProbability
2 sources attachedLocal snapshot ready
concept:probability/distributions

Conceptual Bridge

What should feel connected as you move through this page.

Carry inRandom Variables

Bring the mental model from Random Variables; this page will reuse it instead of restarting from zero.

Work hereDistributions

A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.

Carry outMaximum Likelihood

The next edge should feel earned: use the demo prediction here before following Maximum Likelihood.

Test the linkManipulate one control and predict the visible change.Then continue to Maximum Likelihood
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

The raw outcome might be HHHH, HTHT, THTH, or TTTT, but your model only records X=X= number of heads. So what is the probability of X=1X=1?

A random variable is the measurement rule that turns each raw outcome into a value. A distribution is the probability measure induced on those values after the rule is applied.

The distinction is small but important. The world may have detailed outcomes: full coin-flip sequences, images, documents, users, or physical states. A random variable turns each outcome into a value we care about. The distribution tells us how probability lands on those values. "Measurement" is only a metaphor: XX does not have to be a physical instrument, and the distribution is not the rule itself. It is the probability law created by applying the rule to uncertain outcomes.

Many different outcomes can map to the same value. If XX is the number of heads in two coin flips, both HTHT and THTH become X=1X=1. The probability of X=1X=1 is the combined probability of all outcomes that map there.

That is the bridge to modeling. Once you know the distribution of a random variable, you can sample from it, compute expectations, and score observations. Maximum likelihood will later ask which parameter setting makes the observed values most probable under a chosen distribution family.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let (Ω,F,P)(\Omega,\mathcal F,P) be a probability space. Let (S,S)(S,\mathcal S) be the measurable space of values, and let

X:(Ω,F)(S,S)X:(\Omega,\mathcal F)\to(S,\mathcal S)

be a measurable random variable. The distribution, or law, of XX is the probability measure PXP_X on values:

PX(A)=P(XA)=P({ωΩ:X(ω)A}).P_X(A)=P(X\in A)=P(\{\omega\in\Omega:X(\omega)\in A\}).

Here ASA\in\mathcal S is a measurable set of values. Equivalently, PX(A)=P(X1(A))P_X(A)=P(X^{-1}(A)).

This is called the pushforward of PP through XX. It says: start with probability on raw outcomes, apply the measurement XX, and add up the probability that lands inside each value-set AA.

For a discrete random variable, the probability mass function is

pX(x)=P(X=x).p_X(x)=P(X=x).

If the raw sample space is finite, this is just the mass of every outcome that maps to xx:

pX(x)=ω:X(ω)=xP(ω).p_X(x)=\sum_{\omega:X(\omega)=x}P(\omega).

This is the central mechanism: a value collects probability from every raw outcome that maps to it. Grouping changes the representation of probability, not the total mass, so xpX(x)=1\sum_x p_X(x)=1.

When XX is real-valued, the cumulative distribution function is

FX(t)=P(Xt).F_X(t)=P(X\le t).

It accumulates the mass up to a threshold. For many real-valued distributions used in machine learning, PXP_X has a density fXf_X and interval probabilities are computed by integration:

P(aXb)=abfX(x)dx.P(a\le X\le b)=\int_a^b f_X(x)\,dx.

A density value is not itself a probability; only area under the density over a region is probability. Density values can be greater than 11, because they depend on the units of xx. Some distributions are mixed or have no ordinary density, so PMFs and densities are important cases, not the whole definition of distribution.

The demo uses two independent Bernoulli flips with head probability pp and random variable X=X= number of heads. Then XX has a binomial distribution:

P(X=k)=(2k)pk(1p)2k,k{0,1,2}.P(X=k)=\binom{2}{k}p^k(1-p)^{2-k},\qquad k\in\{0,1,2\}.

Its expectation and variance are

E[X]=2p,Var(X)=2p(1p).\mathbb E[X]=2p,\qquad \operatorname{Var}(X)=2p(1-p).

In machine learning, a parametric distribution family writes this mass or density as pθ(x)p_\theta(x). If observed values x(1),,x(n)x^{(1)},\dots,x^{(n)} are treated as independent draws from the distribution, the log likelihood is

(θ)=i=1nlogpθ(x(i)).\ell(\theta)=\sum_{i=1}^n \log p_\theta(x^{(i)}).

For discrete data, pθ(x)p_\theta(x) is a probability mass. For continuous data, pθ(x)p_\theta(x) is a density value, so likelihood scores density at the observations; it is not the probability of observing those exact points.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import math
import numpy as np

p_head = 0.65

# Raw outcomes for two independent flips.
outcomes = {
    "HH": p_head * p_head,
    "HT": p_head * (1 - p_head),
    "TH": (1 - p_head) * p_head,
    "TT": (1 - p_head) * (1 - p_head),
}

def number_of_heads(outcome):
    return outcome.count("H")

# Push probability mass through X(outcome) = number of heads.
pmf = {0: 0.0, 1: 0.0, 2: 0.0}
for outcome, prob in outcomes.items():
    pmf[number_of_heads(outcome)] += prob

# Grouping changes where the mass lives, not the total amount of mass.
assert abs(sum(outcomes.values()) - 1.0) < 1e-12
assert abs(sum(pmf.values()) - 1.0) < 1e-12

mean = sum(x * prob for x, prob in pmf.items())
variance = sum((x - mean) ** 2 * prob for x, prob in pmf.items())

print("PMF:", {x: round(prob, 3) for x, prob in pmf.items()})
print("E[X]:", round(mean, 3))
print("Var(X):", round(variance, 3))

# Likelihood scores observed values under this distribution.
observed = np.array([2, 1, 1, 0, 2])
observed_masses = [pmf[int(x)] for x in observed]
log_likelihood = (
    -math.inf
    if any(prob == 0 for prob in observed_masses)
    else sum(math.log(prob) for prob in observed_masses)
)
print("observed values:", observed.tolist())
print("log likelihood:", log_likelihood if math.isinf(log_likelihood) else round(log_likelihood, 3))

The code does not start with the binomial formula. It first assigns probability to raw outcomes, applies the random variable, and adds the mass that lands on the same value. The closed-form binomial PMF is the compact result of that aggregation.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Move the head-probability slider. The map from outcomes to XX stays fixed, but the probability mass on outcomes changes, so the distribution of XX changes.

Watch two things at once: the left side shows raw outcome probabilities, while the right side shows the aggregated probability mass function. The readout connects the distribution to expectation, variance, and a small i.i.d. observed-data log likelihood. At the endpoints, some observed values become impossible, so the log likelihood falls to negative infinity.

Live Concept Demo

Explore Distributions

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 2/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Distributions should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.

Prediction open01 / Intuition
Editorial probability illustration of probability mass pushed through a random variable into PMF bars and density curves.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Distributions should make visible.

Visual Inquiry

Make the image answer a mathematical question

A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Distributions easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong

Grounds probability distributions, densities, expectations, and the notation used in ML models.

Open source
book · 2016Deep LearningGoodfellow, Bengio, and Courville

Grounds the probability and information-theory vocabulary reused by generative modeling pages.

Open source

Claim Review

A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources2 references

deisenroth-2020-mml, goodfellow-2016-deep-learning

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedA distribution is the probability law induced by a random variable: it pushes probability from raw outcomes onto measurable value sets, with PMFs and densities as common representations.Claim metadata: source checked

Mathematics for Machine Learning grounds random variables, distributions, densities, and expectations; Goodfellow et al. use the same probability vocabulary as the base language for probabilistic models and information-theoretic losses.

Sources: Mathematics for Machine Learning, Deep LearningThis checks the probability-law framing and common PMF/density vocabulary, not measure-theoretic edge cases or every distribution family used in ML.A bounded review summary is present; still check caveats and exact source scope.

Checked MML chapter 6.1-6.2 and Goodfellow chapter 3.3: MML defines a random variable as a map from outcomes to a target space, gives PX(S)=P(X in S)=P(X^-1(S)), and calls PX, or P composed with X^-1, the law/distribution of X. MML and Goodfellow both distinguish discrete PMFs from continuous densities/PDFs, with density probabilities obtained by integration over value sets.

Reviewer: codex+oracle; reviewed 2026-05-06

Practice Loop

Try the idea before it explains itself

A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Distributions.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptDistributionsProbability

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptProbability

Distributions

Anchored question

What is the smallest example that makes Distributions click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:probability/distributions.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: deisenroth-2020-mml, goodfellow-2016-deep-learning
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Distributions Object key: concept:probability/distributions Context: Probability Anchor id: concept/concept-notebook/probability/distributions Open question: What is the smallest example that makes Distributions click without losing the math? Evidence to inspect: - Source ids to inspect: deisenroth-2020-mml, goodfellow-2016-deep-learning - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/probability/distributions concept:probability/distributions