Random Variables

Formal
(Random Variable)

A random variable XX is a measurable function X:ΩRX : \Omega \rightarrow \mathbb{R} that maps outcomes in the sample space to real numbers. All randomness comes from Ω\Omega; the function XX itself is deterministic.

P(X=x)P ⁣({ωΩX(ω)=x}).(1)P(X = x) \equiv P\!\left(\{\omega \in \Omega \mid X(\omega) = x\}\right). \tag{1}
(Discrete Random Variable)

XX is discrete if its image Im(X)={X(ω)ωΩ}\text{Im}(X) = \{X(\omega) \mid \omega \in \Omega\} is countable. It is characterised by a Probability Mass Function (PMF):

pX(x)=P(X=x),xpX(x)=1.(2)p_X(x) = P(X = x), \quad \sum_{x} p_X(x) = 1. \tag{2}
(Continuous Random Variable)

XX is continuous if its image is uncountable. It is characterised by a Probability Density Function (PDF) fX(x)0f_X(x) \geq 0 such that

P(aXb)=abfX(x)dx,fX(x)dx=1.(3)P(a \leq X \leq b) = \int_a^b f_X(x)\,dx, \quad \int_{-\infty}^{\infty} f_X(x)\,dx = 1. \tag{3}

Note: P(X=x)=0P(X = x) = 0 for any specific xx in the continuous case.

(Cumulative Distribution Function)

The CDF is defined for both discrete and continuous RVs:

FX(x)=P(Xx).(4)F_X(x) = P(X \leq x). \tag{4}

For continuous RVs: fX(x)=ddxFX(x)f_X(x) = \frac{d}{dx}F_X(x).

Intuition

A Random Variable is a type-safe parser for raw outcomes. The sample space Ω\Omega contains unstructured events — a coin toss result, an HTTP response, a user action. A random variable extracts a single numeric value of interest from that event.

raw outcome ω  ──[X : Ω → ℝ]──►  numeric value x
"packet arrived late"    ──►  latency_ms = 340

The PMF or PDF is then the frequency histogram of those numeric values across all possible outcomes, weighted by their probability.

ML Applications
  • Features and labels — every input feature and output label in supervised learning is an RV. Training a model is estimating the joint distribution P(Y,X1,,Xd)P(Y, X_1, \dots, X_d).
  • Model outputs — a classifier outputs P(Y=kX=x)P(Y = k \mid X = x), a conditional PMF over class labels. A regression model outputs an estimate of E[YX=x]\mathbb{E}[Y \mid X = x].
  • Loss functions as expectations — the expected loss E(x,y)P[(f(x),y)]\mathbb{E}_{(x,y) \sim P}[\ell(f(x), y)] is an expectation of an RV. Minimising training loss is an approximation of minimising this.
  • Latent variables — in models like GMMs and VAEs, hidden structure is represented as unobserved RVs that the model must infer.
Connections
  • #type/definition
  • #probability
  • #random-variables