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.

Introductory · Undergraduate mathematics · about 15 minutes

Reading map and next steps

Intuition

The idea in plain words, before the symbols.

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.

Study prompts for this section: Intuition
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Mathematics

Definitions, assumptions and the derivation.

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(X∈A)=P({ω∈Ω:X(ω)∈A}).P_X(A)=P(X\in A)=P(\{\omega\in\Omega:X(\omega)\in A\}).

Here A∈SA\in\mathcal S is a measurable set of values. Equivalently, PX(A)=P(X−1(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(X≤t).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(a≤X≤b)=∫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(1−p)2−k,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(1−p).\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=1nlog⁡pθ(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.

Study prompts for this section: Mathematics
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Code

The same calculation as runnable code, in the notation of the derivation.

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.

Study prompts for this section: Code
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

Demo

Change an input, predict the result, and see which quantities respond.

ExploreChange one control at a time and name what responds.An optional observation guide follows the demo.

Explore Distributions

Loading the interactive demo…

Observation guide

Optional and ungraded. Opening a guide saves nothing.

Choose what to inspect in Distributions, then open its guide.

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. Before the grouped distribution appears, predict which value of XX collects the most probability mass.

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.

Study prompts for this section: Demo
Study prompts

Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.

In focus

Concept: Distributions

What is the smallest example of Distributions you can work through by hand, and what does it show?

BeforeRandom VariablesNextMaximum Likelihood
DetailsProbability

After the first pass

Go deeper

Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.
What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.

Section by section

Choose what to look for in each section

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

Choose what to look for (no demo yet)01 / Intuition
Illustration of probability mass pushed through a random variable into PMF bars and density curves.
What to look for

Start with the picture, metaphor, or geometric mechanism.

Choose first

Choose what you expect to see in this section of Distributions.

Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.

Looking at the picture

Questions to ask of the picture

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 of 4 sections writtenNo live demo yet
Question

Which part of the picture should you look at first?

Choose first

Pick the part of the picture you expect to explain Distributions.

Sources

References for this page

A reference shows where an idea comes from; it does not vouch for every step on this page.
book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong
Why it is cited

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

Open source
book · 2016Deep LearningGoodfellow, Bengio, and Courville
Why it is cited

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

Open source
book · 1933Grundbegriffe der WahrscheinlichkeitsrechnungKolmogorov
Why it is cited

Springer; in English as Foundations of the Theory of Probability (Chelsea, 1950). Defines the distribution of a random variable as the probability it induces on values.

Open source
book · 2019Introduction to Probability (2nd ed.)Blitzstein and Hwang
Why it is cited

Chapman & Hall/CRC. Chapter 3 builds PMFs and CDFs, including the binomial, by grouping outcomes; Chapter 5 covers densities.

Open source
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.

Claims and sources

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

Checked against the cited passages

The checks were made by this site, not by an independent reviewer.

A 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.
What the sources support

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...

Where to see it on this page
Equation 1
X:(Ω,F)→(S,S)X:(\Omega,\mathcal F)\to(S,\mathcal S)
Equation 2
PX(A)=P(X∈A)=P({ω∈Ω:X(ω)∈A}).P_X(A)=P(X\in A)=P(\{\omega\in\Omega:X(\omega)\in A\}).
Caveat

This checks the probability-law framing and common PMF/density vocabulary, not measure-theoretic edge cases or every distribution family used in ML.

StatusChecked against the cited passages.

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.

Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.

Practice · Distributions

Try the idea in your own words

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 · Selected for practice

Distributions

What it rests on: Sources: Mathematics for Machine Learning; Deep Learning; Grundbegriffe der Wahrscheinlichkeitsrechnung

Context and links
Choose a task

Explain the mechanism

For Distributions: What is the smallest example of Distributions you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.

No answer yet

A rough first thought is enough. Your draft stays when you change tasks.

Your draft stays on this page and is cleared when you leave or reload.

A little help · Explain

Open one hint at a time. These are suggestions, not your answer or a grade.

0 of 3 hints shown for this question.

    Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.

    Where am I stuck? (optional)
    Your own description, not an automatic diagnosis

    Choose one, or leave this unspecified. Select it again to clear it.

    Take your draft to a feedback conversation

    No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.

    Write an attempt before copying a feedback prompt.

    A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.

    Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
    Ask about this pageClose
    ConceptDistributionsSources: Mathematics for Machine Learning; Deep Learning; Grundbegriffe der Wahrscheinlichkeitsrechnungassert abs(sum(outcomes.values()) - 1.0) < 1e-12

    Your question

    Choose what your question is about

    Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.
    Next local actionNo local draft saved yet

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

    conceptProbability

    Distributions

    Starting question

    What is the smallest example of Distributions you can work through by hand, and what does it show?

    SourcesCheck the 4 cited sources listed under Sources.Notes can be saved for this item
    Points of view on this item

    Fixed prompts generated from this item. They are not comments from people or independent reviews.

    Learner’s first stepAsk what would make "Distributions" feel predictable rather than familiar.
    Assumption

    The 4 cited sources must support this exact item, not just the surrounding topic.

    Source-checking summary

    Connect the definition to one equation, piece of code or demo before widening the discussion.

    Proposed experiment

    Change one input, then check that the same relationship holds in the mathematics, the code and the demo.

    Next action

    You can state the mechanism in your own words

    Evidence4 checks
    ObservationChecking for a saved observation
    ActionReady for one action
    PromptLearner prompt ready to copy
    Go to this item
    01ObservationChecking what this browser has saved
    02EvidenceChecking for a saved observation
    03SourcesCheck the 4 cited sources listed under Sources.
    04Next stepSave one next action
    Local action draftNo local draft saved yetOpen when you are ready to write one next action
    Local action draft

    This draft stays in this browser and is attached to this item only.

    No local draft saved.
    Evidence to inspect
    • What the 4 cited sources say about this exact item
    • The definition, its prerequisites, and a contrasting concept
    • The equation or code that makes the concept concrete
    • One demo state that shows what stays the same as the inputs change
    What would resolve this
    • You can state the mechanism in your own words
    • You can name the prerequisite that would clear up the confusion
    • You can predict how the result changes when one input changes
    Reference idconcept/concept-notebook/probability/distributions concept:probability/distributions