• A time to give thanks and pray for our university
  • All are welcome
  • Sandwich lunch provided at no charge
  • Come late or leave early if you need to
  • Please RSVP by Friday, November 13, so that we can prepare enough food
  • But if you forget to RSVP, come anyway

MATH 565 — Fall 2026

Selected Topics

Fred J. Hickernell

November 23, 2026

Course Map

Monte Carlo foundations, methods, and applications
Probability
Statistics
Analysis
Computer
Science
Estimation
Error
Assessment
Variance
Reduction
Multilevel
Monte Carlo
Stochastic
Optimization
Monte Carlo
Tree Search
High-Performance
Computing

Choose how to compute, optimize, search, and allocate

Parallel Computing

Monte Carlo foundations, methods, and applications
Practice

Evaluate different sample points on several processors to reduce elapsed time

Parallel computing

Monte Carlo foundations, methods, and applications
Practice

Modern CPUs and GPUs can evaluate many operations concurrently

  • Monte Carlo function values are often pleasingly parallel: samples can be evaluated independently
  • Parallel random-number streams must remain nonoverlapping and statistically sound
  • GPU arithmetic is often optimized for 32-bit floating point rather than 64-bit floating point
  • Reduced precision may lose significant digits but can increase throughput substantially
  • GPUs help most when there are many similar operations
    Launch and data-transfer costs can dominate small problems

Parallelism changes computational cost

It does not repair biased estimators or poor sampling designs

CPU and GPU Monte Carlo

Monte Carlo foundations, methods, and applications
Practice

The prepared laptop demonstration compares

  • NumPy CPU float64 and float32
  • PyTorch CPU float32 and available GPU float32
  • One expectation and many expectations evaluated in batches

Check the actual backend, include generation and evaluation, and synchronize GPU timing

A faster processor helps when the workload outweighs its overhead

Reading the CPU/GPU experiment

  • Read speedup as CPU time / GPU time: above one favors the GPU
  • Name the baseline: NumPy CPU64, NumPy CPU32, or Torch CPU32
    The ratio compares complete implementations, including their random generators
  • Small jobs can favor CPUs; larger jobs spread fixed GPU overhead over more work
  • Generation can dominate: inspect stage timings before attributing a gap to evaluation

End-to-end time determines the practical gain

Faster computation and statistical accuracy

Compare a baseline and a faster implementation: single-core / multicore CPU, or CPU / GPU
For fixed sampling method; runtime proportional to sample count

\[\begin{equation*} \left. \begin{aligned} s=\frac{\operatorname{time}_{\mathrm{baseline}}(n)}{\operatorname{time}_{\mathrm{faster}}(n)}>1 &\quad\implies\quad n_{\mathrm{faster}}\approx s\,n_{\mathrm{baseline}}\\ \operatorname{error}(n)\approx A n^{-p} &\quad\implies\quad \frac{\operatorname{error}(n_{\mathrm{faster}})}{\operatorname{error}(n_{\mathrm{baseline}})}\approx\frac1{s^p} \end{aligned} \right\} \quad\begin{gathered}\alerttext{for the same}\\\alerttext{time budget}\end{gathered} \end{equation*}\]

Error: RMSE for IID/RQMC; absolute-error bound for QMC

Method Power \(p\) Conditions
IID \(1/2\) Finite contribution variance
QMC \(\approx1\) Sufficient smoothness and a suitable design
RQMC \(\approx3/2\) Sufficient smoothness and suitable scrambling

Speedup \(s=16\): about \(1/4\) of the IID RMSE, \(1/16\) of the QMC bound, \(1/64\) of the RQMC RMSE

Computing many expectations together

  • Reuse one sample batch across many functions to share generation cost and expose matrix work
  • More expectations add outputs; each expectation still uses the same \(n\) samples
  • Shared inputs give correlated estimates; their spread is not a standard error
  • Batch samples and functions to bound memory; measure the useful workload and backend

More outputs can improve throughput without improving accuracy per output

Multilevel Monte Carlo

Monte Carlo foundations, methods, and applications
Estimation

Combine many cheap coarse samples with fewer correction samples to reduce the cost of accurately estimating an expectation with high dimensional random input

Common MLMC glossary

MLMC glossary: contributions

The same notation works for \(L=2\) or many levels

Symbol Meaning
\(\ell\), \(L\) Level index and finest included level
\(d_\ell\), \(f_{d_\ell}\) Resolution and approximate output function
\(Y_\ell\) Cheap output at level 1; fine output minus coarse output at later levels
\(\mu_\ell\), \(\hmu_\ell\) Contribution mean \(\Ex(Y_\ell)\) and its estimate
\(\mu_{d_L}\) Mean of the finest approximation: \(\sum_\ell\mu_\ell\)
\(V_\ell\) IID contribution variance \(\var(Y_\ell)\)

MLMC glossary: samples and work

Symbol Meaning
\(n_\ell\), \(n=\sum_\ell n_\ell\) Level sample count and total sample count
\(\$_\ell\) Work for one complete contribution at level \(\ell\)
\(w_\ell\) Sample allocation weight: \(n_\ell/n=w_\ell/\sum_k w_k\)

Total work, for two or many levels

\[ C=n_1\$_1+n_2\$_2+\cdots+n_L\$_L =\sum_{\ell=1}^L n_\ell\$_\ell \]

\(C(\varepsilon)\) is the work needed at error tolerance \(\varepsilon\)

Sample counts and work shares differ

Two-level Monte Carlo

Monte Carlo foundations, methods, and applications
Estimation

We want to compute \(\Ex\bigl[f_{d}(\vX_{1:d})\bigr]\) for large \(d\)

But large \(d\) costs more, e.g., \(\$\bigl(f_d(\vX_{1:d})\bigr)\propto d\)

  • Computational finance: \(d=\) time steps \(\times\) number of assets
  • ODE/PDE models with random fields: \(d=\) grid points representing the field

Choose \(d_1\ll d_2=d\); couple the outputs to reduce the variance of their difference

\[\begin{align*} Y_1&=f_{d_1}(\vX_{1:d_1})& &\alerttext{cheap}\text{ approximation}\\ Y_2&=f_{d_2}(\vX_{1:d_2})-f_{d_1}(\vX_{1:d_1})& &\alerttext{expensive}\text{ correction} \end{align*}\]

\[ \mu=\Ex\{f_{d}(\vX_{1:d})\}=\Ex(Y_1)+\Ex(Y_2) \]

Estimate the cheap part often and the expensive correction less often, if its error is easier to control

Coupling coarse and fine Brownian paths

Choose nested monitoring grids on \([0,T]\) with \(d_2=\kappa d_1\), \(\kappa>1\)

  • Order the Brownian values \(\vX\) with the coarse-grid values first
  • Use a Brownian bridge to add values at the extra fine-grid times

For an option, \(f_{d_\ell}(\vX_{1:d_\ell})\) computes its discounted payoff
using the path values at \(d_\ell\) monitoring times

\[\begin{align*} Y_1&=f_{d_1}(\vX_{1:d_1})&&\alerttext{cheap}\text{ coarse payoff}\\ Y_2&=f_{d_2}(\vX_{1:d_2})-f_{d_1}(\vX_{1:d_1})&&\alerttext{expensive}\text{ payoff correction} \end{align*}\]

  • Estimate \(\Ex(Y_1)\) from coarse-only paths
  • Estimate \(\Ex(Y_2)\) from a separate independent set of bridge-refined paths

Same path, two payoffs in \(Y_2\); aim for small variance of their difference

Random two-level estimates: IID or RQMC

Estimate \(\mu_\ell=\Ex(Y_\ell)\) with uncorrelated level sample means: \(\operatorname{cov}(\hmu_1,\hmu_2)=0\)
Independent sample sets \(\{Y_{i,1}\}_{i=0}^{n_1-1}\) and \(\{Y_{i,2}\}_{i=0}^{n_2-1}\) ensure this condition

\[\begin{align*} \hmu&=\hmu_1+\hmu_2& \hmu_\ell&=\frac1{n_\ell}\sum_{i=0}^{n_\ell-1}Y_{i,\ell}\\ \var(\hmu)&=\var(\hmu_1)+\var(\hmu_2)& C&=n_1\$_1+n_2\$_2 \end{align*}\]

For unbiased level estimates, model \(\operatorname{RMSE}(\hmu_\ell)\approx A_\ell n_\ell^{-p}\)

\[ \operatorname{MSE}(\hmu) =\var(\hmu) \approx\frac{A_1^2}{n_1^{2p}}+\frac{A_2^2}{n_2^{2p}} \]

  • IID: \(p=1/2\), \(A_\ell^2=\var(Y_\ell)\); the variance model is exact
  • RQMC: \(p\) and \(A_\ell\) depend on smoothness, design, and randomization
    Points within each sample set may be dependent

Allocating work optimally

Monte Carlo foundations, methods, and applications
Estimation

For independent unbiased random estimates, minimize the MSE model

\[ \frac{A_1^2}{n_1^{2p}}+\frac{A_2^2}{n_2^{2p}} \quad\text{subject to}\quad n_1\$_1+n_2\$_2=C \]

The optimal continuous allocation satisfies

\[ \frac{n_1}{n_2} =\left(\frac{A_1^2\$_2}{A_2^2\$_1}\right)^{1/(2p+1)} \]

IID (\(p=1/2\), \(A_\ell^2=V_\ell\)): sample allocation weights

\[ w_\ell=\frac{A_\ell}{\sqrt{\$_\ell}}=\sqrt{\frac{V_\ell}{\$_\ell}} \qquad\frac{n_1}{n_2}=\frac{w_1}{w_2} \qquad\frac{n_\ell}{n}=\frac{w_\ell}{w_1+w_2} \]

More points for larger error amplitude; fewer for larger cost per point

Deriving the two-level allocation

For the random case, treat \(n_1,n_2>0\) as continuous; fix total work \(C\)

\[ \underbrace{\mathcal L}_{\text{Lagrangian}} =\frac{A_1^2}{n_1^{2p}}+\frac{A_2^2}{n_2^{2p}} +\lambda(n_1\$_1+n_2\$_2-C) \]

\[\begin{align*} \frac{\partial\mathcal L}{\partial n_\ell}=0 &\implies\frac{2pA_\ell^2}{n_\ell^{2p+1}}=\lambda\$_\ell \qquad(\ell=1,2)\\ \frac{A_1^2}{\$_1n_1^{2p+1}} &=\frac{A_2^2}{\$_2n_2^{2p+1}} \implies\frac{n_1}{n_2} =\left(\frac{A_1^2\$_2}{A_2^2\$_1}\right)^{1/(2p+1)} \end{align*}\]

The sample allocation weights give

\[ w_\ell=\left(\frac{A_\ell^2}{\$_\ell}\right)^{1/(2p+1)} \qquad n_\ell=\frac{Cw_\ell}{\$_1w_1+\$_2w_2} =\frac{nw_\ell}{w_1+w_2} \]

At the optimum, each level buys the same marginal MSE reduction per unit work

IID: MSE decrease per unit work

Treat \(n_\ell>0\) as continuous; keep \(A_\ell,\$_\ell\) fixed

\[\begin{align*} \operatorname{MSE}_\ell&=\frac{A_\ell^2}{n_\ell} &\implies\quad \frac{\mathrm d\operatorname{MSE}_\ell}{\mathrm dn_\ell} &=-\frac{A_\ell^2}{n_\ell^2}\\ \operatorname{cost}_\ell&=n_\ell\$_\ell &\implies\quad \frac{\mathrm d\operatorname{cost}_\ell}{\mathrm dn_\ell}&=\$_\ell \end{align*}\]

The MSE decrease per unit work is the ratio of these derivatives

\[ -\frac{\mathrm d\operatorname{MSE}_\ell}{\mathrm d\operatorname{cost}_\ell} =-\frac{\mathrm d\operatorname{MSE}_\ell/\mathrm dn_\ell} {\mathrm d\operatorname{cost}_\ell/\mathrm dn_\ell} =\frac{A_\ell^2}{\$_\ell n_\ell^2} \]

IID: interpreting the optimal allocation

Write \(\operatorname{err}_\ell^2=\operatorname{MSE}_\ell\) and \(w_\ell=A_\ell/\sqrt{\$_\ell}\)

\[ -\frac{\mathrm d\operatorname{MSE}_\ell}{\mathrm d\operatorname{cost}_\ell} =\frac{A_\ell^2}{\$_\ell n_\ell^2} =\frac{\operatorname{err}_\ell^2}{\operatorname{cost}_\ell} =\left(\frac{w_\ell}{n_\ell}\right)^2 \]

If one level has a larger value, moving a little work to it lowers total MSE

At the optimum, both derivative magnitudes equal \(\lambda\)

\[ \left(\frac{w_1}{n_1}\right)^2 =\left(\frac{w_2}{n_2}\right)^2=\lambda \implies\frac{n_1}{n_2}=\frac{w_1}{w_2} \]

Optimal allocation equalizes the MSE decrease per unit work

Deterministic two-level estimates

Use QMC separately for the same cheap part and coupled correction

Assume justified absolute-error bounds with a common \(p>0\)

\[\begin{align*} \abs{\hmu_\ell-\mu_\ell}&\le\frac{A_\ell}{n_\ell^p}\\ \abs{\hmu-\mu} &\le\abs{\hmu_1-\mu_1}+\abs{\hmu_2-\mu_2} \le\frac{A_1}{n_1^p}+\frac{A_2}{n_2^p} \end{align*}\]

At fixed work \(n_1\$_1+n_2\$_2=C\), minimize the bound

\[ w_\ell=\left(\frac{A_\ell}{\$_\ell}\right)^{1/(p+1)} \qquad\frac{n_1}{n_2}=\frac{w_1}{w_2} =\left(\frac{A_1\$_2}{A_2\$_1}\right)^{1/(p+1)} \]

QMC needs sufficient smoothness and a suitable design
Bound total error by the sum of the level error bounds

What two levels accomplish

  • \(d_1\ll d_2\): the coarse approximation can be much cheaper
  • Coupling can make the expensive correction easier to integrate
  • Allocate points using the error amplitudes, rates, and complete evaluation costs
  • IID/RQMC: independent unbiased level estimates add variances
  • Deterministic QMC: level error bounds add by an inequality
  • Fix the target dimension \(d_2\); increase \(n_1,n_2\) to control integration error

Two levels help when the cheap approximation and small correction error earn their combined cost

Two-level random cost as a function of error

Fix grids, amplitudes, and costs; use the IID or RQMC model with common \(p>0\)

Scale the optimal counts together: \(n_1=t w_1\), \(n_2=t w_2\), \(t>0\)

From the optimal-weight definition: \(A_1^2=\$_1w_1^{2p+1}\) and \(A_2^2=\$_2w_2^{2p+1}\)

\[\begin{align*} S&=\$_1w_1+\$_2w_2 \qquad C=n_1\$_1+n_2\$_2=tS\\ \operatorname{MSE}(\hmu) &\approx\frac{A_1^2}{(tw_1)^{2p}}+\frac{A_2^2}{(tw_2)^{2p}}\\ &=\frac{\$_1w_1^{2p+1}}{t^{2p}w_1^{2p}} +\frac{\$_2w_2^{2p+1}}{t^{2p}w_2^{2p}} =\frac{\$_1w_1+\$_2w_2}{t^{2p}}=\frac{S}{t^{2p}} \end{align*}\]

\[ \operatorname{RMSE}(\hmu)\approx\frac{\sqrt S}{t^p}\approx\varepsilon \implies t\approx\left(\frac{\sqrt S}{\varepsilon}\right)^{1/p} \]

\[ C(\varepsilon)=tS \approx S\left(\frac{\sqrt S}{\varepsilon}\right)^{1/p} =S^{1+1/(2p)}\varepsilon^{-1/p} \]

When does two-level IID save work?

Compare estimates of the same fine target \(\mu\) at RMSE \(\varepsilon\)

Direct fine contributions have variance \(V\) and complete per-sample work \(\$\)

\[ C_{\mathrm{single}}(\varepsilon)=\frac{V\$}{\varepsilon^2} \qquad C_{\mathrm{two}}(\varepsilon) =\frac{\left(\sqrt{V_1\$_1}+\sqrt{V_2\$_2}\right)^2}{\varepsilon^2} \]

With optimal two-level allocation, we save work precisely when

\[ \left(\sqrt{V_1\$_1}+\sqrt{V_2\$_2}\right)^2<V\$ \]

The same \(\varepsilon^{-2}\) factor cancels; compare the cost constants

Why the two-level cost constant can be smaller

On one shared path, the fine payoff is \(Y_1+Y_2\), so

\[ V=\var(Y_1+Y_2)=V_1+V_2+2\sqrt{V_1V_2}\corr(Y_1,Y_2) \]

  • If coupling makes \(V_2\ll V_1\), then \(V\approx V_1\)
  • If the extra coarse work is small, then \(\$_2\approx\$\)

Under these approximations,

\[ \frac{C_{\mathrm{two}}(\varepsilon)}{C_{\mathrm{single}}(\varepsilon)} \approx \left(\sqrt{\frac{\$_1}{\$_2}}+\sqrt{\frac{V_2}{V_1}}\right)^2 \]

Cheap coarse work and small correction variance can make this ratio less than one

Single-level and two-level work versus error

Fix the grids and fine target; assume the same RMSE decay power \(p\)

\[ C_{\mathrm{single}}(\varepsilon)\propto\varepsilon^{-1/p} \qquad C_{\mathrm{two}}(\varepsilon)\propto\varepsilon^{-1/p} \]

Either strategy Halve the RMSE Divide the RMSE by \(10\)
IID: \(p=1/2\) \(4\times\) total work \(100\times\) total work
Illustrative RQMC: \(p=1\) \(2\times\) total work \(10\times\) total work

Two-level IID example: \(V_1=16\), \(V_2=1\), \(\$_1=1\), \(\$_2=16\)

\[ C_{\mathrm{two}}(\varepsilon)=64\varepsilon^{-2} \qquad C_{\mathrm{two}}(0.1)=6400\quad C_{\mathrm{two}}(0.05)=25600 \]

Here, two levels use less work if \(V\$>64\)

Allocate two levels: points versus work

For independent IID level means, take \(p=1/2\) and total work \(C=3200\)

Quantity Cheap level 1 Correction level 2
Contribution variance \(V_\ell\) \(16\) \(1\)
Cost per contribution \(\$_\ell\) \(1\) \(16\)

\(\exstar\) Find the optimal ratio \(n_1/n_2\) and the point counts \(n_1,n_2\) How much work goes to each level? Do fewer correction samples imply less correction work?

Multilevel option pricing in code

Multilevel Option Pricing — notebook · Open in Colab

  • Couple coarse and fine Brownian paths for the same Asian-option model
  • Compare point counts and work under equal and optimal allocations
  • Compare direct fine estimates, IID MLMC, and randomized Sobol’ MLQMC
  • Charge for pilots and keep sampling error separate from approximation bias

More samples reduce integration error; finer grids address approximation bias

A hierarchy of coupled approximations

Monte Carlo foundations, methods, and applications
Estimation

Repeat the two-level idea on grids \(d_1<d_2<\cdots<d_L\)

\[\begin{align*} Y_1&=f_{d_1}(\vX_{1:d_1})\\ Y_\ell&=f_{d_\ell}(\vX_{1:d_\ell}) -f_{d_{\ell-1}}(\vX_{1:d_{\ell-1}}),\qquad \ell\ge2 \end{align*}\]

The means telescope to the finest approximation

\[ \mu_{d_L}=\Ex\{f_{d_L}(\vX_{1:d_L})\} =\sum_{\ell=1}^L\Ex(Y_\ell) \]

One cheap approximation plus differences of coupled fine/coarse pairs

Sampling error and approximation bias

For an infinite-resolution target, distinguish the limit from the finest approximation

\[\begin{align*} \mu&=\lim_{d\to\infty}\Ex\{f_d(\vX_{1:d})\}\\ b_L&=\mu-\mu_{d_L} \qquad\text{remaining approximation bias} \end{align*}\]

Independent unbiased level estimates give \(\Ex(\hmu)=\mu_{d_L}\), so

\[ \operatorname{MSE}(\hmu)=b_L^2+\sum_{\ell=1}^L\var(\hmu_\ell) \]

  • More samples reduce sampling error
  • Refine the finest grid to reduce approximation bias

At fixed \(L\), more samples cannot remove \(b_L\)

Optimal multilevel allocation

Monte Carlo foundations, methods, and applications
Estimation

For IID, the same allocation result holds for any number of levels

\[ w_\ell=\sqrt{\frac{V_\ell}{\$_\ell}} \qquad \frac{n_\ell}{n}=\frac{w_\ell}{\sum_{k=1}^L w_k} \]

  • More samples where contribution variance is larger
  • Fewer samples where each contribution costs more
  • Choose the total count to meet the work budget \(C\)

The optimum equalizes MSE reduction per unit work across levels

Why telescoping helps

Monte Carlo foundations, methods, and applications
Estimation

For a fixed finest grid, the optimal IID sampling cost is

\[ C(\varepsilon_{\mathrm s})=\frac{\left(\sum_{\ell=1}^L\sqrt{V_\ell\$_\ell}\right)^2}{\varepsilon_{\mathrm s}^2} \]

For total RMSE \(\varepsilon\), reserve \(\varepsilon_{\mathrm s}^2=\varepsilon^2-b_L^2>0\) for sampling error

Coupling helps when correction variances shrink fast enough to offset their higher cost

To reduce Change
Sampling error Sample counts
Approximation bias Finest grid

Small fine-level terms in the sum can make extra resolution affordable

Cost versus accuracy: IID

Now refine the final grid as the target RMSE \(\varepsilon\) shrinks to control approximation bias

Two examples: each refinement halves bias and makes a contribution cost \(4\times\) as much

Correction variance per refinement Most work \(C(\varepsilon)\)
Divided by \(8\) Coarse levels \(\propto\varepsilon^{-2}\)
Divided by \(2\) Fine levels \(\propto\varepsilon^{-3}\)

The cost exponent depends on how fast correction variance falls compared with growing work and required refinement

Multilevel in practice

  • For IID, use pilot runs to measure correction variance and complete cost, then allocate samples
  • Assess remaining approximation bias; one small correction does not bound the omitted tail
  • QMC can improve sampling accuracy when coupling preserves suitable smoothness
  • Count pilots, setup, and allowed sample sizes in the total work
  • With cheap evaluations, sampling and setup overhead can outweigh the saved evaluation work: MLMC may take longer in clock time

Compare the option-pricing notebook and beam notebook to inspect allocation and bias

Stochastic Gradient Descent

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

Sample a few observations per update for cheap optimization moves, while controlling gradient noise

Optimize a loss function

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

Choose \(m\) parameters \(\vtheta\) to make loss small

\[\begin{equation*} \vtheta_*\in\argmin_{\vtheta\in\reals^m}\operatorname{Loss}(\vtheta) \end{equation*}\]

  • Start from a guess; use local information to improve it
  • Gradient: which direction is downhill?
  • Curvature: how far should we move?
  • Conditioning: how unequal is curvature across directions?
  • Cost: could sampled loss terms give a cheaper gradient estimate?
  • An exact local direction usually does not solve the whole problem

Optimization usually needs many moves; compare their total cost

Local models guide a move

For one parameter, approximate the loss near the current \(\theta\)

\[\begin{equation*} q(s)=\operatorname{Loss}(\theta)+g s+\tfrac12 h s^2 \qquad g=\operatorname{Loss}'(\theta),\quad h=\operatorname{Loss}''(\theta) \end{equation*}\]

A nonquadratic quartic loss, its tangent and its local quadratic model at theta equal to one. The quadratic model recommends theta equal to one half, which lowers the true loss but does not reach its minimum at zero; the true and model values at one half also differ

Newton chooses \(s=-g/h\) when \(h>0\); then rebuild the local model

Challenges even in one-dimensional optimization

Challenge What changes? Consequence for optimization
Nonquadraticity Curvature changes with position Refresh the local model; shorten or safeguard a proposed step
Nonconvexity A stationary point need not be globally optimal Try multiple starts and compare losses; no global guarantee

Rebuild local models and compare starting points; local information has limits

Gradient descent avoids the full Hessian

\[\begin{gather*} \vg_k=\nabla\operatorname{Loss}(\vtheta_k) \qquad \mH_k=\nabla^2\operatorname{Loss}(\vtheta_k) \\ \vtheta_{k+1}=\vtheta_k-\eta_k\vg_k \qquad \eta_k>0\text{ is the learning rate} \end{gather*}\]

Method Direction Generic dense storage / solve
Gradient descent \(-\eta_k\vg_k\) \(m\) gradient entries; no Hessian solve
Newton Solve \(\mH_k\vs=-\vg_k\) \(O(m^2)\) storage; \(O(m^3)\) solve
  • GD is reasonable when curvature information is too costly
  • A small enough step decreases a smooth loss with nonzero gradient

Other optimization methods

Method Information used When to consider it
Downhill simplex (Nelder–Mead) Loss at \(m+1\) vertices Modest \(m\); derivatives unavailable
Newton / trust-region Gradients and curvature Affordable local models
BFGS / L-BFGS Gradients and previous steps Curvature without a full Hessian
Momentum / accelerated gradient Gradients and past motion Improve first-order progress

Choose a direction method, then ask how much each move costs

Geometry still matters

Feature Meaning Practical response
Nonquadraticity Curvature changes as we move Recompute directions; safeguard steps
Nonconvexity Zero gradient need not mean a global minimum Compare starts; no general global guarantee
Poor conditioning Curvature differs greatly by direction Scale, precondition or use curvature

For a convex loss, a zero gradient identifies a global minimizer

For a quadratic loss with positive-definite Hessian \(\mH\)
\(\kappa(\mH)=\lambda_{\max}(\mH)/\lambda_{\min}(\mH)\) measures conditioning

Cheap moves help with cost; they do not remove difficult geometry

The banana function is still difficult

\[R(\vtheta)=(1-\theta_1)^2+100(\theta_2-\theta_1^2)^2 \qquad \vtheta_*=(1,1)^\top\]

Rosenbrock contours and loss histories from the same start: full gradient descent with backtracking makes 500 accepted updates, while BFGS reaches the minimizer in about 34; the marked long blue segment is one accepted update

Unequal and changing curvature can slow GD even with only two parameters

A closer look at curvature and conditioning

Close-up of the last 100 accepted gradient-descent updates on Rosenbrock: small moves zigzag across the curved valley centerline while advancing slowly

  • Steep across the valley; shallow along it
  • The valley direction changes as we move
  • Short accepted GD moves can zigzag
  • BFGS uses curvature to change direction and scale

At the minimizer: \(m=2\), \(\kappa\approx2508\)

Every dot is one accepted GD update

Sampling makes gradients cheaper; it does not remove poor conditioning

Challenges so far: several variables

Challenge What changes? Consequence for optimization
Nonquadraticity Curvature changes with position Refresh the local model; shorten or safeguard a proposed step
Nonconvexity A stationary point need not be globally optimal Try multiple starts and compare losses; no global guarantee
Hessian cost Dense storage \(O(m^2)\); solve \(O(m^3)\) Use first-order or limited-memory methods when full curvature costs too much
Conditioning Curvature differs across directions Scale or precondition variables; consider curvature information

First-order methods save Hessian work; the geometry still affects convergence

When the full loss is expensive

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

With \(N\) observations, a common objective is a finite average

\[\begin{equation*} \operatorname{Loss}(\vtheta)=\frac1N\sum_{i=0}^{N-1}\operatorname{loss}_i(\vtheta) \end{equation*}\]

For dense regression models with \(m\) parameters

Calculation Direct work
One observation’s loss or gradient \(O(m)\)
Full loss or full gradient \(O(Nm)\)

Many full-data moves mean many expensive passes

Could we sample the \(\operatorname{loss}_i\) terms rather than average all \(N\) at every move?

Challenges before sampling the gradient

Challenge What changes? Consequence for optimization
Nonquadraticity Curvature changes with position Refresh the local model; shorten or safeguard a proposed step
Nonconvexity A stationary point need not be globally optimal Try multiple starts and compare losses; no global guarantee
Hessian cost Dense storage \(O(m^2)\); solve \(O(m^3)\) Use first-order or limited-memory methods when full curvature costs too much
Conditioning Curvature differs across directions Scale or precondition variables; consider curvature information
Full-gradient cost Direct data pass \(O(Nm)\) Reuse structure or sample fewer terms; small \(m\) can still favor Newton

First-order methods save Hessian work; sampling can reduce full-gradient work

Cheap sampled updates

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

Full gradient: \(\vg_k=\nabla\operatorname{Loss}(\vtheta_k)\); sampled estimate: \(\vG_k\)

Sample \(b\) loss terms using fresh IID indices \(I_{k0},\ldots,I_{k,b-1}\) uniform on \(\{0,\ldots,N-1\}\)

\[\begin{gather*} \vG_k=\frac1b\sum_{j=0}^{b-1}\nabla\operatorname{loss}_{I_{kj}}(\vtheta_k) \\ \vtheta_{k+1}=\vtheta_k-\eta_k\vG_k \qquad \Ex[\vG_k\mid\vtheta_k]=\vg_k \end{gather*}\]

  • \(b=1\): single-observation SGD; \(b>1\): mini-batch SGD
  • Take each sampled loss term’s gradient at the same current iterate; average them
  • Work per move: \(O(bm)\) instead of \(O(Nm)\)
  • No full-loss acceptance test; an individual move may make the loss worse

Differentiate the sampled loss terms, average their gradients, then take a cheap update

The gradient estimate is Monte Carlo

One uniform \(U\sim\Unif[0,1)\) selects one whole observation: \(I=\lfloor NU\rfloor\)

\[\begin{gather*} \widetilde{\vg}_{\vtheta}(u)=\nabla\operatorname{loss}_{\lfloor Nu\rfloor}(\vtheta) \\ \int_0^1\widetilde{\vg}_{\vtheta}(u)\,\dif u =\nabla\operatorname{Loss}(\vtheta) \qquad \vG_k=\frac1b\sum_{j=0}^{b-1}\widetilde{\vg}_{\vtheta_k}(U_{kj}) \end{gather*}\]

Count Meaning
\(N\) Observations in the fixed dataset
\(m\) Entries in each gradient; parameters we update
\(b=d\) Independent indices in one mini-batch; dimension of the draw

Sample observation indices; average their \(m\)-component gradients

When component gradients agree

Identical loss functions

  • Every component gradient equals the full gradient
  • Even one sampled term gives \(\vG_k=\vg_k\)
  • Same start and learning rates: exactly the GD iterates

Similar component gradients

  • Gradients close to their average at \(\vtheta_k\)
  • A small batch introduces little sampling noise
  • For the same learning rate, an update close to GD’s

Appropriate learning rates and GD’s convergence conditions still matter

Judge similarity by gradients; compare sampling noise with the full-gradient signal

Noise near the solution

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

For \(\operatorname{loss}_i(\theta)=\tfrac12(\theta-a_i)^2\), with \(a_i=\pm1\) equally often

\[\begin{equation*} \operatorname{Loss}(\theta)=\tfrac12(\theta^2+1) \qquad \theta_*=0 \qquad \operatorname{Loss}'(0)=0 \end{equation*}\]

At \(0\), every component loss is \(1/2\), but the gradients are \(+1\) and \(-1\)

  • The full gradient can vanish while sampled gradients keep fluctuating
  • Averaging \(b\) independent gradients divides their noise variance by \(b\)
  • Finer accuracy may need a larger batch, a smaller rate, or averaging iterates

Do not wait for each sampled gradient to become zero

Sampling saves work and introduces noise

Challenge What changes? Consequence for optimization
Nonquadraticity Curvature changes with position Refresh the local model; shorten or safeguard a proposed step
Nonconvexity A stationary point need not be globally optimal Try multiple starts and compare losses; no global guarantee
Hessian cost Dense storage \(O(m^2)\); solve \(O(m^3)\) Use first-order or limited-memory methods when full curvature costs too much
Conditioning Curvature differs across directions Scale or precondition variables; consider curvature information
Full-gradient cost Direct data pass \(O(Nm)\) Reuse structure or sample fewer terms; small \(m\) can still favor Newton
Gradient noise Random direction estimates Use mini-batches, smaller steps or averaging for finer accuracy

Gradient and stochastic-gradient paths

Toy objective: \(m=2\) parameters, average of \(N=1{,}000\) loss terms
Equal component-gradient work: 45 GD moves versus 4,500 mini-batch moves
45,000 contributions each: 1,000 per GD move; 10 per SGD move (\(b=10\))
Common rate \(\eta=0.5\); picture shows first 60 mini-batch moves (600 contributions)

Contours of excess average quadratic loss comparing 45 full-gradient descent moves with 4500 mini-batch SGD moves of batch size ten at the same 45000-contribution budget, showing the first 60 mini-batch moves or 600 contributions

Monitor progress between blocks of moves

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

  1. Choose a batch size, learning-rate schedule and accuracy goal or budget
  2. Make many cheap updates without evaluating the full loss
  3. Periodically compare loss on the same randomly selected diagnostic subset of \(s\) observations, typically \(b\ll s\ll N\)
  4. If progress is poor, adjust the rate or batch size for the next block
  5. Stop when the accuracy check passes or the work budget is spent

Use periodic evidence to guide the run; small movement alone is weak evidence

Count monitoring in the cost

For \(K\) updates, \(J_s\) diagnostic checks and \(J_N\) full-loss checks

\[\begin{equation*} \text{direct training work}=O\bigl(m(Kb+J_s s+J_N N)\bigr) \end{equation*}\]

Check Cost Purpose
Loss on the same \(s\) randomly selected observations \(O(sm)\) Estimate training-loss progress
Full training loss \(O(Nm)\) Measure the empirical objective
Held-out validation loss Depends on validation size Check predictive performance
  • One diagnostic check: work comparable to about \(s/b\) updates
  • One full check: work comparable to about \(N/b\) updates

Pay for checks after many moves, with cheaper diagnostics between

Choose how small the full gradient should be

Full gradient: \(\vg_k=\nabla\operatorname{Loss}(\vtheta_k)\); sampled update direction: \(\vG_k\)

Choose a stationarity target \(\norm{\vg_k}\leq\tau\), with \(\tau>0\)

Evidence at a checkpoint What can we conclude?
Tiny move or loss plateau May reflect a small rate or unresolved noise
Full-gradient norm at most \(\tau\) The stationarity target is met; costs \(O(Nm)\)
Sampled \(\vG_k\) Its norm plus justified uncertainty must be at most \(\tau\)
  • Choose \(\tau\) to match the application’s precision and parameter scaling
  • If uncertainty is too large, enlarge the checking batch or use the full gradient
  • Small gradient means approximate stationarity; optimality needs assumptions

A large-data example

Monte Carlo foundations, methods, and applications
Stochastic
Optimization
Estimation

Binary observation \(y_i\in\{0,1\}\); predictor \(z_i=\vx_i^\top\vtheta\)

\[\begin{gather*} p_i(\vtheta)=\Prob_{\vtheta}(Y_i=1\mid\vx_i) =\frac{1}{1+e^{-z_i}} \end{gather*}\]

Observed label Probability assigned to that label
\(y_i=1\) \(p_i\)
\(y_i=0\) \(1-p_i\)

Combine the two cases: \(q_i(\vtheta)=p_i^{y_i}(1-p_i)^{1-y_i}\)

For independent labels, maximize their likelihood

\[\max_{\vtheta}\prod_i q_i(\vtheta) \quad\Longleftrightarrow\quad \min_{\vtheta}\sum_i[-\log q_i(\vtheta)]\]

Derive the logistic loss

The negative log likelihood for one observation is

\[\ell_i^{\mathrm{data}}=-\log q_i =-y_i\log p_i-(1-y_i)\log(1-p_i)\]

Substitute \(p_i=e^{z_i}/(1+e^{z_i})\)

\[\begin{align*} \log p_i&=z_i-\log(1+e^{z_i})\\ \log(1-p_i)&=-\log(1+e^{z_i}) \end{align*}\]

Therefore

\[\begin{align*} \ell_i^{\mathrm{data}} &=-y_i z_i+[y_i+(1-y_i)]\log(1+e^{z_i})\\ &=\log(1+e^{z_i})-y_i z_i \end{align*}\]

At \(p_i=0.9\): loss \(0.105\) for label 1; loss \(2.303\) for label 0

Regularization and the gradient

Add a separate quadratic penalty to the mean data loss

\[F(\vtheta)=\frac1N\sum_{i=0}^{N-1}\ell_i^{\mathrm{data}}(\vtheta) +\frac\lambda2\norm{\vtheta}^2\]

First differentiate with respect to \(z_i=\vx_i^\top\vtheta\)

\[\frac{\dif\ell_i^{\mathrm{data}}}{\dif z_i} =\frac{e^{z_i}}{1+e^{z_i}}-y_i=p_i-y_i\]

With \(\operatorname{loss}_i=\ell_i^{\mathrm{data}}+(\lambda/2)\norm{\vtheta}^2\), the chain rule gives

\[\nabla\operatorname{loss}_i(\vtheta) =(p_i-y_i)\vx_i+\lambda\vtheta\]

  • Average these component gradients for the full gradient
  • Average a sampled batch for SGD
  • Penalizing every coefficient with \(\lambda>0\) gives a unique minimizer

Learning rates in the logistic experiment

Let \(X\) have rows \(\vx_i^\top\); the notebook uses the global curvature bound

\[L_{\mathrm{bound}}=\lambda_{\max}\!\left(\frac{X^\top X}{4N}\right)+\lambda\]

Method Implemented learning rate
Full GD \(1/L_{\mathrm{bound}}\), computed once for the fixed dataset
Fixed mini-batch SGD \(\eta=0.3\)
Decaying single-observation or mini-batch SGD \(\eta(w)=0.3/(1+w/(0.25N))\)
  • \(w\): observation-gradient work already used before the update
  • The decaying rate is \(0.15\) after a quarter equivalent pass and \(0.06\) after one pass
  • The SGD rates are illustrative settings to review and tune
  • The reference minimum is for comparing results; the optimizer does not know it

One dataset, several accuracy targets

One fixed logistic dataset: \(N=262{,}144\), \(m=20\), \(b=256\), \(s=1{,}024\)

Loss gap: \(\operatorname{Loss}(\vtheta)-\operatorname{Loss}(\vtheta_*)\)

One equivalent pass: \(N\) observation-gradient contributions

Median passes to the first recorded target crossing

Loss-gap target Full GD Fixed SGD Decaying SGD
\(10^{-3}\) — useful answer \(2\) \(0.059\) \(0.066\)
\(10^{-4}\) \(3\) — \(2.04\)
\(10^{-6}\) — finer answer \(6\) — —
  • Same data and start; five repeats per method; — means unreached in eight passes
  • Crossings assessed retrospectively; every run stops at eight passes
  • At \(10^{-3}\): SGD uses less gradient work and measured update time
  • At \(10^{-4}\): decay uses fewer contributions, but GD is faster here
  • Compare at the same useful accuracy; include setup and checking costs

GD and SGD compared

Monte Carlo foundations, methods, and applications
Stochastic
Optimization

Same average loss; both choose a direction and a learning rate

Feature Full GD Mini-batch SGD
Direction Full gradient \(\vg_k\) Sampled \(\vG_k\): unbiased, noisy
Learning rate, \(\eta_k\) Curvature bound, or full-loss backtracking Short pilots; then use a fixed or decaying schedule
Update work All \(N\) terms: \(O(Nm)\) Sample \(b\) terms: \(O(bm)\)
Total work \(O(K_{\mathrm{GD}}Nm)+C_{\mathrm{GD}}\) \(O(K_{\mathrm{SGD}}bm)+C_{\mathrm{SGD}}\)
Near minimum \(\vg_k\) approaches zero Noise can persist at fixed \(b\)
Reduce noise effect No sampling noise Smaller steps, larger batches or variance reduction
Check progress Full-gradient norm or loss Periodic checks with noise assessment

\(K\): each method’s updates to the target; \(C\): setup, tuning and all checking work

Both face difficult geometry; compare total work and time at the same accuracy

Beyond SGD

Monte Carlo foundations, methods, and applications
Stochastic
Optimization
Research direction Contribution Link to SGD
Derivative-free optimization Rates and limits for gradient estimates from function values Randomness can estimate a direction without derivatives
Accelerated methods A variational, continuous-time framework Understand and design methods using momentum
Escape from saddle points Guarantees for deliberately perturbed gradient descent Randomness can also help leave a saddle

Sampling data, estimating derivatives, and perturbing iterates serve different purposes

Gradient descent companion notebook

Open Stochastic Gradient Descent on GitHub · Run in Colab

  • Part 1: banana-valley paths and backtracking; Part 2: optional curvature calculations
  • Parts 3–4: optional variance, expected-descent and noise-floor calculations
  • Parts 5–6: logistic regression at equal component work and measured time
  • Sampled/full-loss diagnostics and the final gradient check have separate timers

\(\exstar\) Increase \(N\) with \(m\) fixed; then tighten the requested accuracy When do cheap updates help, and when does noise limit useful progress?

Choose an action by simulating futures

Monte Carlo foundations, methods, and applications
Monte Carlo
Tree Search

Choose an airport itinerary before departure; traffic makes arrival uncertain

A tree of partial airport itineraries: choose North, Central or South, then a connector; four further binary choices lead to a complete route whose traffic is simulated

  • Nodes: partial plans; branches: the next route choice
  • Six segments give \(3\times2^5=96\) plans; twenty give \(3\times2^{19}>1.5\) million
  • Spend a limited simulation budget on promising continuations

Where MCTS is used

Application Search decisions Good outcome
AlphaGo and AlphaZero Legal moves in Go; also chess and shogi for AlphaZero Win the game
Navigation Sailing directions under uncertain wind Reach the destination at low travel cost
Traveling salesperson Choose the next unvisited city Short tour through every city and back to start
AlphaTensor Steps in a matrix multiplication algorithm Correct result with fewer scalar multiplications
  • A learned policy gives a rule for choosing actions
  • A learned value can estimate an outcome without simulating to the end

MCTS allocates search effort among sequences of decisions

Specify a travel-time model

The notebook declares synthetic segment distributions in minutes

First road Base time Extra delay Delay probability
A · North 10 26 0.35
B · Central 13 13 0.22
C · South 16 7 0.10

For North’s first segment, \[\begin{equation*} T_A=\begin{cases}10 & \text{with probability }0.65\\36 & \text{with probability }0.35\end{cases} \end{equation*}\]

  • A fixed itinerary has a random total time; each trial draws fresh traffic
  • Search also samples unfinished route choices
  • A real application needs a simulator fitted to travel-time observations

Turn simulated trips into values

For a complete plan \(p\), simulate its total travel time \(T(p)\) in minutes

With deadline \(D=80\) minutes, record the return

\[\begin{equation*} R=\begin{cases}1 & \text{arrive by the deadline}\\0 & \text{arrive late}\end{cases} \qquad \mu(p)=\Ex(R)=\Prob\bigl(T(p)\leq D\bigr) \end{equation*}\]

At a stored node \(s\), keep successes \(W(s)\) and visits \(N(s)\)

\[\begin{equation*} \overline Q(s)=\frac{W(s)}{N(s)} \qquad \frac{28\text{ on-time trips}}{40\text{ simulations}}=0.70 \end{equation*}\]

  • A rollout: complete the remaining choices, then simulate the trip
  • Early rollouts use simple random choices; deeper search can improve the continuations

A branch’s average summarizes the continuations tried so far

Chess has deterministic moves; this toy game shows why replies matter

A toy deterministic game: our move A allows the opponent to choose our win or our loss, while our move B forces a draw; accounting for the opponent's best reply favors B

  • Our turns seek high values; opposing turns seek low values from our viewpoint
  • Random rollouts explore a small part of a huge, deterministic game tree

One tree-search iteration

Monte Carlo foundations, methods, and applications
Monte Carlo
Tree Search

One MCTS iteration: run all four steps in order

Step In one iteration
Select Follow highest-scoring stored choices until reaching a node with an untried action, or a complete plan
Expand Store one untried child, if available
Roll out Sample remaining choices without storing their nodes; simulate traffic for \(R\)
Back up Update visits and returns for the selected stored nodes and the one new node; discard the rollout suffix

Repeat until the search budget is exhausted

Here each iteration uses one traffic simulation; a search run uses the whole budget

Keep the selected path and any newly expanded node

Discard the rollout suffix; retain its return in the counters

Why discard the rollout suffix?

The full rollout gives one sampled return for the new route prefix

Grow the tree gradually

  • Store at most one new node per iteration
  • Skip allocating a node and counters for each temporary choice
  • Add deeper choices when later iterations expand them

Keep the rollout’s return

  • Back up \(R\) through every stored node on the path, including the new one
  • Retain successes \(W\) and visits \(N\)
  • Sample a fresh continuation on a later visit

The stored nodes keep the return from the complete simulated trip

Exploration versus exploitation

UCT: Upper Confidence Bounds applied to Trees

At partial plan \(s\), score a visited next road choice \(a\)

\[\begin{equation*} \underbrace{\overline Q(s,a)}_{\text{exploit a high average}} +\underbrace{c\sqrt{\frac{\log N(s)}{N(s,a)}}}_{\text{explore a less-visited branch}} \qquad c>0 \end{equation*}\]

  • \(s\): current stored node, a partial route
  • \(a\): candidate next action from \(s\)
  • \(N(s)\): iterations that visited node \(s\)
  • \(N(s,a)\): iterations that took stored action \(a\) from \(s\)
  • \(W(s,a)\): successes backed up through that action
  • \(\overline Q(s,a)=W(s,a)/N(s,a)\): average return through that action
  • \(c>0\): weight given to exploration

Expand an untried action first

Otherwise select the largest score

Following example: \(c=1\), natural \(\log\)

For action \(a\), use the counts in the child box reached from \(s\)

Probability bounds for mean rewards motivate the exploration bonus

A ten-iteration tree search

The small route tree starts with only Start stored, with zero successes and zero visits

A smaller teaching tree

  • First road: A or B
  • Then three choices: 0 or 1
  • \(2^4=16\) complete routes
  • Choose the whole route before departure

Simulate a trip, then record

\[\begin{equation*} R=\begin{cases} 1 & T\leq80\text{ minutes}\\ 0 & T>80\text{ minutes} \end{cases} \end{equation*}\]

Initially, only the root is stored

Each iteration restarts at Start

At most one new node; roll out the suffix

Iteration 1 — expand A

Expand A, sample the remaining route A–0–1–0 without storing its continuation, simulate 76 minutes and back up one: Start and A each have one success in one visit

Before: \(N(\text{Start})=0\)
Both actions are untried — no UCT comparison

  1. Select: start at the root
  2. Expand: store A
  3. Roll out: sample 0, 1, 0
    Simulate \(T=76\), so \(R=1\)
  4. Back up: add one visit and one success to Start and A
    Discard the rollout suffix

Only one new node stored

The dashed continuation is sampled, then discarded

Iteration 2 — expand B

The next iteration expands untried B, samples B–1–0–0 and returns zero for 86 minutes; Start becomes 1/2, A stays 1/1 and B is 0/1

Before: \(N(\text{Start})=1\)
B is untried — no UCT comparison

  1. Select: start at the root
  2. Expand: store untried B
  3. Roll out: sample 1, 0, 0
    Simulate \(T=86\), so \(R=0\)
  4. Back up: add one visit to Start and B; no new successes
    Discard the rollout suffix

Try untried actions first

A stays at 1/1

Next: restart at Start and compare UCT scores

Iteration 3 — expand A–0

Iteration 3: select A using UCT, store only A–0, sample the dashed suffix and back up return 1; all stored A and B nodes remain visible

\(c=1\) for this example

Select (before backup) \(N(\text{Start})=2\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 1 1 1.833
B 0 1 0.833

Expand: A–0, using untried 0
Roll out: 1, 0, \(T=78\), \(R=1\)
Back up: update Start, A, A–0
and discard the dashed suffix

Iteration 4 — expand A–1

Iteration 4: select A using UCT, store only A–1, sample the dashed suffix and back up return 1; all stored A and B nodes remain visible

Select (before backup) \(N(\text{Start})=3\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 2 2 1.741
B 0 1 1.048

Expand: A–1, using untried 1
Roll out: 0, 0, \(T=79\), \(R=1\)
Back up: update Start, A, A–1
and discard the dashed suffix

Iteration 5 — expand A–0–0

Iteration 5: select A using UCT, store only A–0–0, sample the dashed suffix and back up return 0; all stored A and B nodes remain visible

Select (before backup) \(N(\text{Start})=4\), \(N(A)=3\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 3 3 1.680
B 0 1 1.177
A–0 1 1 2.048
A–1 1 1 2.048

Expand: A–0–0, using untried 0
Roll out: 0, \(T=86\), \(R=0\)
Back up: update Start, A, A–0, A–0–0
and discard the dashed suffix

Iteration 6 — expand A–1–0

Iteration 6: select A using UCT, store only A–1–0, sample the dashed suffix and back up return 0; all stored A and B nodes remain visible

Select (before backup) \(N(\text{Start})=5\), \(N(A)=4\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 3 4 1.384
B 0 1 1.269
A–0 1 2 1.333
A–1 1 1 2.177

Expand: A–1–0, using untried 0
Roll out: 0, \(T=85\), \(R=0\)
Back up: update Start, A, A–1, A–1–0
and discard the dashed suffix

Iteration 7 — expand B–0

Iteration 7: expand B–0, sample the dashed suffix to complete B–0–1–0, and back up return 1 through Start, B, B–0. The stored tree shows the updated counts.

One path down resembles depth-first search
Breadth-first search grows level by level
Here A–0–0 (depth 3) came before B–0 (depth 2)

Select (before backup) \(N(\text{Start})=6\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 3 5 1.199
B 0 1 1.339

Expand: B–0, untried 0 at B
Roll out: 1, 0, \(T=76\), \(R=1\)
Back up: update Start, B, B–0
and discard the dashed suffix

Iteration 8 — expand B–1

Iteration 8: expand B–1, sample the dashed suffix to complete B–1–0–0, and back up return 0 through Start, B, B–1. The stored tree shows the updated counts.

Select (before backup) \(N(\text{Start})=7\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 3 5 1.224
B 1 2 1.486

Expand: B–1, untried 1 at B
Roll out: 0, 0, \(T=86\), \(R=0\)
Back up: update Start, B, B–1
and discard the dashed suffix

Iteration 9 — expand A–0–1

Iteration 9: expand A–0–1, sample the dashed suffix to complete A–0–1–0, and back up return 0 through Start, A, A–0, A–0–1. The stored tree shows the updated counts.

Select (before backup) \(N(\text{Start})=8\), \(N(A)=5\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 3 5 1.245
B 1 3 1.166
A–0 1 2 1.397
A–1 1 2 1.397

Expand: A–0–1, untried 1 at A–0
Roll out: 0, \(T=84\), \(R=0\)
Back up: update Start, A, A–0, A–0–1
and discard the dashed suffix

Iteration 10 — expand B–0–1

Iteration 10: expand B–0–1, sample the dashed suffix to complete B–0–1–0, and back up return 1 through Start, B, B–0, B–0–1. The stored tree shows the updated counts.

B–0–1 was rollout-only in iteration 7 and becomes a stored node here

Select (before backup) \(N(\text{Start})=9\), \(N(B)=3\)

\[\begin{equation*} \operatorname{UCT}(s,a)=\frac{W(s,a)}{N(s,a)} +\sqrt{\frac{\log N(s)}{N(s,a)}} \end{equation*}\]

Child \(W(s,a)\) \(N(s,a)\) UCT
A 3 6 1.105
B 1 3 1.189
B–0 1 1 2.048
B–1 0 1 1.048

Expand: B–0–1, untried 1 at B–0
Roll out: 0, \(T=78\), \(R=1\)
Back up: update Start, B, B–0, B–0–1
and discard the dashed suffix

From search to a decision

Monte Carlo foundations, methods, and applications
Monte Carlo
Tree Search

During search

  • UCT chooses where to simulate next
  • With an eleventh iteration, UCT would pick B at Start (\(1.259\) vs. \(1.119\) for A)
  • Both averages are \(1/2\). B has fewer visits and gets the larger exploration bonus

After the budget

  1. Start at the root and follow the stored child with the most visits
  2. Break visit ties by larger \(W/N\), then by earlier action (0 before 1)
  3. Repeat at the next prefix. If it has no stored child, fill the remaining choices with 0

The first road in the recommendation is A with 6 visits, compared with 4 for B

Our route after 10 iterations

Build the itinerary using the counts after the tenth backup

Current prefix Stored children Next choice
Start A: 6 visits, B: 4 visits A has more visits
A A–0: 3 visits, A–1: 2 visits 0 has more visits
A–0 Each child has \(W/N=0/1\) 0 comes first in a tie
A–0–0 No stored child 0 fills the final choice

Recommended itinerary: A–0–0–0

  • A–0–0–0 was late in its only trial (86 minutes in iteration 5)
  • B–0–1–0 was on time in both of its trials (iterations 7 and 10)
  • Counts at each prefix pool trips with different continuations

Tree-search companion notebook

Open Monte Carlo Tree Search on GitHub · Run in Colab

  • Draw a route tree and track its visits and on-time returns
  • Run selection, expansion, rollout and backup
  • Compare adaptive search with uniform route sampling at the same simulation budget
  • Use the small exact benchmark to check the recommended itinerary

\(\exstar\) Change the simulation budget or exploration weight \(c\) Does a high early success rate always identify the best complete plan?

Big Ideas

Monte Carlo foundations, methods, and applications
Probability
Statistics
Estimation
  • Monte Carlo samples are naturally parallel, but random streams and precision still matter
  • Stochastic gradients trade exact directions for cheaper iterations
  • Monte Carlo tree search balances exploration and exploitation when choosing actions
  • Two-level and multilevel estimators split work according to error decay and cost
  • Coupling adjacent approximations can make corrections easier to integrate
  • A good hierarchy spends most computation where it buys the largest reduction in error

How Far We Have Come

From Monte Carlo estimates to computational design

  • Model — express a question as an expectation and generate suitable samples
  • Check — quantify uncertainty and compare sample distributions
  • Improve — reduce variance with conditioning or weights; use structured points for suitable integrands
  • Search — use simulated returns to focus on promising decisions
  • Allocate — distribute work across processors and approximation levels

Good simulation balances accuracy, computational cost, and evidence for stopping

What Comes Next

Bring the course methods together in a concrete model or project:

  • Define the target quantity and the source of approximation error
  • Choose a sampling method and justify its assumptions
  • Compare an efficiency improvement against a clear baseline
  • Report uncertainty, computational cost, and a stopping criterion

The next step is a defensible end-to-end simulation

«
»