Foundations to Frontier
Tests
A. Mathematical Foundations › A4 Probability Theory › Stochastic processes

Martingales (Intro)

A martingale is the mathematical form of a fair game: given everything so far, the expected next value equals the current one. Random walks, S² − n, likelihood ratios, Pólya urns, Itô integrals and Doob's 'best guess so far' are all martingales. Three theorems make them powerful: optional stopping (no stopping rule beats a fair game), martingale convergence, and maximal and concentration inequalities (Doob, Ville, Azuma). You will use them to compute hitting probabilities without recursions, and to monitor a robot's success rate continuously without inflating false alarms.

Level 0: Foundation

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

The gambler’s dream that never works

A gambler bets on fair coin flips with a “foolproof” plan: bet 1; after every loss, double the bet. Eventually a win comes and recovers everything plus 1. What could go wrong? A long losing streak needs a bet bigger than all the gambler’s money, and they’re wiped out. On average, the plan wins exactly nothing.

The rule behind this: in a fair game, whatever you’ve seen so far, your expected future fortune equals your fortune now. No clever betting or stopping rule can change that average. A process with this property is a martingale.

You can't beat a fair game: martingales
over 3000 players after up to 200 rounds: mean final wealth 99.6 (started at 100) · ahead 51% · ruined 44.1%
Twenty wealth paths are shown. "Double after a loss" wins small amounts very often, then a long losing streak wipes the player out. Betting a fraction never goes broke, but most paths drift down. Whatever the rule, as long as it only uses the past, the expected wealth stays 100: a martingale transform of a fair game is still fair (optional stopping).
Why engineers care

Martingales tell you when an estimate is “honest”, meaning it doesn’t drift on average. They give exact answers to “will the robot reach the dock before the battery dies?” They also let you monitor a system continuously without fooling yourself with false alarms. Learning-theory bounds, stochastic approximation and filtering proofs all run on them.

📝 Quick check (Level 0)
0/3 answered
  1. 1. In a fair game, your expected future fortune is…
  2. 2. The 'double after each loss' strategy, on average, wins…
  3. 3. Can a stopping rule turn a fair game into a winning one (bounded money and time)?

Level 1: Beginner

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

Definition

Let Fn\mathcal F_n be the information at time nn (a filtration, A4.3-1). MnM_n is a martingale if it is known at time nn (adapted), E∣Mn∣<∞\mathbb E\lvert M_n\rvert<\infty, and

E[Mn+1∣Fn]=Mn\mathbb E[M_{n+1}\mid\mathcal F_n] = M_n

If the condition is ≤\le instead, it’s a supermartingale (an unfavourable game). If it’s ≥\ge, a submartingale. Taking expectations: EMn=EM0\mathbb EM_n = \mathbb EM_0 for all nn.

Examples

  • Symmetric random walk SnS_n.
  • Compensated square Sn2−nS_n^2 - n: E[Sn+12∣Fn]=Sn2+1\mathbb E[S_{n+1}^2\mid\mathcal F_n] = S_n^2 + 1.
  • Exponential martingale eλSn/(cosh⁡λ)ne^{\lambda S_n}/(\cosh\lambda)^n.
  • Products of iid mean-1 positive factors. Likelihood ratios ∏q(xi)/p(xi)\prod q(x_i)/p(x_i) under pp are an example.
  • Doob martingale E[Z∣Fn]\mathbb E[Z\mid\mathcal F_n]: your best guess of ZZ as information arrives.
📝 Quick check (Level 1)
0/3 answered
  1. 1. For a martingale, E M₁₀₀ equals…
  2. 2. Which is a martingale for the simple random walk?
  3. 3. A game that's unfavourable to you is a…

Level 2: Intermediate

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

Optional stopping

A stopping time τ\tau is a rule whose decision “stop now?” uses only the past. If τ\tau is bounded, or Eτ<∞\mathbb E\tau<\infty with bounded increments, then

EMτ=EM0\mathbb EM_\tau = \mathbb EM_0

Gambler’s ruin in two lines. Stop the walk at 0 or NN, starting from kk.

  1. Apply it to SS: k=N⋅P(hit N)k = N\cdot P(\text{hit }N), so P(hit N)=k/NP(\text{hit }N) = k/N.
  2. Apply it to S2−nS^2 - n: k2=N2⋅kN−Eτk^2 = N^2\cdot\frac kN - \mathbb E\tau, so Eτ=k(N−k)\mathbb E\tau = k(N - k).

The conditions matter. “Stop the first time S=1S = 1” gives Sτ=1≠0S_\tau = 1\ne0. Here τ<∞\tau<\infty a.s. but Eτ=∞\mathbb E\tau = \infty, and the doubling strategy needs unbounded credit. With finite resources, no strategy beats a fair game.

Martingale transforms

If you bet HkH_k (decided from the past) on each fair increment, your wealth ∑Hk(Mk−Mk−1)\sum H_k(M_k - M_{k-1}) is still a martingale. It’s the discrete version of the Itô integral (A4.4-5).

🐍 Exercise 1: martingales and optional stopping
Check that S_n, S_n² − n and the exponential martingale keep their expectation constant. Then stop fair walks at 0 or 10 starting from 3, and confirm the optional-stopping answers P(hit 10) = 0.3 and E τ = 21.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Fair walk from 4, stop at 0 or 10: P(hit 10)?
  2. 2. Same walk: E τ?
  3. 3. 'Stop when ahead by 1' fails optional stopping because…

Level 3: Advanced

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

Proof of optional stopping (bounded τ)

Let τ≤K\tau\le K. Write Mτ=M0+∑k=1K1{τ≥k}(Mk−Mk−1)M_\tau = M_0 + \sum_{k=1}^K\mathbf 1\{\tau\ge k\}(M_k - M_{k-1}).

  1. Predictability. {τ≥k}={τ≤k−1}c∈Fk−1\{\tau\ge k\} = \{\tau\le k - 1\}^c\in\mathcal F_{k-1}.
  2. Each term has mean zero. E[1{τ≥k}(Mk−Mk−1)]=E[1{τ≥k} E[Mk−Mk−1∣Fk−1]]=0\mathbb E[\mathbf 1\{\tau\ge k\}(M_k - M_{k-1})] = \mathbb E[\mathbf 1\{\tau\ge k\}\,\mathbb E[M_k - M_{k-1}\mid\mathcal F_{k-1}]] = 0.
  3. Sum up. EMτ=EM0\mathbb EM_\tau = \mathbb EM_0. ∎ For unbounded τ\tau, apply this to τ∧K\tau\wedge K and let K→∞K\to\infty under dominated convergence.

Convergence and maximal inequalities

  • Martingale convergence theorem. An L1L^1-bounded martingale converges a.s. Bounded or non-negative martingales always converge. Examples: the Pólya urn fraction, and posterior probabilities as data accumulate.
  • Doob’s maximal inequality. P(max⁡k≤nMk≥a)≤E[Mn+]/aP(\max_{k\le n}M_k\ge a)\le\mathbb E[M_n^+]/a.
  • Ville’s inequality. A non-negative supermartingale with M0=1M_0 = 1 satisfies P(sup⁡nMn≥1/α)≤αP(\sup_nM_n\ge1/\alpha)\le\alpha, uniformly over all time.
  • Azuma–Hoeffding. If ∣Mk−Mk−1∣≤ck\lvert M_k - M_{k-1}\rvert\le c_k, then P(Mn−M0≥t)≤e−t2/(2∑ck2)P(M_n - M_0\ge t)\le e^{-t^2/(2\sum c_k^2)}. This powers McDiarmid (A4.3-6).

Doob decomposition

Every adapted integrable process splits as Xn=X0+Mn+AnX_n = X_0 + M_n + A_n: a martingale plus a predictable drift An=∑E[Xk−Xk−1∣Fk−1]A_n = \sum\mathbb E[X_k - X_{k-1}\mid\mathcal F_{k-1}]. For Sn2S_n^2, An=nA_n = n. This is the discrete root of quadratic variation and of Itô’s lemma.

Exercise 3.1: Show the Pólya urn fraction is a martingale

With rr red balls out of tt, the next fraction is r+1t+1\frac{r+1}{t+1} with probability r/tr/t, and rt+1\frac r{t+1} otherwise. Its expectation is r(r+1)+(t−r)rt(t+1)=rt\frac{r(r+1) + (t - r)r}{t(t+1)} = \frac rt.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Ville's inequality bounds P(sup M_n ≥ 1/α) for a non-negative supermartingale starting at 1 by…
  2. 2. A bounded martingale…
  3. 3. In S_n² = M_n + A_n, the predictable part is…

Level 4: Expert

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

Monitoring a success rate without fooling yourself

A deployed grasping robot should succeed 95% of the time. Engineers want an alarm as soon as performance degrades. Re-running a standard 95% test after every trial (“peeking”) makes the false-alarm rate climb toward certainty as time goes on: about 30% within 1000 trials here. The fix is a martingale. The likelihood ratio Mn=∏ip1xi(1−p1)1−xip0xi(1−p0)1−xiM_n = \prod_i\frac{p_1^{x_i}(1-p_1)^{1-x_i}}{p_0^{x_i}(1-p_0)^{1-x_i}} has mean 1 under the healthy rate p0p_0. By Ville’s inequality, alarming when Mn≥1/αM_n\ge1/\alpha keeps false alarms below α\alpha no matter how often you look. That’s Wald’s SPRT, and the basis of modern anytime-valid confidence sequences and e-values (Wald, 1945; Howard et al., 2021; Ramdas et al., 2023).

🐍 Exercise 2 (research): anytime-valid monitoring with a likelihood-ratio martingale
Monitor 1500 healthy robots (95% success) for 1000 trials each. Show that peeking at a fixed-n z-test after every trial gives far more than 5% false alarms, while the likelihood-ratio martingale with Ville's threshold 1/α stays below 5%. Then check that it detects degradation to 85% quickly.

Martingales in AI, robotics and aerospace

  • Stochastic approximation and RL. Convergence proofs for SGD, TD and Q-learning decompose the error into a martingale-difference noise term plus a drift, then apply martingale convergence (Robbins and Siegmund, 1971; Bertsekas and Tsitsiklis, 1996).
  • Bandit and RL confidence sets. Self-normalized martingale bounds give the confidence ellipsoids of LinUCB and optimism-based RL (Abbasi-Yadkori et al., 2011).
  • Sequential testing and A/B monitoring. SPRT, e-processes and confidence sequences give anytime-valid inference for online experiments and safety monitors.
  • Filtering consistency. The innovation sequence of a correct Kalman filter is a martingale-difference sequence. Checking this (“innovation whiteness tests”) is a standard filter-tuning diagnostic (Bar-Shalom et al., 2001).
  • Stochastic stability. Supermartingale (Lyapunov-like) certificates prove that stochastic systems reach goals or stay safe with high probability (Kushner, 1967; Chakarov and Sankaranarayanan, 2013).

References

  1. D. Williams (1991). Probability with Martingales. Cambridge University Press.
  2. J. L. Doob (1953). Stochastic Processes. Wiley.
  3. J. Ville (1939). Étude critique de la notion de collectif. Gauthier-Villars.
  4. A. Wald (1945). “Sequential tests of statistical hypotheses.” Annals of Mathematical Statistics, 16(2).
  5. K. Azuma (1967). “Weighted sums of certain dependent random variables.” Tôhoku Mathematical Journal, 19(3).
  6. S. Howard, A. Ramdas, J. McAuliffe, J. Sekhon (2021). “Time-uniform, nonparametric, nonasymptotic confidence sequences.” Annals of Statistics, 49(2).
  7. A. Ramdas, P. Grünwald, V. Vovk, G. Shafer (2023). “Game-theoretic statistics and safe anytime-valid inference.” Statistical Science, 38(4).
  8. H. Robbins, D. Siegmund (1971). “A convergence theorem for non negative almost supermartingales and some applications.” Optimizing Methods in Statistics.
  9. D. Bertsekas, J. Tsitsiklis (1996). Neuro-Dynamic Programming. Athena Scientific.
  10. H. Kushner (1967). Stochastic Stability and Control. Academic Press.