IV.10 · Probability
What changes when probability is spread evenly or concentrated near a center?
Compare a normalized rectangle with a Gaussian curve using the same interval. Read probability as area, then standardize location and scale without changing the question.
Compare flat and Gaussian densities
x · density has inverse-x units · drawn tails are truncated, total Gaussian mass is analytically one
F(x) = area to the left · approaches zero and one in the tails
Gaussian mean 0, standard deviation 1. Selected closed interval [-1, 1]. A PDF height is density, with inverse-value units. Interval probability is area: approximately 0.682689. A single continuous point has probability zero. Numerical CDF absolute error budget 1e-9; interval budget 2e-9. The finite drawing does not prove normalization.
- Selected interval area
- 0.682689
- CDF at lower bound
- 0.158655
- CDF at upper bound
- 0.841345
- Density at Gaussian mean
- 0.398942
- Any exact point probability
- 0
- Standardized lower bound
- −1
- Standardized upper bound
- 1
= exact model quantity · ≈ numerical companion or observed estimate
from −10 to 10, up to 2 decimal places
from −10 to 10, up to 2 decimal places
from −5 to 5, up to 2 decimal places
from 0.1 to 5, up to 2 decimal places
from −20 to 35, up to 2 decimal places
from −20 to 35, up to 2 decimal places
Specify a normalized density
The Gaussian density is normalized analytically over the full real line, not over the displayed window.
Predict the uniform density from its support width. Switch to normal mode and explain why equal interval widths need not contain equal mass.
Intuition: shape controls area
A uniform distribution assigns the same density across a finite support. Equal-width subintervals inside that support receive equal probabilities. A Gaussian concentrates density near its mean and decreases smoothly into both tails. Equal-width intervals at different locations generally have different probabilities.
Neither density gives positive probability to a single point. A shaded interval has area; a solitary density height describes concentration per unit of value. This distinction remains true at the highest point of the Gaussian curve.
Definition
For , the continuous uniform density is inside and zero outside. Its CDF is zero below , within the support, and one above . Endpoint density choices do not affect any interval probability.
A Gaussian, or normal, distribution with finite mean and positive standard deviation has density
Its mathematical support is the whole real line. The standard normal has and ; write its CDF as . The density integrates to one over the whole line. A zero-width uniform support or nonpositive Gaussian is invalid for these continuous formulas; a point-mass model would be a separate definition.
Mechanics: separate model and viewport
Choose uniform or normal mode, change its parameters, and move the interval bounds. The highlighted area, CDF difference, inspector, formula, and integration trace all describe the same state. In uniform mode, only the part of the interval inside the support contributes area.
In normal mode, the drawn curve is sampled most densely over , with extra points at interval and viewport bounds. The viewport also includes the uniform support for comparison. These finite samples make a readable approximation; they do not define the distribution’s support or renormalize its CDF. The numerical integration uses a separate positive-tail cutoff at standard deviations.
Derivation: normalize and standardize
Uniform normalization requires density times support width to equal one. Thus interval probability is the overlap width divided by :
For the Gaussian, set . The substitution cancels the density’s factor, yielding the standard-normal density. Therefore
The positive scale preserves endpoint order. Because these models are continuous, including or excluding finite endpoints gives the same probability.
Worked examples
Uniform has support width and density . Its interval has width , so the area is exactly . The interval overlaps the full support and has probability , rather than .
Worked example: Compare flat and Gaussian densities
x · density has inverse-x units · drawn tails are truncated, total Gaussian mass is analytically one
F(x) = area to the left · approaches zero and one in the tails
Gaussian mean 0, standard deviation 1. Selected closed interval [-1, 1]. A PDF height is density, with inverse-value units. Interval probability is area: approximately 0.682689. A single continuous point has probability zero. Numerical CDF absolute error budget 1e-9; interval budget 2e-9. The finite drawing does not prove normalization.
- Selected interval area
- 0.682689
- CDF at lower bound
- 0.158655
- CDF at upper bound
- 0.841345
- Density at Gaussian mean
- 0.398942
- Any exact point probability
- 0
- Standardized lower bound
- −1
- Standardized upper bound
- 1
= exact model quantity · ≈ numerical companion or observed estimate
from −10 to 10, up to 2 decimal places
from −10 to 10, up to 2 decimal places
from −5 to 5, up to 2 decimal places
from 0.1 to 5, up to 2 decimal places
from −20 to 35, up to 2 decimal places
from −20 to 35, up to 2 decimal places
Specify a normalized density
The Gaussian density is normalized analytically over the full real line, not over the displayed window.
For ,
For , the second parameter here denotes variance, so . Interval standardizes to and has the same probability. Always state whether a normal notation or software API uses variance or standard deviation as its scale parameter.
Executable reference code
The exact uniform reference uses Fraction overlap widths. Its independent Gaussian CDF uses standard-library math.erfc, with . It also demonstrates the positive-tail Simpson calculation and compares it with that independent CDF over a deterministic sweep and several intervals.
The NumPy program exposes density arrays, an evenly spaced 2049-point grid, and Simpson weights . It uses installed NumPy plus the standard library, without SciPy. Both references include assertions for literal areas, invalid parameters, and the stated CDF and interval error budgets.
"""Exact uniform areas and Gaussian erfc cross-checks of Simpson integration.
The Gaussian drawing stops at +/-4 sigma. Integration uses the positive tail
to 8 sigma and 2048 Simpson subdivisions. Omitted one-sided mass is <6.4e-16.
CDF absolute-error budget: 1e-9; two-CDF interval budget: 2e-9.
"""
from fractions import Fraction as F
from math import erfc, exp, fsum, isfinite, pi, sqrt
def uniform_interval(a, b, lower, upper):
if any(not isinstance(x, (int, F)) or isinstance(x, bool) for x in (a, b, lower, upper)):
raise ValueError("Use integer or Fraction endpoints")
if a >= b or lower > upper:
raise ValueError("Require a < b and lower <= upper")
overlap = max(F(0), min(F(b), F(upper)) - max(F(a), F(lower)))
return overlap / (F(b) - F(a))
def standardize(x, mu=0, sigma=1):
if not all(isfinite(v) for v in (x, mu, sigma)) or sigma <= 0:
raise ValueError("Use finite x, mu and positive finite sigma")
return (x - mu) / sigma
def normal_cdf(x, mu=0, sigma=1):
return 0.5 * erfc(-standardize(x, mu, sigma) / sqrt(2))
def simpson_cdf(x, mu=0, sigma=1):
z = standardize(x, mu, sigma)
start = abs(z)
if start >= 8:
return 1.0 if z > 0 else 0.0
n = 2048
h = (8 - start) / n
def density(t):
return exp(-t*t/2) / sqrt(2*pi)
odd = fsum(density(start + j*h) for j in range(1, n, 2))
even = fsum(density(start + j*h) for j in range(2, n, 2))
tail = h/3 * (density(start) + density(8) + 4*odd + 2*even)
return 1 - tail if z >= 0 else tail
def normal_interval(lower, upper, mu=0, sigma=1):
low, high = normal_cdf(lower, mu, sigma), normal_cdf(upper, mu, sigma)
if lower > upper:
raise ValueError("Interval endpoints must be ordered")
return high - low
def main():
assert uniform_interval(-2, 2, -1, 1) == F(1, 2)
assert uniform_interval(-2, 2, -3, 3) == 1
assert uniform_interval(-2, 2, 2, 3) == 0
assert uniform_interval(-2, 2, 0, 0) == 0
assert standardize(-1, 2, 3) == -1 and standardize(5, 2, 3) == 1
assert abs(normal_interval(-1, 1) - 0.682689492137) < 1e-12
assert normal_cdf(0) == 0.5
assert 0.5 * erfc(8 / sqrt(2)) < 6.4e-16
points = [j/8 for j in range(-80, 81)]
errors = [abs(simpson_cdf(z) - normal_cdf(z)) for z in points]
assert max(errors) <= 1e-9
for lower, upper in ((-1, 1), (-4, 4), (-8, -7), (7, 8), (-2.3, 0.7), (0, 0)):
estimate = simpson_cdf(upper) - simpson_cdf(lower)
assert abs(estimate - normal_interval(lower, upper)) <= 2e-9
assert abs(normal_interval(-1, 5, 2, 3) - 0.682689492137) < 1e-12
for args in ((0, 0, 0), (0, 0, -1), (float('nan'), 0, 1), (0, float('inf'), 1)):
try:
normal_cdf(*args)
except ValueError:
pass
else:
raise AssertionError("Invalid Gaussian parameters accepted")
for args in ((2, 2, 0, 1), (-2, 2, 1, -1)):
try:
uniform_interval(*args)
except ValueError:
pass
else:
raise AssertionError("Invalid uniform parameters accepted")
try:
normal_interval(1, -1)
except ValueError:
pass
else:
raise AssertionError("Reversed Gaussian interval accepted")
print("Uniform[-2,2] density = 1/4, P([-1,1]) =", uniform_interval(-2, 2, -1, 1))
print("Standard normal P([-1,1]) ≈", normal_interval(-1, 1))
print("Largest sampled Simpson CDF error against erfc:", max(errors))
print("Omitted drawn +/-4 sigma tail mass ≈", erfc(4 / sqrt(2)))
if __name__ == "__main__":
main()"""Array mechanics for densities and positive-tail Simpson, without SciPy."""
from math import erfc, sqrt
import numpy as np
def normal_pdf(x, mu=0, sigma=1):
x = np.asarray(x, dtype=float)
if not np.all(np.isfinite(x)) or not np.isfinite(mu) or not np.isfinite(sigma) or sigma <= 0:
raise ValueError("Use finite points, finite mu and positive finite sigma")
z = (x - mu) / sigma
return np.exp(-z*z/2) / (sigma * np.sqrt(2*np.pi))
def simpson_cdf(x, mu=0, sigma=1):
if not all(np.isfinite(v) for v in (x, mu, sigma)) or sigma <= 0:
raise ValueError("Use finite x, mu and positive finite sigma")
z = (x - mu) / sigma
start = abs(z)
if start >= 8:
return 1.0 if z > 0 else 0.0
grid = np.linspace(start, 8, 2049)
weights = np.ones(2049)
weights[1:-1:2] = 4
weights[2:-1:2] = 2
tail = ((8 - start) / 2048) / 3 * np.dot(weights, normal_pdf(grid))
return 1 - tail if z >= 0 else tail
def uniform_interval(a, b, lower, upper):
if not all(np.isfinite(v) for v in (a, b, lower, upper)) or a >= b or lower > upper:
raise ValueError("Require finite ordered endpoints and a < b")
return max(0, min(b, upper) - max(a, lower)) / (b - a)
def main():
assert uniform_interval(-2, 2, -1, 1) == 0.5
assert uniform_interval(-2, 2, -3, 3) == 1
assert uniform_interval(-2, 2, 2, 3) == 0
np.testing.assert_allclose(normal_pdf([0, 1, -1]), [0.3989422804014327, 0.24197072451914337, 0.24197072451914337], rtol=0, atol=1e-12)
points = np.linspace(-10, 10, 161)
estimates = np.array([simpson_cdf(float(z)) for z in points])
independent = np.array([0.5 * erfc(-float(z) / sqrt(2)) for z in points])
np.testing.assert_allclose(estimates, independent, rtol=0, atol=1e-9)
assert np.all(np.diff(estimates) >= 0)
for lower, upper in ((-1, 1), (-4, 4), (-8, -7), (7, 8), (-2.3, .7), (0, 0)):
area = simpson_cdf(upper) - simpson_cdf(lower)
oracle = 0.5 * (erfc(-upper/sqrt(2)) - erfc(-lower/sqrt(2)))
np.testing.assert_allclose(area, oracle, rtol=0, atol=2e-9)
np.testing.assert_allclose(simpson_cdf(1) - simpson_cdf(-1), 0.682689492137, rtol=0, atol=2e-9)
np.testing.assert_allclose(simpson_cdf(5, 2, 3) - simpson_cdf(-1, 2, 3), 0.682689492137, rtol=0, atol=2e-9)
for args in ((0, 0, 0), (0, 0, -1), (np.nan, 0, 1), (0, np.inf, 1)):
for function in (normal_pdf, simpson_cdf):
try:
function(*args)
except ValueError:
pass
else:
raise AssertionError("Invalid Gaussian parameters accepted")
for args in ((2, 2, 0, 1), (-2, 2, 1, -1), (-2, 2, np.nan, 1)):
try:
uniform_interval(*args)
except ValueError:
pass
else:
raise AssertionError("Invalid uniform parameters accepted")
print("Gaussian interval [-1,1] ≈", simpson_cdf(1) - simpson_cdf(-1))
print("Largest sampled CDF error:", np.max(np.abs(estimates - independent)))
print("CDF budget 1e-9; two-CDF interval budget 2e-9; plotted +/-4σ omits tails")
if __name__ == "__main__":
main()Explore
In uniform mode, move a fixed-width interval entirely within the support. Predict the unchanged area, then move it across an edge and predict the decrease. Collapse the interval bounds to one point: area becomes zero while the density at that point can remain positive.
In normal mode, compare intervals one standard deviation wide near the mean and far into a tail. Change while shifting the interval by the same amount. Then scale and the interval’s distances from together. Standardized bounds explain why those coordinated changes preserve probability.
Common mistakes and counterexamples
Uniform means equal density within the support, not over the entire real line. Extending a constant positive height forever would give infinite area. Gaussian does not mean every symmetric interval has the same probability: its location and width relative to and matter.
For a normal density, substituting variance for changes both height and width. A curve drawn within four standard deviations also does not capture exactly all mass: about lies beyond the two drawing limits in total.
Numerical considerations
The Gaussian model integrates the positive tail from to using composite Simpson’s rule with 2048 subdivisions, then uses symmetry to obtain a CDF value. Beyond standard deviations it truncates the one-sided tail approximately; that omitted mass is less than , not mathematically zero.
The absolute CDF error budget is against independent math.erfc values. An interval subtracts two approximate CDFs, so its absolute budget is . This is not a promise of relative accuracy for tiny intervals or extreme tails. The drawn curve is not claimed to have exactly normalized area.
Engineering and ML connections
Uniform models describe deliberate random choices over bounded ranges. Gaussian models describe a specified noise or uncertainty shape with location and scale. A bell-shaped drawing alone does not establish that observed data are Gaussian. The interval calculation is conditional on the chosen model, and density values must be interpreted with their measurement units.
Exercises
Use exact fractions for uniform calculations and signed numbers for standardized endpoints. The Gaussian choices use approximate values explicitly.
Summary and checkpoints
Uniform probability is normalized overlap width; Gaussian probability is a standardized CDF difference. Check that you can obtain the uniform half-area exactly, standardize under , , and explain both the numerical error budgets and the positive tails beyond a finite drawing.