Mathematical Foundations

IV.8 · Probability

Is this height a probability, a density, or an accumulation?

Link a mass or density view to its cumulative distribution. Discrete jumps and continuous areas answer interval questions differently at their endpoints.

Mass, density and accumulated probability

PMF · probability at a numerical value
PMF · probability at a numerical valueBinomial n=2, p=50 percent. Selected k=1, exact mass 0.5. Selected closed interval [0, 1]. PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.10: approximately 0.251: approximately 0.52: approximately 0.25012

Success count k · colored selected bars carry probability mass

CDF · nondecreasing and continuous from the right
CDF · nondecreasing and continuous from the rightBinomial n=2, p=50 percent. Selected k=1, exact mass 0.5. Selected closed interval [0, 1]. PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.1012

Filled dot gives F(k); an open dot marks the left limit at a positive jump. F ends at one.

Binomial n=2, p=50 percent. Selected k=1, exact mass 0.5. Selected closed interval [0, 1]. PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.

Selected interval mass
0.75
CDF at lower bound
0.25
CDF at upper bound
0.75
CDF just before lower bound
0

= exact model quantity · ≈ numerical companion or observed estimate

from 0 to 30, whole numbers only

from 0 to 100, up to 2 decimal places

from −1 to 31, whole numbers only

from −20 to 35, up to 2 decimal places

from −20 to 35, up to 2 decimal places

PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.
P(X=k)=(nk)pk(1−p)n−kp=0.5P(X=k)=\binom nk p^k(1-p)^{n-k}\quad p=0.5
P(ℓ≤X≤u)=F(u)−F(ℓ−)=0.75P(\ell\le X\le u)=F(u)-F(\ell^-)=0.75

Start with individual trial outcomes

2 iid Bernoulli trials, p=0.5. Empty products are one in this counting context; n=0 means zero successes with probability one.

P(X=k)=(nk)pk(1−p)n−kp=0.5P(X=k)=\binom nk p^k(1-p)^{n-k}\quad p=0.5

Compare Binomial(2, 1/2) PMF bars with CDF jumps. The initial closed interval [0, 1] includes the masses at both endpoints.

Predict the interval probability before reading the inspector. Identify the mass at the lower endpoint and explain why subtracting F(0)F(0) would remove it.

Intuition: three ways to read probability

A discrete mass function attaches probability to each possible value. A continuous density spreads probability across intervals as area. A cumulative distribution asks a common question for both models: how much probability lies at or below this threshold?

Linking the views makes the distinction visible. A discrete PMF bar becomes a CDF jump of the same size. A continuous density accumulates smoothly; its height controls how quickly the CDF grows, rather than assigning positive mass to a single point.

Definition

For a discrete variable, the PMF is p(x)=P(X=x)p(x)=P(X=x), with nonnegative masses summing to one. For a variable with a PDF ff, interval probability is the integral of a nonnegative density whose total area is one. The CDF of any real-valued random variable is

F(x)=P(X≤x).F(x)=P(X\le x).

It is nondecreasing and right-continuous, approaching 00 and 11 at the two infinite extremes. Let F(a−)=P(X<a)F(a^-)=P(X<a) denote its left limit. Then F(a)−F(a−)=P(X=a)F(a)-F(a^-)=P(X=a); the difference measures a possible point mass.

The stage offers discrete, uniform, and normal modes. Move interval bounds and compare highlighted masses or density area with the CDF endpoints, inspector, equation, and trace. The default discrete mode is Binomial⁡(2,1/2)\operatorname{Binomial}(2,1/2), with interval bounds 00 and 11 inclusive.

At a discrete jump, distinguish the value at the endpoint from its left limit. F(1)=3/4F(1)=3/4 includes the mass at 11; F(1−)=1/4F(1^-)=1/4 excludes it. Just to the right of 11, the CDF remains 3/43/4. Read endpoint markers and labels alongside the curve to recognize right-continuity.

Derivation: choose the correct subtraction

Subtract all probability strictly below aa from all probability at or below bb:

P(a≤X≤b)=F(b)−F(a−).P(a\le X\le b)=F(b)-F(a^-).

Subtracting F(a)F(a) instead gives P(a<X≤b)P(a<X\le b) and omits a possible lower-endpoint mass. For the continuous uniform and normal models, singleton probabilities vanish, so F(a−)=F(a)F(a^-)=F(a) and the familiar area formula is F(b)−F(a)F(b)-F(a). Equal bounds thus give a discrete point mass but zero continuous area.

For a density, F(x)=∫−∞xf(t) dtF(x)=\int_{-\infty}^x f(t)\,dt. Where the density is continuous, F′(x)=f(x)F'(x)=f(x). A PMF is a jump size, while a PDF is a rate of accumulation; neither is generally the cumulative height.

Worked examples

For Binomial⁡(2,1/2)\operatorname{Binomial}(2,1/2), the masses at 0,1,20,1,2 are 1/4,1/2,1/41/4,1/2,1/4. Therefore F(0)=1/4F(0)=1/4, F(1)=3/4F(1)=3/4, and F(2)=1F(2)=1. Since F(0−)=0F(0^-)=0,

P(0≤X≤1)=34−0=34,P(0<X≤1)=34−14=12.P(0\le X\le1)=\frac34-0=\frac34, \qquad P(0<X\le1)=\frac34-\frac14=\frac12.

Worked example: Mass, density and accumulated probability

PMF · probability at a numerical value
PMF · probability at a numerical valueBinomial n=2, p=50 percent. Selected k=1, exact mass 0.5. Selected closed interval [0, 1]. PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.10: approximately 0.251: approximately 0.52: approximately 0.25012

Success count k · colored selected bars carry probability mass

CDF · nondecreasing and continuous from the right
CDF · nondecreasing and continuous from the rightBinomial n=2, p=50 percent. Selected k=1, exact mass 0.5. Selected closed interval [0, 1]. PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.1012

Filled dot gives F(k); an open dot marks the left limit at a positive jump. F ends at one.

Binomial n=2, p=50 percent. Selected k=1, exact mass 0.5. Selected closed interval [0, 1]. PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.

Selected interval mass
0.75
CDF at lower bound
0.25
CDF at upper bound
0.75
CDF just before lower bound
0

= exact model quantity · ≈ numerical companion or observed estimate

from 0 to 30, whole numbers only

from 0 to 100, up to 2 decimal places

from −1 to 31, whole numbers only

from −20 to 35, up to 2 decimal places

from −20 to 35, up to 2 decimal places

PMF bars carry exact point masses. The closed interval has mass 0.75. A CDF includes the jump at its argument: subtract F(ℓ−), not F(ℓ), for a closed interval.
P(X=k)=(nk)pk(1−p)n−kp=0.5P(X=k)=\binom nk p^k(1-p)^{n-k}\quad p=0.5
P(ℓ≤X≤u)=F(u)−F(ℓ−)=0.75P(\ell\le X\le u)=F(u)-F(\ell^-)=0.75

Start with individual trial outcomes

2 iid Bernoulli trials, p=0.5. Empty products are one in this counting context; n=0 means zero successes with probability one.

P(X=k)=(nk)pk(1−p)n−kp=0.5P(X=k)=\binom nk p^k(1-p)^{n-k}\quad p=0.5

Read the canonical CDF at 0 and 1, then compare a closed interval with a single-point interval. In continuous modes, zero-width intervals have zero mass.

For a uniform variable on [0,1/2][0,1/2], density is 22. Its total rectangle has area 2×1/2=12\times1/2=1. The interval [0,1/4][0,1/4] has probability 2×1/4=1/22\times1/4=1/2. A density above one is valid because height alone is not probability.

Executable reference code

The exact program implements a finite CDF by summing masses with either ≤\le or <<, then subtracts the lower left limit for a closed interval. It checks singleton intervals and all ordered integer endpoint pairs from −1-1 through 33. The NumPy program exposes cumsum and the two sides of searchsorted; selecting the side determines whether equality is included.

code/python/probability_representations.py
"""Exact PMF and right-continuous CDF of Binomial(2, 1/2)."""
from fractions import Fraction as F

PMF = {0: F(1, 4), 1: F(1, 2), 2: F(1, 4)}


def cdf(x, left=False):
    if not isinstance(x, (int, F)) or isinstance(x, bool) or type(left) is not bool:
        raise ValueError("Use an exact threshold and a boolean left-limit selector")
    return sum((p for k, p in PMF.items() if (k < x if left else k <= x)), F(0))


def interval_probability(lower, upper):
    # Validate both endpoints even if their ordering is invalid.
    low_left, high = cdf(lower, left=True), cdf(upper)
    if lower > upper:
        raise ValueError("Interval endpoints must be ordered")
    return high - low_left


def main():
    assert sum(PMF.values(), F(0)) == 1
    assert [cdf(k) for k in (0, 1, 2)] == [F(1, 4), F(3, 4), F(1)]
    assert cdf(0, left=True) == 0
    assert cdf(1, left=True) == F(1, 4)
    assert cdf(F(1001, 1000)) == cdf(1) == F(3, 4)
    assert interval_probability(0, 1) == F(3, 4)
    assert cdf(1) - cdf(0) == F(1, 2)  # This is P(0 < X <= 1).
    for lower in range(-1, 4):
        for upper in range(lower, 4):
            assert interval_probability(lower, upper) == sum((p for k, p in PMF.items() if lower <= k <= upper), F(0))
    assert interval_probability(1, 1) == F(1, 2)
    assert interval_probability(-10, 10) == 1
    for lower, upper in ((2, 1), (float('nan'), 1), (0, 1.0)):
        try:
            interval_probability(lower, upper)
        except ValueError:
            pass
        else:
            raise AssertionError("Invalid exact interval accepted")
    print("PMF:", PMF, "CDF at support:", [cdf(k) for k in PMF])
    print("P(0 <= X <= 1) = F(1) - F(0-) =", interval_probability(0, 1))
    print("Uniform[0, 1/2]: density = 2; area on [0, 1/4] =", F(2) * F(1, 4))


if __name__ == "__main__":
    main()
code/python/probability_representations_numpy.py
"""Sort-free canonical support: cumsum and searchsorted implement CDF sides."""
import numpy as np

SUPPORT = np.array([0., 1., 2.])
PMF = np.array([0.25, 0.5, 0.25])
CUMULATIVE = np.concatenate(([0.], np.cumsum(PMF)))


def cdf(x, left=False):
    if not np.isfinite(x) or type(left) is not bool:
        raise ValueError("Use a finite threshold and boolean side selector")
    return CUMULATIVE[np.searchsorted(SUPPORT, x, side="left" if left else "right")]


def interval_probability(lower, upper):
    low_left, high = cdf(lower, left=True), cdf(upper)
    if lower > upper:
        raise ValueError("Interval endpoints must be ordered")
    return high - low_left


def main():
    np.testing.assert_array_equal([cdf(k) for k in SUPPORT], [0.25, 0.75, 1])
    assert cdf(1, left=True) == 0.25
    assert cdf(1.001) == cdf(1) == 0.75
    assert interval_probability(0, 1) == 0.75
    assert interval_probability(1, 1) == 0.5
    for lower in range(-1, 4):
        for upper in range(lower, 4):
            assert interval_probability(lower, upper) == PMF[(SUPPORT >= lower) & (SUPPORT <= upper)].sum()
    for lower, upper in ((2, 1), (np.nan, 1), (0, np.inf)):
        try:
            interval_probability(lower, upper)
        except ValueError:
            pass
        else:
            raise AssertionError("Invalid interval accepted")
    print("PMF:", PMF, "CDF:", CUMULATIVE[1:])
    print("Closed interval [0, 1]:", interval_probability(0, 1))
    print("Jump at 1:", cdf(1) - cdf(1, left=True))


if __name__ == "__main__":
    main()

Explore

In discrete mode, compare [0,1][0,1], [1,1][1,1], and an interval covering all three values. Predict 3/43/4, 1/21/2, and 11. Move a bound between consecutive support values and explain why the accumulated mass stays flat until a value is crossed.

Switch to uniform mode with support [−2,2][-2,2] and interval [−1,1][-1,1]. Predict density 1/41/4 and probability 1/21/2. Then choose normal mode with μ=0\mu=0, σ=1\sigma=1 and the same interval. Its probability is approximately 0.6826894921370.682689492137; identical interval endpoints do not imply identical distributions.

Common mistakes and counterexamples

The PMF and CDF at 11 differ: 1/21/2 is the jump size and 3/43/4 is the cumulative height. Treating the CDF as left-continuous would assign its lower jump height at a support point and change the event from X≤xX\le x to X<xX<x.

For a continuous PDF, f(0)>0f(0)>0 does not imply P(X=0)>0P(X=0)>0. A point has no interval width. Also, not every distribution has a PDF: the discrete model uses masses, and mixed distributions require both continuous and point-mass contributions.

Numerical considerations

Finite rational masses and their CDF sums can be exact. The NumPy reference checks the same finite mechanics in floating-point form. Normal areas are approximate: the model integrates a positive tail with composite Simpson’s rule using 2048 subdivisions, truncated at 88 standard deviations. Beyond that threshold the omitted one-sided tail is below 6.4×10−166.4\times10^{-16}.

The absolute CDF error budget is 10−910^{-9}, validated against an independent math.erfc calculation; subtracting two CDF values gives an absolute interval budget of 2×10−92\times10^{-9}. The Gaussian drawing uses a dense grid within μ±4σ\mu\pm4\sigma and extra interval and viewport points. Its polygonal area is not claimed to be exact or normalized. Drawing samples and numerical integration limits are separate choices.

Engineering and ML connections

Categorical predictions use PMF-like probability vectors. Continuous likelihoods are density values and depend on units. CDFs support threshold queries and interval checks across both types of variable. When writing an API or evaluation rule, specify the inequality at each endpoint so a point mass is not silently included or excluded.

Exercises

Enter exact finite answers where requested. The explanations distinguish cumulative height, jump size, density, and area.

calculation

Include both discrete endpoints

X has Binomial(2, 1/2) masses at 0, 1, 2. Give P(0 ≤ X ≤ 1) and F(0⁻).

calculation

Accumulate the PMF

For Binomial(2, 1/2), give F(0), F(1), F(2).

calculation

Convert density height into area

X is uniform on [0, 1/2]. Give its density inside the support and P(0 ≤ X ≤ 1/4).

explanation

Which end of a CDF jump is included?

At x = 1 in Binomial(2, 1/2), which reading matches F(x) = P(X ≤ x)?

Choose one answer

explanation

Read a continuous point correctly

A normal PDF is positive at x = 0. What follows about P(X = 0)?

Choose one answer

Summary and checkpoints

A PMF gives point masses; a PDF gives probability per unit of value; a CDF accumulates probability at or below a threshold. Check that you can recover a jump from its left and right heights, obtain 3/43/4 for the canonical closed interval, and explain when F(b)−F(a)F(b)-F(a) includes the intended endpoints.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available