Maths for Machines
0 of 9 lessons done100 questions

Lesson 1 of 9

Random variables, PMFs, and expectation

A random variable is a number-labeling machine for uncertain outcomes; its distribution says how often each label appears.

Core lesson · about 5 minutes · 3 guided parts

At a school fair, each game result earns points. The result is random, while the scoring rule turns it into a number.

Your learning route

Build the idea one piece at a time

  1. Discrete distributions
  2. Expected value as a weighted balance point
  3. Turn a real payoff table into a decision
Random variables, PMFs, and expectation, made visible
random samples form a stable shape

Discrete distributions

A probability mass function places pieces of a one-unit probability pie on countable values.

A random variable X maps each outcome ω to a real number X(ω).

For discrete X, p(x)=P(X=x) is nonnegative and its values sum to 1.

The CDF F(x)=P(X≤x) accumulates mass and never decreases.

The underlying outcome can be descriptive, such as which card was drawn, while a random variable records a number such as its points. Different scoring rules on the same experiment create different random variables.

A PMF is a table of exact-value probabilities. Check that every entry is at least zero and that the entire table sums to one before using it for any calculation.

The CDF at x adds every mass at or below x. For a discrete variable it looks like a staircase: flat between possible values and jumping upward by p(x) at each value.

In symbolspX(x)=P(X=x); FX(x)=Σ over values t≤x of pX(t)

Worked example

X takes values 0, 1, 2 with probabilities 0.2, 0.5, 0.3. Find F(1).

  1. F(1) means P(X≤1).
  2. The qualifying values are 0 and 1.
  3. Add their masses: 0.2+0.5=0.7.

Answer: 0.7

Expected value as a weighted balance point

Expectation is the long-run average produced by weighting every value by its probability.

Multiply each possible value by how often it occurs, then add.

Expectation can be a value the variable never takes; a fair die has mean 3.5.

Linearity E[aX+b]=aE[X]+b holds even without independence.

Expectation is a weighted sum, not an ordinary average of the listed values. A value occurring with probability 0.9 must influence the balance point nine times as strongly as a value occurring with probability 0.1.

Linearity lets us price totals without finding their full joint distribution: E[X+Y]=E[X]+E[Y], even when X and Y depend on each other. Independence becomes important for many variance calculations, not for this expectation identity.

An insurer multiplies each possible claim amount by its probability and adds to obtain expected claim cost, then adds expenses and a risk margin to set premiums. Expectation is useful because it predicts portfolio averages, while it cannot describe tail risk for one customer by itself.

In symbolsE[X]=Σ over x of x·pX(x)

Worked example

A game pays ₹0 with probability 0.5, ₹10 with probability 0.3, and ₹30 with probability 0.2. What is the expected payout?

  1. Weight each payout: 0×0.5, 10×0.3, and 30×0.2.
  2. These contributions are 0, 3, and 6.
  3. Add them to get ₹9.

Answer: ₹9

Practical deep dive for this lesson

Turn a real payoff table into a decision

A distribution becomes useful when every possible numerical consequence and its probability are made explicit, checked, and summarized for the decision horizon.

List outcomes, map each to a profit or cost, and combine duplicate numerical values into one PMF entry. Check that probability sums to one before calculating expectation.

Multiply each value by its mass and add to obtain average payoff per repetition. For many independent repetitions, expected totals scale linearly, but actual cash needs can still be driven by variance and worst cases.

Compare expected payoff with fees, risk tolerance, and alternative actions. A positive expectation can coexist with a high chance of loss, so decisions usually need quantiles or variance in addition to the mean.

In symbolsexpected net payoff=Σ(outcome probability×net payoff)

Worked example

A game pays ₹40 with probability 0.25 and ₹0 otherwise, and costs ₹8 to enter. Find the net payoff distribution and expected net payoff.

  1. After the fee, a win gives ₹32 and a loss gives −₹8.
  2. Assign probabilities 0.25 to ₹32 and 0.75 to −₹8.
  3. Compute E[net]=0.25×32+0.75×(−8).
  4. The contributions 8 and −6 sum to an expected net payoff of ₹2.

Answer: ₹32 with probability 0.25, −₹8 with probability 0.75; expectation ₹2

Check your picture

If E[X]=4, what is E[3X−2]?

Reveal answer

10

This lesson versus the whole chapter

Your topic-specific practical example is above.

The final lesson collects five longer chapter-wide workflows for machine learning, LLMs, trading, physics, and everyday decisions.

Formula shelf

Symbols with meaning

Expected valueE[X]=Σx p(x) or ∫x f(x)dx

Probability-weighted long-run center.

VarianceVar(X)=E[X²]−E[X]²

Average squared spread around the mean.

CovarianceCov(X,Y)=E[(X−μX)(Y−μY)]

Signed joint movement.

Binomial massC(n,k)pᵏ(1−p)ⁿ⁻ᵏ

Probability of k successes in n iid binary trials.

Multinomial massn!/(∏ᵢnᵢ!) times ∏ᵢpᵢ raised to nᵢ

Joint counts from fixed iid categorical trials.

Hypergeometric massC(K,k)C(N−K,n−k)/C(N,n)

Success count from sampling a finite population without replacement.

Poisson massexp(−λ)λᵏ/k!

Probability of k arrivals at mean count λ.

Continuous interval probabilityP(a≤X≤b)=∫ₐᵇf(x)dx

Area of density over an interval.

Beta updateBeta(α,β)+s successes+f failures→Beta(α+s,β+f)

Update uncertainty about a Bernoulli probability.

Gaussian linear combinationaᵀX~N(aᵀμ,aᵀΣa)

Project a multivariate normal vector onto one direction.

Probability space(Ω,𝓕,P)

Outcomes, measurable events, and their probability measure.

Convergence in probabilityP(|Xₙ−X|>ε)→0

The chance of a visible error vanishes.

Lp convergenceE|Xₙ−X|ᵖ→0

Expected powered error vanishes.

z-scorez=(x−μ)/σ

Position measured in standard deviations.

Standard errorSD(X̄)=σ/√n

Sampling spread of an independent sample mean.

Before moving on

You are ready when you can…

  • Read PMFs, PDFs, and CDFs
  • Build probability statements from (Ω,𝓕,P) and interpret almost-sure claims
  • Compute expectation, variance, covariance, and correlation
  • Choose among categorical, multinomial, binomial, negative-binomial, hypergeometric, and Poisson stories
  • Match beta, gamma, lognormal, chi-square, Student-t, and multivariate normal models to their supports and assumptions
  • Use family relationships such as beta-Bernoulli updating, chi-square as gamma, and normal projections
  • Find continuous interval probabilities
  • Distinguish almost-sure, probability, Lp, and distributional convergence
  • State the assumptions and different conclusions of the classical LLN and CLT