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
Success count k · colored selected bars carry probability mass
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
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.
Predict the interval probability before reading the inspector. Identify the mass at the lower endpoint and explain why subtracting 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 , with nonnegative masses summing to one. For a variable with a PDF , interval probability is the integral of a nonnegative density whose total area is one. The CDF of any real-valued random variable is
It is nondecreasing and right-continuous, approaching and at the two infinite extremes. Let denote its left limit. Then ; the difference measures a possible point mass.
Mechanics: link bars or area to accumulation
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 , with interval bounds and inclusive.
At a discrete jump, distinguish the value at the endpoint from its left limit. includes the mass at ; excludes it. Just to the right of , the CDF remains . Read endpoint markers and labels alongside the curve to recognize right-continuity.
Derivation: choose the correct subtraction
Subtract all probability strictly below from all probability at or below :
Subtracting instead gives and omits a possible lower-endpoint mass. For the continuous uniform and normal models, singleton probabilities vanish, so and the familiar area formula is . Equal bounds thus give a discrete point mass but zero continuous area.
For a density, . Where the density is continuous, . A PMF is a jump size, while a PDF is a rate of accumulation; neither is generally the cumulative height.
Worked examples
For , the masses at are . Therefore , , and . Since ,
Worked example: Mass, density and accumulated probability
Success count k · colored selected bars carry probability mass
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
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.
For a uniform variable on , density is . Its total rectangle has area . The interval has probability . 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 or , then subtracts the lower left limit for a closed interval. It checks singleton intervals and all ordered integer endpoint pairs from through . The NumPy program exposes cumsum and the two sides of searchsorted; selecting the side determines whether equality is included.
"""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()"""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 , , and an interval covering all three values. Predict , , and . 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 and interval . Predict density and probability . Then choose normal mode with , and the same interval. Its probability is approximately ; identical interval endpoints do not imply identical distributions.
Common mistakes and counterexamples
The PMF and CDF at differ: is the jump size and 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 to .
For a continuous PDF, does not imply . 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 standard deviations. Beyond that threshold the omitted one-sided tail is below .
The absolute CDF error budget is , validated against an independent math.erfc calculation; subtracting two CDF values gives an absolute interval budget of . The Gaussian drawing uses a dense grid within 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.
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 for the canonical closed interval, and explain when includes the intended endpoints.