Foundations to Frontier
Tests
A. Mathematical Foundations › A4 Probability Theory › Basics

Random Variables: Discrete and Continuous

A random variable is a numerical summary of a random outcome. Formally it's a function from the sample space to the real numbers, and its distribution records how probability spreads over its values. Discrete variables put probability on points, continuous ones spread it as a density, and mixed ones (such as censored lifetimes) do both. Functions of random variables are random variables, which is how uncertainty propagates through robot kinematics, and why linearization can mislead.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Putting a number on chance

When you roll two dice, you often don’t care about the exact pair, only the total. When you toss 10 coins, you might only care how many came up heads. A rule that turns each random outcome into a number is a random variable.

Some random variables jump between separate values: a dice total, a count of heads. Those are discrete. Others can be any value in a range: a height, a time, a temperature, how far a dart lands from the bullseye. Those are continuous.

Random variables: functions from outcomes to numbers
X(a, b) =
23456734567845678956789106789101178910111221/3632/3643/3654/3665/3676/3685/3694/36103/36112/36121/36
Hover a value: every outcome ω with X(ω) = x lights up, and P(X = x) counts them. The probabilities sum to 1. Different functions of the same experiment give different distributions.
Why engineers care

A robot doesn’t know its joint angles exactly. Each one is a random variable, so the position of its hand, a function of those angles, is random too. Engineers need to know that distribution to decide whether the gripper will safely clear an obstacle.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The number of heads in 2 tosses can be…
  2. 2. A person's exact height is…
  3. 3. A random variable turns outcomes into…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Definition and distribution

A random variable is a function X:Ω→RX:\Omega\to\mathbb R. Its distribution tells you P(X∈B)P(X\in B) for sets BB of values: P(X∈B)=P({ω:X(ω)∈B})P(X\in B) = P(\{\omega: X(\omega)\in B\}). You find it by collecting the outcomes that give each value.

Example: for X=a+bX = a + b on two dice, P(X=7)=6/36P(X = 7) = 6/36 and P(X=2)=1/36P(X = 2) = 1/36.

Type Probability lives on Described by Example
discrete points x1,x2,…x_1, x_2, \dots PMF p(x)=P(X=x)p(x) = P(X = x) dice sum, # defects
continuous intervals density ff: P(a≤X≤b)=∫abfP(a\le X\le b) = \int_a^bf waiting time, sensor noise
mixed both CDF (A4.1-6) censored lifetime

For a continuous XX, P(X=x)=0P(X = x) = 0 for every single xx. A density value is a probability per unit length, and it can exceed 1.

📝 Quick check (Level 1)
0/3 answered
  1. 1. P(sum of two dice = 5) = ?
  2. 2. For a continuous X, P(X = 2.5) = ?
  3. 3. Can a density value exceed 1?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Functions of random variables

If XX is a random variable and gg is a function, then Y=g(X)Y = g(X) is a random variable. For discrete XX, P(Y=y)=∑x:g(x)=yP(X=x)P(Y = y) = \sum_{x:g(x) = y}P(X = x). For continuous XX, work through the CDF: P(Y≤y)=P(g(X)≤y)P(Y\le y) = P(g(X)\le y), then differentiate (A4.1-6).

Indicators: events as random variables

1A(ω)=1\mathbf 1_A(\omega) = 1 if ω∈A\omega\in A, else 0. It’s a discrete random variable with E[1A]=P(A)\mathbb E[\mathbf 1_A] = P(A). Counts are sums of indicators. “How many of these 253 people share my birthday?” is ∑1Ai\sum\mathbf 1_{A_i}, so its expectation is ∑P(Ai)\sum P(A_i) even though the events are dependent. That’s linearity of expectation (A4.1-7).

A continuous example from geometry

Throw darts uniformly at a unit disk, and let RR be the distance from the centre. Then P(R≤r)=πr2π=r2P(R\le r) = \frac{\pi r^2}{\pi} = r^2, so the density is f(r)=2rf(r) = 2r. Darts land far out more often because the outer rings have more area. This is a frequent bug in “uniform disk” sampling: taking rr uniform clusters points at the centre. The fix is r=Ur = \sqrt U.

🐍 Exercise 1: random variables on the dice space
Compute the distribution of several random variables on two dice (sum, max, |difference|) by pushing the uniform measure forward. Transform distributions through further functions.
📝 Quick check (Level 2)
0/3 answered
  1. 1. E[1_A] = ?
  2. 2. Uniform darts on a disk: P(R ≤ 0.5) = ?
  3. 3. To sample uniformly in a disk with polar coordinates, take r = …

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Measurability

Formally, a random variable must be measurable: {X≤x}∈F\{X\le x\}\in\mathcal F for every xx, so its probability is defined. All functions you’ll meet in practice (continuous, piecewise, limits of such) are measurable. The distribution PX(B)=P(X−1(B))P_X(B) = P(X^{-1}(B)) is the pushforward of PP by XX. Once you have it, you can usually forget Ω\Omega entirely.

Why P(X = x) = 0 doesn’t mean “impossible”

For a continuous XX, every exact value has probability 0, yet some value happens. Countable additivity isn’t violated, because there are uncountably many values. Probability 0 means “never happens” only for countably many alternatives.

Mixed random variables

A battery test stops at time TT. The observed X=min⁡(L,T)X = \min(L, T) is continuous below TT with an atom P(X=T)=P(L≥T)P(X = T) = P(L\ge T). Neither a PMF nor a density describes it alone. The CDF does (A4.1-6). Censoring is everywhere in reliability, survival analysis and RL episode cut-offs.

Exercise 3.1: Find the PMF of the maximum of two dice

P(max⁡≤k)=(k/6)2P(\max\le k) = (k/6)^2, so P(max⁡=k)=k2−(k−1)236=2k−136P(\max = k) = \frac{k^2 - (k-1)^2}{36} = \frac{2k - 1}{36}.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The distribution of X is the ___ of P.
  2. 2. min(L, T) for an exponential L is…
  3. 3. P(max of two dice = 6) = ?

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Uncertainty propagation through nonlinear maps

A 2-link arm’s joint angles are uncertain, q∼N(qˉ,Σ)\mathbf q\sim\mathcal N(\bar{\mathbf q}, \Sigma), from encoder noise or calibration error. The hand position x=f(q)\mathbf x = f(\mathbf q) is then a random variable. There are two ways to describe it:

  • Linearization (EKF-style) approximates x≈f(qˉ)+J(q−qˉ)\mathbf x\approx f(\bar{\mathbf q}) + J(\mathbf q - \bar{\mathbf q}), giving N(f(qˉ),JΣJ⊤)\mathcal N(f(\bar{\mathbf q}), J\Sigma J^\top). It’s accurate for small noise.
  • Monte Carlo samples the exact distribution. For large noise this is a curved “banana” that can’t exceed the arm’s reach. Its mean is shifted toward the base, which linearization misses.

The unscented transform (Julier and Uhlmann, 2004) and particle methods exist because of this. Long et al. (2012) showed the “banana distribution” of robot poses, and Barfoot (2017) treats propagation on rotation groups.

🐍 Exercise 2 (research): when does linearized uncertainty fail?
Propagate Gaussian joint-angle noise through 2-link forward kinematics by Monte Carlo and by first-order linearization (JΣJᵀ). Measure the mean shift and covariance error for small vs large noise, and confirm that samples respect the reach limit.

Random variables across engineering and AI

  • Reparametrization. Writing z=μ+σεz = \mu + \sigma\varepsilon with ε∼N(0,1)\varepsilon\sim\mathcal N(0,1) expresses a random variable as a deterministic function of a fixed one. That lets gradients flow through sampling (Kingma and Welling, 2014, VAEs).
  • Generative models and normalizing flows are functions of random variables: x=gθ(z)x = g_\theta(z). Their density follows from the change-of-variables formula (A4.1-6, A3.2-8).
  • Sensor models treat a measurement as a random variable z=h(x)+vz = h(x) + v. Its distribution is the likelihood that Bayes filters use (A4.1-3).
  • Reliability data are often censored (mixed type). Ignoring the atom biases lifetime estimates. Survival analysis (Kaplan and Meier, 1958) handles it.

References

  1. D. Bertsekas, J. Tsitsiklis (2008). Introduction to Probability, 2nd ed., Ch. 2–3. Athena Scientific.
  2. G. Grimmett, D. Stirzaker (2020). Probability and Random Processes, 4th ed. Oxford.
  3. S. Julier, J. Uhlmann (2004). “Unscented filtering and nonlinear estimation.” Proceedings of the IEEE, 92(3).
  4. A. Long, K. Wolfe, M. Mashner, G. Chirikjian (2012). “The banana distribution is Gaussian: a localization study with exponential coordinates.” RSS.
  5. T. Barfoot (2017). State Estimation for Robotics. Cambridge.
  6. D. Kingma, M. Welling (2014). “Auto-encoding variational Bayes.” ICLR.
  7. E. Kaplan, P. Meier (1958). “Nonparametric estimation from incomplete observations.” JASA, 53.