A random variable is the numerical quantity attached to an uncertain event or measurable attribute. Its allowed values, or ranges of values, are associated with probabilities: adult weight, height, a stock index crossing a threshold, and infection count can all be modeled this way. The variable gives probability a concrete target—probability of what value or range occurring. section 5.1.1
A discrete random variable takes values from a countable set. For quantized adult weight, let X = 1 mean less than 60 kg, X = 2 mean 60–90 kg, and X = 3 mean more than 90 kg. A probability distribution assigns a probability to every allowed value, such as P(X = 1) = 0.25, P(X = 2) = 0.5, and P(X = 3) = 0.25. The possible categories must cover all outcomes and not overlap, so their probabilities sum to 1. section 5.1.1 section 5.2 section 5.3.2
Table 5.1 Frequency table for the weights of adults in the city of Statsville
| S1: Less than 60 kg |
S2: Between 60 and 90 kg |
S3: More than 90 kg |
|---|---|---|
| 25,000 |
50,000 |
25,000 |
This frequency table turns a population into the three possible values of a discrete weight variable. Dividing each count by the total population yields its probability distribution. section 5.1.2 section 5.2
A continuous random variable can take values at arbitrarily fine granularity. Start by narrowing discrete buckets; in the limit, infinitely many infinitesimal intervals form a probability density function p(x). Here p(x) represents the probability of X lying in an infinitesimally small interval from x to x + δx, rather than an ordinary discrete point probability. Across the full domain, the density integrates to 1. section 5.6 section 5.10
Random variables support several core probability operations:
- Sampling draws an arbitrary allowed value; over many draws, higher-probability values appear more often. section 5.10
- Expected value is the long-run sample average, or the probability-weighted sum of possible values; for continuous variables, the sum becomes an integral. section 5.7.1
- Joint distributions assign probabilities to combinations of values from multiple variables, making dependence or independence explicit. section 5.4.2 section 6.1.3
From binary outcome to classification loss
A Bernoulli random variable encodes one success-or-failure trial as X = 1 with probability π and X = 0 with probability 1 − π. The same representation scales to a four-class image classifier: X can denote cat, dog, airplane, or automobile, while a probability vector represents the predicted distribution. Cross-entropy compares that prediction with the one-hot ground-truth distribution during training. section 5.9.5 section 6.3
Uniform variable in PyTorch
For a uniform continuous variable on [a, b], density is constant inside the interval and zero outside; the total area is 1. PyTorch's Uniform distribution can evaluate log probability, while sampled means and variances can be compared with the distribution's mean and variance. section 5.9.1




