Bring the mental model from Random Variables; this page will reuse it instead of restarting from zero.
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.

Concept Structure
Distributions
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
DistributionsConceptual Bridge
What should feel connected as you move through this page.
A distribution is the law of a random variable: it says how probability mass or density lands on the values the variable can take.
The next edge should feel earned: use the demo prediction here before following Maximum Likelihood.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
The raw outcome might be , , , or , but your model only records number of heads. So what is the probability of ?
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: 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 is the number of heads in two coin flips, both and become . The probability of 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
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let be a probability space. Let be the measurable space of values, and let
be a measurable random variable. The distribution, or law, of is the probability measure on values:
Here is a measurable set of values. Equivalently, .
This is called the pushforward of through . It says: start with probability on raw outcomes, apply the measurement , and add up the probability that lands inside each value-set .
For a discrete random variable, the probability mass function is
If the raw sample space is finite, this is just the mass of every outcome that maps to :
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 .
When is real-valued, the cumulative distribution function is
It accumulates the mass up to a threshold. For many real-valued distributions used in machine learning, has a density and interval probabilities are computed by integration:
A density value is not itself a probability; only area under the density over a region is probability. Density values can be greater than , because they depend on the units of . 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 and random variable number of heads. Then has a binomial distribution:
Its expectation and variance are
In machine learning, a parametric distribution family writes this mass or density as . If observed values are treated as independent draws from the distribution, the log likelihood is
For discrete data, is a probability mass. For continuous data, is a density value, so likelihood scores density at the observations; it is not the probability of observing those exact points.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
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
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Move the head-probability slider. The map from outcomes to stays fixed, but the probability mass on outcomes changes, so the distribution of 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.
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.

Start with the picture, metaphor, or geometric mechanism.
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.
Which visible object should carry the first intuition?
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.
Grounds probability distributions, densities, expectations, and the notation used in ML models.
Open sourceGrounds the probability and information-theory vocabulary reused by generative modeling pages.
Open sourceClaim 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.
Claims without a substantive review badge still need exact source-support review.
deisenroth-2020-mml, goodfellow-2016-deep-learning
Use equation, code, and demo objects to check whether the source support is operational.
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-06Practice 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.
Before touching the demo, predict one visible change that should happen in Distributions.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
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.Open the draft below to save one note and next action in this browser.
Distributions
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
This draft stays locally in this browser for concept:probability/distributions.
- 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
- 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
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.
concept/concept-notebook/probability/distributions
concept:probability/distributions