14. Review of Probability Theory
Real systems face noise and uncertainty that deterministic state equations can’t capture. This chapter reviews the probability theory needed to describe stochastic systems, preparing the ground for state estimation.
Slides
Section titled “Slides”Interactive example
Section titled “Interactive example”Sum of two uniform random variables
Section titled “Sum of two uniform random variables”The Central Limit Theorem says that summing enough independent, identically distributed random variables produces something that looks Gaussian, regardless of the original distribution. To see this in action, start with two random variables X1, X2, each uniform on [0, 1], and look at the distribution of their sum Z = X1 + X2.
Below, 100,000 samples of each are drawn, summed, and binned into a normalized histogram (an empirical estimate of the pdf p_Z(x)). The mean and variance are checked against the theoretical values for a sum of two independent Uniform(0,1) variables: mean = 1, variance = 1/6.
import numpy as npimport matplotlibmatplotlib.use("Agg")import matplotlib.pyplot as pltimport io, base64
# Generate two random arrays of size 1e5, uniform on [0, 1]X1 = np.random.rand(1, int(1e5))X2 = np.random.rand(1, int(1e5))
# Compute the sum of X1 and X2Z = X1 + X2
# Compute the histogram of Z with 100 binsfz, x = np.histogram(Z, bins=100)
# Normalize the histogram by the area and the bin widthw_fz = x[-1] / len(fz)fz = fz / np.sum(fz) / w_fz
print("mean(Z) =", np.mean(Z), " (theory: 1.0)")print("var(Z) =", np.var(Z), " (theory: 1/6 =", 1 / 6, ")")
# Plot the histogram as a bar chartplt.figure(figsize=(6, 4))plt.bar(x[:-1], fz, width=w_fz)plt.xlabel("$x$")plt.ylabel("$p_Z(x)$")plt.title("Sum of 2 uniform random variables")
buf = io.BytesIO()plt.savefig(buf, format="png", dpi=90)plot_b64 = base64.b64encode(buf.getvalue()).decode()Sum of two uniform random variables (mcimp/codes/probability_review/sum_2rv.py)
Click "Run" to execute.
Sum of three uniform random variables
Section titled “Sum of three uniform random variables”Adding one more uniform random variable pushes the distribution noticeably closer to a bell curve. Here Z = X1 + X2 + X3, with each X_i uniform on [0, 1].
Compare the shape below to the two-variable case above: the single “tent” shape has smoothed into something visibly closer to Gaussian, illustrating the Central Limit Theorem’s convergence even after just three terms. Theoretical mean = 1.5, variance = 1/4.
import numpy as npimport matplotlibmatplotlib.use("Agg")import matplotlib.pyplot as pltimport io, base64
# Generate three random arrays of size 1e5, uniform on [0, 1]X1 = np.random.rand(1, int(1e5))X2 = np.random.rand(1, int(1e5))X3 = np.random.rand(1, int(1e5))
# Compute the sum of the three arraysZ = X1 + X2 + X3
# Compute the histogram of Z with 100 binsfz, x = np.histogram(Z, bins=100)
# Normalize the histogram by the area and the bin widthw_fz = x[-1] / len(fz)fz = fz / np.sum(fz) / w_fz
print("mean(Z) =", np.mean(Z), " (theory: 1.5)")print("var(Z) =", np.var(Z), " (theory: 1/4 =", 1 / 4, ")")
# Plot the histogram as a bar chartplt.figure(figsize=(6, 4))plt.bar(x[:-1], fz, width=w_fz)plt.xlabel("$x$")plt.ylabel("$p_Z(x)$")plt.title("Sum of 3 uniform random variables (looks Gaussian already)")
buf = io.BytesIO()plt.savefig(buf, format="png", dpi=90)plot_b64 = base64.b64encode(buf.getvalue()).decode()Sum of three uniform random variables (mcimp/codes/probability_review/sum_3rv.py)
Click "Run" to execute.