Click & Drag to change the view of the 3D surface; scroll on the plot to zoom.
The surface is four Gaussian wells of different depths and widths dug into a gently
rising plain, $f(x, y) = 1 + \tfrac{(x^2 + y^2)}{100} - \sum_i A_i \,
e^{-((x - c_i)^2 + (y - d_i)^2) / 2\sigma_i^2}$. Its four minima are not equal:
$f = -0.842$ (the global minimum), $-0.537$, $-0.342$ and $-0.133$ — the goal is to find
a minimal point, and which one you reach is decided by where you start.
Three local methods race from every start: gradient descent (green), momentum
(blue, $\beta = 0.8$) and Adam (amber) — the cast of the Optimizer Race below, on
terrain where they can end in different wells. The $\alpha$ slider drives the first two;
Adam keeps its own step size, $\eta_A = 0.10$. The green
arrow at the green point points in the opposite direction of the
Gradient, $\nabla f$, with its size proportional to $\|\nabla f\|_2$; each plain
gradient-descent step moves $-\alpha \, \nabla f$ from the current point.
Multi-start GD (red) plays a different game: it ignores the dealt start, runs plain
gradient descent from a $3 \times 3$ grid of starts — the nine red walks — and keeps the
best ending. Three of its nine walks find the deep well, so its best is the global
minimum; the price at the default $\alpha$ is 462 steps against gradient descent's 54.
Certainty is purchased with evaluations.
The widest well is not the deepest: on a grid of 1,369 starts at $\alpha = 0.25$, the wide
shallow well ($f = -0.342$) captures 36% of gradient-descent walks, more than the global
minimum's 32% — most starts end at a merely local minimum.
Usually the three methods still agree on the well — the basin decides, and only the step
counts differ. Not always: from a start beside the narrow well, gradient descent settles
in it ($f = -0.133$, 49 steps) while momentum's overshoot carries it over the rim into the
wide well ($f = -0.342$, 81 steps). New Starting Point deals all three the same
fresh start — run them and compare.
The readout reports the step count, $f$, and $\|\nabla f\|$ after every move; the walk has
converged when $\|\nabla f\| < 10^{-3}$. A larger $\alpha$ walks faster but overshoots the
narrow wells — at $\alpha = 0.5$, a walk starting inside the narrowest well never settles.
The Gradient Descent is also implemented for Linear Regression on the page
Linear Regression.
The idea behind Gradient Descent is intuitive, say we have a single valued function
$$f:\mathbb{R}^n\to \mathbb{R}$$
and we are standing at a point $x $ in the domain $\mathbb{R}^n$, and we are about to take a step in the
direction
of some unit vector $v$ with step size $\delta$.
When we want to maximize our output, we go in the direction of $v=\nabla f(x)$.
And similarly, if we want to minimize our output, we go in the opposite direction of the gradient,
$-\nabla f(x)$. For the mathematical justification, see my notes at .
For a function $f:\mathbb{R}^n\to \mathbb{R}$, the Gradient Descent Algorithm seeks to find a local
minimum of $f$ through the following iterative procedure
Start with some initial point $x_0$
At step $i$: set $$ x_i = x_{i-1} - \alpha\cdot \nabla f(x_{i-1}) $$
Repeat the previous part, until $\alpha \cdot \nabla f(x_{i-1})$ is sufficiently small.
The Optimizer Race
Gradient descent is not the only way to follow a gradient downhill, and on an
ill-conditioned problem it is not the fastest. Race it against two standard upgrades on the
quadratic $$f(x,y)=\tfrac12\left(x^2+25y^2\right),$$ whose Hessian has eigenvalues $1$ and
$25$ — condition number $\kappa = 25$. The contours are long ellipses: steep across the
valley, shallow along it. All three methods start at $(2.8,\,1.0)$, where $f = 16.42$, and a
run ends when $f < 0.005$.
Momentum (Polyak's heavy ball) keeps a velocity,
$v \leftarrow \beta v + \nabla f(x)$ and $x \leftarrow x - \eta v$, here with $\beta = 0.8$:
gradients that keep pointing the same way build the velocity up, gradients that alternate —
the zigzag across a valley — cancel. Adam instead rescales the gradient coordinate by
coordinate, $x \leftarrow x - \eta_A\,\hat m / (\sqrt{\hat v} + \epsilon)$, where $\hat m$ and
$\hat v$ are bias-corrected averages of the gradient and its square ($\beta_1 = 0.9$,
$\beta_2 = 0.999$). Its step size is a distance per coordinate, not a multiple of the
gradient, so the slider below does not apply to it — it runs at its own $\eta_A = 0.08$.
Contours of $f$ at $0.05, 0.15, 0.4, 1, 2.2, 4.5, 9, 16$; the dashed ellipse is the
finish line $f = 0.005$.
Two things worth noticing. First, plain gradient descent is squeezed from both sides:
stability across the valley demands $\eta < 2/25 = 0.08$, and at any such $\eta$ the shallow
coordinate can shrink by at most a factor $1 - \eta$ per step; push the slider past $0.08$ and
the steep coordinate's factor $1 - 25\eta$ passes $-1$, so the zigzag grows instead of
dying. Even at its optimal step size its error shrinks only like
$\frac{\kappa - 1}{\kappa + 1} \approx$ 0.92 per step. Second, the two upgrades attack
different halves of the squeeze: momentum's velocity cancels across the valley and
accumulates along it — at its optimal tuning the rate improves to
$\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1} \approx$ 0.67 per step — while Adam barely feels
the squeeze at all, because dividing by $\sqrt{\hat v}$ makes its step nearly independent of
each coordinate's steepness, which is also why it is unaffected when the slider moves past
gradient descent's stability limit.
Flip on stochastic gradients and the race runs the way these methods are actually
used in machine learning: nobody hands Adam the exact gradient of the whole dataset —
each step sees a minibatch estimate $\hat g = \nabla f(x) + \sigma\xi$, with $\xi$ a
fresh standard normal in each coordinate and $\sigma = 1.2$ here. The noise is seeded,
and every racer draws from the same seed, so the comparison stays fair; a racer counts
as finished at its first entry into the finish ellipse, since a noisy iterate can
bounce back out. The second act is different in kind, not just in step counts: plain
gradient descent never settles — it jitters in a ball around the minimum whose radius
grows like $\sqrt{\eta}\,\sigma$ — while momentum's velocity, an average over past
gradients, cancels the independent noise down by a variance factor
$\frac{1-\beta}{1+\beta} \approx 0.11$, and Adam responds in its own way again, its
$\hat v$ soaking up $\sigma^2$ until, near the minimum, its steps shrink toward the
size of the noise itself.
Derivative Tests
When $f$ can be restricted to a bounded domain or $f$ is concave / convex, global optimum can be obtained via
derivative tests.
Let $f(x):\mathbb{R}^n\to\mathbb{R} $, if $f\in C^2$, let $H_f$ be the
Hessian
matrix of $f$.
Suppose
$$\nabla f(x_0) =\mathbf{0}$$
if $H_f(x_0)$ is positive definite, then $x_0$ is a local minimum,
if
$H_f(x_0)$ is negative definite, then $x_0$ is a local maximum,
If $f$ is convex, then every local minimum of $f$ is a global minimum. Strict convexity
gives at most one global minimum, but a minimum need not be attained (e.g. $e^x$ on
$\mathbb{R}$).
If $f$ is concave, then every local maximum of $f$ is a global maximum. Strict concavity
gives at most one global maximum, but a maximum need not be attained.
For definitions and discussion, see my notes at 🖇️.
Newton's Method
To find critical points $x_0$, where $$\nabla f(x_0) =\mathbf{0}$$ one can use Newton's Method.
Let $g(\mathbf{x}):\mathbb{R}^n\to \mathbb{R}^m$. Newton's Method is an algorithm
for finding a root of $g$ (if it exists).
We go over two different views of Newton's Method.
Linear Approximation
To derive Newton's Method, we start with the first-order linear approximation,
$$\vec{0}\approx J_g(x_0)(x-x_0)+g(x_0)$$ where, $x$ is a root that we are seeking, $x_0$ is a point near
the
root,
$J$ is the Jacobian
$$J_g(x_0)=\left[\begin{array}{ccc}
\frac{\partial g_{1}}{\partial x_{1}} & \cdots & \frac{\partial g_{1}}{\partial x_{n}} \\
\vdots & \ddots & \vdots \\
\frac{\partial g_{m}}{\partial x_{1}} & \cdots & \frac{\partial g_{m}}{\partial x_{n}}
\end{array}\right]$$
The linear approximation implies $$x \approx x_0-J^{-1}_g(x_0)g(x_0)$$
And this gives us the Newton's Method
Start with an initial guess $x_0$
Repeat until convergence
$$x_i = x_{i-1}- J^{-1}_g(x_{i-1})g(x_{i-1})$$
If $g(\mathbf{x}):\mathbb{R}^n\to \mathbb{R}^n$ is affine, i.e. it is of the form $$g(x)=Mx+b$$ then the
first-order
linear approximation will be exact,
and Newton's method requires only one step to get the root
$$x_1 = x_0 - M^{-1} (Mx_0+b) = -M^{-1}b $$
Fixed Point Equation
A fixed point equation is an equation of the form
$$x=f(x)$$
when $f(x)$ is a contraction, a solution to the equation can be found efficiently through an iterative
procedure
Let $(X, d)$ be a non-empty complete metric space with a contraction mapping $$T: X
\rightarrow X$$ Then $T$ admits a unique fixed-point $x^{*}$ in $X$ (i.e.
$T\left(x^{*}\right)=x^{*}$ ).
Furthermore, $x^{*}$ can be found as follows:
start with an arbitrary element $x_{0} \in X$ and define a
sequence $\left(x_{n}\right)_{n \in \mathbb{N}}$ by $$x_{n}=T\left(x_{n-1}\right)$$ for $n
\geq
1$.
Then $$\lim _{n
\rightarrow \infty} x_{n}=x^{*}$$
Newton's Method is a special case of Fixed Point Iteration where we have the following fixed
point equation
$$g(x)=x-J^{-1}_g(x)g(x)$$
Newton, Computed
In one dimension the iteration above has a picture: at $x_k$, replace $g$ by its
tangent line and jump to where that line crosses the axis,
$$x_{k+1} = x_k - \frac{g(x_k)}{g'(x_k)}.$$
The method's reputation rests on what happens near a root $r$ with $g'(r) \ne 0$:
the error $e_k = x_k - r$ obeys
$$e_{k+1} = \frac{g''(r)}{2g'(r)}\, e_k^2 + O(e_k^3),$$
quadratic convergence — once the iterate is close, the number of correct
digits roughly doubles at every step. That is the local half of the story, and it is
why the optimization version ($g = \nabla f$, the Jacobian above becomes the Hessian)
finishes in a handful of steps when it works: the Interior Point demo later on this page
takes exactly such a Newton step at every iteration. The other half is that the theorem
is local — it promises nothing about a start outside the root's basin. The demo
computes all three fates on functions whose iterates are exact.
Read the first example's iterates as fractions and they are
$1,\ \frac32,\ \frac{17}{12},\ \frac{577}{408},\ \frac{665857}{470832}$ — Heron's
Babylonian sequence for $\sqrt 2$ (Newton on $x^2 - 2$ is the averaging rule
$\frac12(x + 2/x)$), each numerator and denominator solving the Pell equation
$p^2 - 2q^2 = 1$. Its measured error ratios $e_{k+1}/e_k^2$ run
$0.500,\ 0.333,\ 0.353,\ 0.354$, closing on the theorem's constant
$\frac{g''(r)}{2g'(r)} = \frac{1}{2\sqrt 2} \approx$ 0.354. The other two presets are
the standard warnings, not contrived pathologies: $x^3 - 2x + 2$ from $0$ cycles
$0 \to 1 \to 0$ forever, never approaching its only real root at $-1.769$, and for
$\sqrt[3]{x}$ the step $g/g'$ is exactly $3x$, so $x_{k+1} = -2x_k$ — the error
doubles each step, because $g'(0) = \infty$ violates the theorem's hypothesis
as badly as possible. Production Newton codes are therefore safeguarded — damped,
line-searched or trust-regioned, as in Nocedal & Wright in the References — and
the raw iteration above is the fast local engine inside them.
Derivative-Free Methods
Random Search
Initialize $x$ with a random position
Until termination condition is met
Generate a random direction $d$
Move $x$ in the direction $d$ by a random step size $\alpha$
If $f(x+\alpha d) < f(x)$, then set $x=x+\alpha d$
The box above is local random search: it samples around the current
point and keeps only improving moves, so it needs no gradient and works on
discontinuous or noisy objectives — at the price of no convergence rate
beyond what the step-size schedule buys. Its global cousin, pure
random search, samples the whole feasible region independently at each
trial. Pure search has one exact, dimension-free guarantee: if the good
region occupies a fraction $q$ of the search volume, $N$ independent trials
miss it with probability $(1-q)^N$. With $q = 0.05$, $60$ trials already
hit the top $5\%$ with probability $1 - 0.95^{60} \approx 0.954$, and the
expected rank of the best of $N$ draws is the $1/(N+1)$ quantile. That is
why random search is a serious baseline for hyper-parameter tuning
(Bergstra & Bengio, in the References): a grid spends most of its
trials re-testing the same values of the few coordinates that matter,
while random draws test a fresh value of every coordinate every time.
Genetic Algorithm
Initialize a population of $N$ individuals
$$P_0 = \{x_0^1,\cdots,x_0^N\}$$
With fitness
$$\{f(x^i)\}$$
Until termination condition is met
Select based on fitness$$S(P_0)\to\left(x_k^i,x_k^j\right)\in P_k$$
Descendant according to some crossover rule
$$ D(x_k^i,x_k^j)\to d$$
With probability $p$, mutate $d$,
$$ M(d)\to d$$
add $d$ to the population
$$P_{k+1} = P_k\cup\{d\}$$
A genetic algorithm (Holland, in the References) is random search with
memory: instead of independent draws, a population of candidates is
carried forward, fitter individuals are selected as parents, crossover
recombines two parents' coordinates — the bet that good partial
solutions (schemata) compose — and mutation re-injects the variation
crossover destroys. The honest caveats belong beside the algorithm:
there is no general convergence rate, performance turns on the
encoding, the population size and the mutation probability $p$, and on
a smooth low-dimensional problem the gradient methods above will
usually beat it by orders of magnitude. Its niche is the opposite
corner — discrete, discontinuous or simulation-based objectives where
no derivative exists and a population's diversity is worth its cost.
Random Search & Genetic Algorithm, Computed
The two boxes above, run on one landscape — Himmelblau's function on
$[-5, 5]^2$, with its four equal minima — under one budget. The yardstick is
volume: a point's quantile is the fraction of the square
whose $f$ is no larger (measured on a $401 \times 401$ grid). The shaded region
is the top $5\%$, $f \le 11.42$ — the region the Random Search prose's hitting
law is about. Pure random search (seeded stream, seed 20261121) spends the
budget on independent uniform trials; its best-of-$N$ quantile has expectation
$1/(N+1)$, the dashed curve. The genetic algorithm spends the same budget with
memory: $24$ opening draws, then $22$ children per generation — tournament of
$3$, uniform crossover, mutation with $p = 0.3$ at $\sigma = 0.6$, the best $2$
carried over. Each Step buys both methods $22$ fresh evaluations.
top 5% region (f ≤ 11.42)random searchgenetic algorithm1/(N+1), the memoryless expectation
Pure random search: every trial independent, the cloud uniform over the square.The genetic algorithm's population at the current generation — selection concentrates it, mutation keeps it honest.Best-so-far quantile against evaluations spent (log scale). Lower is deeper into the square's best volume.
The race has three acts. Act one is luck, and it is quantifiable: the GA's
opening population of $24$ already holds a top-$5\%$ point ($f = 3.35$) — a
population that size had probability $1 - 0.95^{24} \approx 0.71$ of doing so —
while random search waits until evaluation $49$ to cross (a run still waiting
at $49$ has probability $0.95^{49} \approx 0.08$: this stream is mildly
unlucky, and the law says so). Act two is the plateau: between evaluations
$134$ and $244$ the random-search best does not move at all — no memory, no
mechanism to improve a good draw — while the GA's children, bred from its best
points, push from $0.32$ to $0.052$. Act three is the dive: at $904$
evaluations random search sits at $f = 0.1515$, quantile $5.8 \times 10^{-4}$
(about twice as lucky as its own $1/(N+1)$ expectation), and the GA sits at
$f = 2.1 \times 10^{-5}$ on the minimizer $(-2.805, 3.132)$, quantile
$6.2 \times 10^{-6}$ — a single cell of the $401 \times 401$ grid — some
$94$ times deeper into the volume at the same price.
That is the prose's claim with numbers on it: memory converts evaluations
from independent lottery tickets into a converging population — on a
landscape with structure to exploit. Both streams are seeded; the ratio
belongs to these streams, the mechanism is the section's.
Nelder-Mead
Given a function $f:\mathbb{R}^n\to \mathbb{R}$,
Initialize a simplex $S_0$ with $n+1$ vertices
$$S_0 = \{x_0,\cdots,x_{n}\}$$
$\delta_{e}\in (1,\infty)$
$\delta_{\text{c}}\in (0,1) $
$\gamma\in (0,1) $
Order $S_k$ by $f(x_0)\leq \cdots \leq f(x_{n})$
and set $f_{best}^k = f(x_0)$
Expansion: If $f_{\text{r}} < f_{\text{best}}^k$, then
$$x_{\text{e}}=x_{\text{o}} + \delta_{e}(x_\text{r}-x_{\text{o}})$$ $$
f_{\text{e}}=f(x_{\text{e}})$$ If $f_{\text{e}} < f_{\text{r}}$, then
$$x_n=x_{\text{e}}$$ else $$x_n=x_{\text{r}}$$
Reflection:
If $f_{\text{best}}^k \le f_{\text{r}} \le f(x_{n-1}) $, then
$$x_n = x_{\text{r}}$$
Contraction:
If $f(x_{n-1}) \le f_{\text{r}} \le f(x_n)$,
then
$$x_{\text{c}} = x_{\text{o}} +
\delta_{\text{c}}(x_{\text{r}}-x_{\text{o}} )$$ $$
f_{\text{c}} = f(x_{\text{c}})$$
If $f_{\text{c}} < f_{\text{r}} $, then $$x_n=x_{\text{c}}$$ else go to step 4
If $ f(x_n)\le f_{\text{r}} $, then
$$x_{\text{c}} = x_{\text{o}} +
\delta_{\text{c}}(x_n-x_{\text{o}})$$ $$
f_{\text{c}} = f(x_{\text{c}})$$
If $f_{\text{c}} < f(x_n)$, then $$x_n=x_{\text{c}}$$ else go to step 4
Increase k by 1 and go to step 2
Shrink
Set $S_{k+1}= \{x_0, x_0+\gamma(x_1-x_0),\cdots,x_0+\gamma(x_n-x_0)\}$ and go to step 2
Consider the simple example
$$f(x)=x^2$$
with
$$\delta_{e}=1.5$$
Case 1 : If we start with the initial simplex (ordered)
$$S_0 = \{(-4),(-5) \}$$
Then
$$f^0_{\text{best}} = f(-4) = 16$$
$$x_{\text{o}} = -4$$
$$x_{\text{r}} = -4 + (-4+5) = -3$$
$$f_{\text{r}} = f(-3) = 9$$
Since $f_{\text{r}} < f_{\text{best}}^0 $ $$x_{\text{e}}=-4 + 1.5(-3+4)=-2.5$$
$$f_{\text{e}}=f(-2.5)=6.25 < f_{\text{r}} $$ So we set $$x_1=x_{\text{e}}=-2.5$$
Nelder–Mead, Computed
The pseudocode above becomes a method you can watch in two dimensions, where the
simplex is a triangle. Each step ranks the three vertices, reflects the worst one
through the centroid of the other two, and then decides how brave to be:
expand if the reflection is the best point yet, accept the
reflection if it merely beats the second-worst,
contract if it disappoints, and — when even the contraction
fails — shrink the whole triangle toward its best vertex.
The demo runs the algorithm exactly as specified, with the standard coefficients
(reflection $1$, expansion $2$, contraction $\tfrac12$, shrink $\tfrac12$), on three
functions whose minima are known in closed form, so the crawl can be graded against
the truth. It stops when the triangle's longest edge first falls below
$10^{-6}$ ($10^{-5}$ on Rosenbrock, whose valley floor is that flat).
The three runs behave the way experience with the method suggests. The bowl takes
$55$ steps, and the mix changes as it descends: reflections and expansions do the
early travelling, while contractions — $45$ of the $55$ — do the close work of
shrinking the triangle onto $(1, -1)$, ending at $f \approx 2.7 \times 10^{-14}$.
Rosenbrock takes $92$: the triangle flattens against the valley wall, crawls along
the floor, and the expansions ($14$ of them) fire exactly where the reflection
keeps winning, along the valley's straightening run into $(1, 1)$. Himmelblau
takes $50$ steps into $(3, 2)$ — one of four identical minima, chosen by the
start, not by the function. Two honest caveats. The shrink step never fires in
any of the three runs: on smooth problems it is insurance, not the engine. And
Nelder–Mead has no general convergence guarantee —
McKinnon constructed a smooth, strictly convex function on which the method
converges to a point that is not even stationary. It survives in practice, and
in production codes, because it asks for no derivatives and is hard to break on
the low-dimensional problems it is meant for; the original 1965 paper is in the
References.
Linear Programming
Standard Form
A linear program in standard form is written as:
$$\begin{align}
\text{minimize} \quad & \mathbf{c}^T\mathbf{x} \\
\text{subject to} \quad & \mathbf{A}\mathbf{x} = \mathbf{b} \\
& \mathbf{x} \geq \mathbf{0}
\end{align}$$
where:
$\mathbf{x} \in \mathbb{R}^n$ is the vector of decision variables
$\mathbf{c} \in \mathbb{R}^n$ is the vector of objective function coefficients
$\mathbf{A} \in \mathbb{R}^{m \times n}$ is the constraint coefficient matrix
$\mathbf{b} \in \mathbb{R}^m$ is the right-hand side of the constraints
The feasible region of a linear program is a convex polyhedron.
Fundamental Theorem of Linear Programming If the feasible region
is non-empty and bounded, then the optimal solution occurs at a vertex of the feasible
region.
If an optimal solution exists, it occurs at a vertex of the feasible region.
If multiple optimal solutions exist, then at least one of them is at a vertex of the feasible
region.
Simplex Method
Convert the linear program to augmented form via slack variables:
$$\begin{align}
\text{minimize} \quad & \mathbf{c}^T\mathbf{x} \\
\text{subject to} \quad & \mathbf{A}\mathbf{x} + \mathbf{s} = \mathbf{b} \\
& \mathbf{c}^T\mathbf{x} - z = 0 \\
& \mathbf{x}, \mathbf{s} \geq \mathbf{0}
\end{align}$$
where $\mathbf{s}$ are slack variables and $z$ is the objective value
Find an initial basic feasible solution
While the solution can be improved:
Choose an entering variable (most negative reduced cost)
Choose a leaving variable (minimum ratio test)
Pivot to update the basis
If no negative reduced costs exist, the current solution is optimal
Duality
Shadow Prices
For every linear program (the primal), there exists a corresponding dual
linear program:
where $\mathbf{y} \in \mathbb{R}^m$ is the vector of dual variables, and the components of the optimal $y^*$ are called
the shadow prices.
Weak Duality
For any feasible solutions $\mathbf{x}$ and $\mathbf{y}$ to the primal and dual problems,
$$\mathbf{c}^T\mathbf{x} \leq \mathbf{b}^T\mathbf{y}$$
Strong Duality
If the primal problem has an optimal solution $\mathbf{x}^*$, then the dual problem also has an optimal
solution $\mathbf{y}^*$, and
$$\mathbf{c}^T\mathbf{x}^* = \mathbf{b}^T\mathbf{y}^*$$
Simplex, Computed
The Simplex box above states the rules and the Duality box states the theorems, but
neither runs a number. Here they are run, on one small program in the Duality box's own
maximization form: maximize $3x_1 + 4x_2$ subject to $x_1 + 2x_2 \le 11$,
$x_1 + 3x_2 \le 14$, $2x_1 + x_2 \le 16$ and $\mathbf{x} \ge 0$. Slack variables
$s_1, s_2, s_3$ put it in the augmented form of the Simplex box; the $z$ row carries the
reduced costs (it starts at $-c$); the entering variable is the most negative reduced
cost, the leaving variable is chosen by the minimum ratio test, and the run stops when
no negative reduced cost remains — the page's rules, word for word. Every entry is an
exact fraction, and no denominator larger than $3$ ever appears. Beside the tableau is
the same state drawn: the feasible polygon, the current basic feasible solution as a
vertex, and the objective contour through it, so each pivot is also a step along an
edge. Nothing below is scripted — each tableau is the previous one pivoted, and the
picture is drawn from the same fractions.
The tableau at the current step — the entering column and the leaving
row of the next pivot are shaded, and their crossing is the pivot element.
The same state as geometry: the feasible polygon, the objective contour
through the current vertex, and the gradient $(3, 4)$ as an arrow — the walk climbs
the polygon's edges.
The dual, read off the tableau
At the optimum, the $z$ row's entries under the slack columns are the
shadow prices $\mathbf{y}^*$ — and they satisfy the dual's constraints, with both
rows tight.
Strong duality, checked
Both objectives evaluated from the fractions above — the equality the
Duality box asserts, computed rather than quoted.
Complementary slackness
Each primal slack times its shadow price, and each variable times its
dual slack — every product must vanish, and each does.
Three things to read off. First, the objective climbs
$0 \to \frac{56}{3} \to 27 \to 29$, and every gain is one edge of the polygon: up the
$x_2$ axis to $(0, \frac{14}{3})$, along the second constraint's boundary to $(5, 3)$,
then along the first constraint's boundary to $(7, 2)$. The last pivot enters a slack
variable, $s_2$ — algebraically a slack becoming positive again, geometrically the walk
leaving the second constraint's boundary while staying on the first. Second, the dual
estimate read off the slack columns satisfies $\mathbf{b}^T\mathbf{y}^{(k)} = z_k$ at
every step, feasible or not — that identity is the tableau's bookkeeping, not duality —
and it becomes a dual solution only at the end: at step 2 it is $(5, -2, 0)$, with both
dual constraints already tight and one component negative. Third, the finale is the
Duality box evaluated: $\mathbf{y}^*$ is dual feasible, so weak duality turns $29$ into
an upper bound on every feasible objective value, and strong duality is the equality
the check line verifies — together with complementary slackness, whose five products
each vanish because one factor does: a binding constraint, a zero price on the one
loose constraint, a tight dual row.
Interior Point Methods
While the simplex method moves along the boundary of the feasible region, interior point methods traverse the
interior of the feasible region. These methods are particularly effective for large-scale problems.
Start with a strictly feasible point (in the interior of the feasible region)
Until convergence:
Compute a search direction that improves the objective while staying away from the
boundary
Determine an appropriate step size
Move in the computed direction by the determined step size
Modern interior point methods include:
Path-following methods: Follow the central path to the optimal solution
Potential reduction methods: Minimize a potential function that combines the objective and a
barrier term
Affine-scaling methods: Scale the variables to stay away from boundaries
Interior Point, Computed
The box above states the idea in words — start in the interior, improve while staying
away from the boundary — and lists path-following first among the modern variants. Here
it is run, on the Simplex demo's program, so the two methods can be compared on the same
feasible polygon: maximize $3x_1 + 4x_2$ subject to the same three constraints and
$\mathbf{x} \ge 0$. The method is primal-dual: it carries a dual estimate $\mathbf{y}$
alongside $\mathbf{x}$, with slacks $\mathbf{s} = \mathbf{b} - A\mathbf{x}$ on the primal
side and $\mathbf{z} = A^T\mathbf{y} - \mathbf{c}$ on the dual side, and drives the five
complementarity products $s_i y_i$ and $x_j z_j$ toward a common value $\mu$. The start
$\mathbf{x} = (1, 1)$, $\mathbf{y} = (1, 1, 1)$ is strictly feasible on both sides, so
the duality gap is exactly the sum of those products:
$\mathbf{b}^T\mathbf{y} - \mathbf{c}^T\mathbf{x} = 5\mu$ at every step — a running
certificate, not a hope. Each step solves Newton's system for the optimality conditions
with every product re-centred at $\mu/10$ — one decade of gap per step — and shortens
the step to $99\%$ of the distance to the boundary, so no iterate ever touches it. The
numbers are decimals printed to six places; unlike the tableau above, nothing here is
exact, and the gap column is the honest measure of what remains.
The whole run at a glance — the current step is shaded; $z$ is the
objective $3x_1 + 4x_2$ and the gap is $\mathbf{b}^T\mathbf{y} - \mathbf{c}^T\mathbf{x}$,
equal to $5\mu$ throughout: the certificate shrinking by a decade a step.
The same run as geometry: the iterates curve through the interior and
settle onto the vertex $(7, 2)$ without ever touching an edge — the dashed contour
is the objective through the current iterate.
The dual, approached
The dual iterates settle where the tableau's finale read the shadow
prices off the $z$ row — the same $\mathbf{y}^*$, reached from the interior.
The certificate
Weak duality brackets the optimum between the primal and dual values;
the bracket's width is the final gap.
Three things to read off. First, the contrast with the walk above: the simplex visited
four vertices and finished in three pivots; this run takes thirteen steps and visits no
vertex at all — its iterates curve through the interior, swing out to within $0.109$ of
the third constraint's boundary at step 2, and only settle onto $(7, 2)$ as $\mu$ falls.
Second, the early steps are shortened — the step lengths in the notes are
$\alpha = 0.458, 0.857, 0.706, 0.733$ — because the full Newton step would cross a
boundary; from step 4 on the steps are full ($\alpha = 1$) and $\mu$ falls by almost
exactly its decade each time. Third, the endpoint agrees with the tableau's: the dual
iterates settle at $(5/3, 0, 2/3)$ to the printed digits, the same shadow prices read
off the $z$ row in the finale above, and the final gap $5.7 \times 10^{-10}$ brackets
the optimum, $z^* \in [28.9999999998, 29.0000000003]$, with $29$ inside. That is the
method in one picture: a step count driven by the gap's decades — in theory
$O(\sqrt{n}\,\log(1/\varepsilon))$ steps, a bound in the problem's size — never by the
number of vertices, which is where a boundary walk can be made to crawl.
$V_i(y)$ is the value function at stage $i$ and state $y$
$f_i(y,x)$ represents the immediate reward/cost from decision $x$ at state $y$
$g_i(y,x)$ describes the system transition from state $y$ under decision $x$
Key principles of Dynamic Programming:
Optimal Substructure: The optimal solution contains optimal solutions to subproblems
Overlapping Subproblems: The same subproblems are encountered multiple times
Backward Induction: Starting from the last stage and moving backward, we solve each stage
sequentially until reaching the initial stage
Stochastic Dual Dynamic Programming
Stochastic Dual Dynamic Programming (SDDP) is an advanced optimization technique that extends dynamic
programming to handle multi-stage stochastic optimization problems with high-dimensional state spaces.
SDDP addresses problems of the form:
$$\begin{align}
\min_{u_1, \ldots, u_T} \quad & \mathbb{E}\left[\sum_{t=1}^{T} c_t(x_t, u_t, \xi_t)\right] \\
\text{subject to} \quad & x_{t+1} \in \mathcal{X}_t(x_t, u_t, \xi_t), \quad t = 1, \ldots, T
\end{align}$$
where:
$T$ is the number of time stages
$x_t$ is the state at stage $t$
$u_t$ is the decision variable at stage $t$
$\xi_t$ is the random variable (uncertainty) at stage $t$
$c_t$ is the cost function at stage $t$
$\mathcal{X}_t$ is the state transition set at stage $t$: the possible next states given the
current state, the decision, and the current uncertainty
The key equation in SDDP is the Bellman equation:
$$V_t(x_t) = \min_{u_t \in \mathcal{U}_t(x_t)} \mathbb{E}\left[c_t(x_t, u_t, \xi_t) +
V_{t+1}(x_{t+1}) \mid x_t, u_t\right], \quad t = 1,\ldots,T$$
where:
$V_t(x_t)$ is the optimal cost-to-go function at stage $t$ given state $x_t$
$c_t(x_t, u_t, \xi_t)$ is immediate cost incurred at stage $t$
$u_t$ are decision variables at stage $t$
$\mathcal{U}_t(x_t)$ defines feasible decisions based on current state $x_t$
The expectation operator $\mathbb{E}[\cdot]$ is over the uncertainty $\xi_t$ and the next
state $x_{t+1}$ it induces
Terminal condition: $V_{T+1}(x_{T+1}) = 0$
This recursive formulation is the Bellman equation that we have seen earlier.
Algorithm Structure
Initialization:
Build initial approximations of the cost-to-go functions for all stages
Set iteration counter $k = 0$
Forward Pass:
Generate sample paths of the uncertainties $\{\xi_t^k\}_{t=1}^T$
For each stage $t = 1, \ldots, T$:
Solve the stage problem using the current approximation of the cost-to-go function
$$u_t^k = \arg \min_{u_t \in \mathcal{U}_t(x_t^k)} \left[c_t(x_t^k, u_t, \xi_t^k) +
\tilde{V}_{t+1}(x_{t+1}^k)\right]$$
where $\tilde{V}_{t+1}(\cdot)$ is approximated by existing cuts
Store the optimal solutions $\{u_t^k\}$ and state variables $\{x_t^k\}$
Backward Pass:
For each stage $t = T, \ldots, 2$ (working backwards):
For each sampled state from the forward pass:
Compute the dual variables (shadow prices) of the constraints
Generate and add cutting planes to improve the approximation of the cost-to-go
function
The cutting planes take the form:
$$V_{t+1}(x_{t+1}) \geqslant a_{t+1}^Tx_{t+1} + b_{t+1}$$
where $a_{t+1}$ are the dual variables and $b_{t+1}$ is the intercept term
Convergence Check:
Calculate upper and lower bounds on the optimal value
If bounds are sufficiently close or maximum iterations reached, stop
Otherwise, increment $k$ and return to step 2
Example: Hydropower Planning
Consider a multi-reservoir hydropower system planning problem:
State variables: Water levels in reservoirs
Decision variables: Water releases and power generation
Uncertainty: Inflows to reservoirs (dependent on rainfall)
Objective: Minimize expected cost of operation and thermal generation
Constraints: Water balance, generation limits, transmission constraints
This problem has continuous state and action spaces, multiple stages (e.g., weekly planning for a
year), and significant uncertainty, making it suitable for SDDP.
In the hydropower planning context, SDDP would:
In the forward pass: Simulate operation decisions for sample inflow scenarios
In the backward pass: Build cutting planes that approximate the future cost function
Iteratively refine the approximation until convergence
The resulting policy provides operation decisions (water releases) for any reservoir level and inflow
scenario, balancing immediate generation with future water value.
Advantages and Limitations
Advantages:
Can handle high-dimensional continuous state spaces where traditional DP suffers from the curse of
dimensionality
Provides both primal solutions (decisions) and dual information (marginal values)
Delivers upper and lower bounds on the optimal solution value
Handles complex constraints and objective functions
Limitations:
Requires convexity of the problem (for the cuts to be valid)
Computational intensity increases with the number of stages and random variables
May struggle with very rare events or "black swan" scenarios
Classical version assumes stagewise independence of random variables
Extensions
Several extensions to the basic SDDP algorithm have been developed:
Risk-averse SDDP: Incorporates risk measures like CVaR (Conditional Value-at-Risk) instead of
expectation
Inexact SDDP: Uses approximate solutions in the backward pass to reduce computational burden
Multistage stochastic decomposition: Combines SDDP with stochastic approximation techniques
SDDP with auto-regressive random variables: Handles temporal dependencies in the uncertain parameters
Reinforcement Learning
Reinforcement Learning problems are typically formalized as Markov Decision Processes (MDPs), defined by
the tuple $(S, A, P, R, \gamma)$:
$S$ is the state space
$A$ is the action space
$P$ is the transition probability: $P(s'|s,a)$
$R$ is the reward function: $R(s,a,s')$
$\gamma \in [0,1]$ is the discount factor, balancing immediate vs. future rewards
The objective is to find an optimal policy $\pi^*$ that maximizes the
expected cumulative discounted
reward:
$$\max_{\pi} \mathbb{E}_{\pi}\left[\sum_{t=0}^{\infty} \gamma^t r_t\right]$$
Value Functions and Optimality
The state-value function $V^{\pi}(s)$ represents the expected return
starting
from state $s$
and following policy $\pi$:
Unlike dynamic programming approaches, model-free methods don't require knowledge of the transition
probabilities and reward function. They learn directly from experience.
Bandit, Computed
Strip the state out of reinforcement learning and what remains is the
multi-armed bandit: one choice, repeated, with no context and
no transitions — the base case every method in this section generalizes. The demo
runs the standard instance. Five arms pay Gaussian rewards with $\sigma = 1$ and
means $\mu = 0.2,\ 0.5,\ 0.8,\ 1.1,\ 1.4$, printed in the table; arm 5 is best, and
the gaps are $\Delta = 1.2,\ 0.9,\ 0.6,\ 0.3,\ 0$. The score is
cumulative regret: the sum over pulls of the mean gap
$\mu^* - \mu_{a_t}$ of the arm actually pulled — what the choices cost against
always pulling the best arm, with the luck of each draw averaged out of the
accounting. Two strategies face the same seeded reward stream (each arm's
2,000 rewards are drawn in advance, so the comparison is paired, pull for pull):
$\epsilon$-greedy with $\epsilon = 0.1$ — pull the empirical
best arm, except on a tenth of pulls, chosen uniformly at random — and
UCB1, which pulls the arm maximizing
$\bar x_i + \sqrt{2 \ln t \,/\, n_i}$: the empirical mean plus an exploration bonus
that shrinks as the arm is sampled and grows, slowly, for every arm left alone.
Both start by pulling each arm once. The dashed curve is the
Lai–Robbins asymptotic, $\sum_i 2 \ln t / \Delta_i$ — the
growth rate no strategy's expected regret can beat in the limit.
UCB1ε-greedy (ε = 0.1)Lai–Robbins asymptotic
Cumulative regret against the best arm (μ = 1.4) over
2,000 pulls. ε-greedy leads early — UCB1 pays its systematic exploration up
front — and is passed near pull 700, after which its regret grows linearly
while UCB1's flattens.
The finished runs make the tradeoff concrete. UCB1 ends at regret $84.0$,
$\epsilon$-greedy at $115.2$ — and the pull counts hold the surprise:
$\epsilon$-greedy pulls the best arm more often ($1{,}842$ of $2{,}000$,
$92.1\%$, against UCB1's $1{,}775$) and still loses. UCB1 makes more mistakes
($225$ suboptimal pulls to $158$) but cheaper ones: it spends $191$ of them on the
$\Delta = 0.3$ arm, the only arm genuinely hard to tell from the best, while
$\epsilon$-greedy's exploration tax falls uniformly — $\epsilon$ times the average
gap, $0.06$ per pull, forever. The last $500$ pulls show the two futures plainly:
$\epsilon$-greedy pays $32.4$ more regret, UCB1 pays $1.5$, because its bonus for
the settled arms has decayed like $\sqrt{\ln t / n}$. Two honest caveats. The
dashed Lai–Robbins curve reaches $105.6$ at $t = 2{,}000$, above UCB1's $84.0$ —
no contradiction: the bound governs expected regret in the limit, and a
single realization at a finite horizon can finish below it. And one seeded stream
is one realization — the ordering of the two strategies is the theorem's, but the
exact numbers belong to this stream. The $\epsilon$-greedy rule returns immediately
below, doing duty as Q-learning's behavior policy; the bandit is where it can be
graded exactly.
Temporal Difference Learning
Initialize $Q(s,a)$ arbitrarily for all state-action pairs
For each episode:
Initialize state $s$
For each step of the episode:
Choose action $a$ from $s$ using policy derived from $Q$ (e.g.,
$\epsilon$-greedy)
Take action $a$, observe reward $r$ and next state $s'$
The key difference between Q-Learning and SARSA is that Q-Learning is an off-policy method (learns the
value of the optimal policy), while SARSA is an on-policy method (learns the value of the policy being
followed).
Policy Gradient, Computed
Policy gradient methods directly optimize the policy without using a value function. The policy is
typically parameterized by a vector $\theta$:
$$\pi_\theta(a|s) = P(a|s,\theta)$$
Take the bandit above as a one-state MDP and the theorem becomes an algorithm
you can watch. The policy is a softmax over five
preferences, one per arm: $\pi_\theta(a) = e^{\theta_a} / \sum_j e^{\theta_j}$,
starting from $\theta = 0$, so every arm begins at probability $1/5$. For a
softmax the score has a closed form, $\nabla_{\theta_j} \log \pi_\theta(a) =
\delta_{aj} - \pi_\theta(j)$ — the gradient pushes the pulled arm's preference
up and every other arm's down, in proportion to its current probability. The
demo runs REINFORCE (Williams 1992): after each pull
of arm $a$ for reward $r$,
$$\theta \leftarrow \theta + \alpha\, (r - b)\, (e_a - \pi_\theta),$$
where the baseline $b$ is the running mean of all rewards
received so far ($0$ before the first pull). The baseline never depends on the
action just taken, so it leaves the expected update — the gradient — unchanged
while damping the noise of single rewards. No value is estimated anywhere: there
is no $\bar x_i$, no bonus, no $Q$ table. The policy itself is the thing being
optimized, one stochastic-gradient step per pull, on the bandit's own seeded
reward streams (seed 20261119) with its own action-sampling stream (seed + 21).
The step size $\alpha$ is yours to move.
REINFORCE (α = 0.10)UCB1Lai–Robbins asymptotic
Cumulative regret against the best arm (μ = 1.4) over
2,000 pulls. REINFORCE pays for its learning up front — its early pulls are
near-uniform — then flattens as the softmax saturates on the best arm.
At the default $\alpha = 0.1$, REINFORCE ends at regret $93.0$ against UCB1's
$84.0$ and $\epsilon$-greedy's $115.2$ — a near-tie with the value method, reached
the opposite way. It pays about twice as much as UCB1 over the first 500 pulls
($78.9$ to $39.6$), while its policy is still close to uniform, and then almost
nothing: $3.3$ over the last 500 pulls, against UCB1's $1.5$ — by then both
policies have settled, and the race was decided in the opening. By pull 100 the best arm already holds
probability $0.40$; by pull 200, $0.75$; at the end $0.992$, with $1{,}846$ of
$2{,}000$ pulls on it. The step size is the whole story. On this stream
$\alpha = 0.05$ finishes at $240.0$ (best-arm probability still climbing, $0.975$),
$\alpha = 0.2$ at $59.7$, and $\alpha = 0.5$ at $16.2$ — bigger steps learn
faster here, because the first lucky pulls point at the right arm. That is a
gamble, not a free lunch: across twelve action-sampling streams at
$\alpha = 0.5$, eleven lock onto the best arm (regret $9$–$54$) but one saturates
on the second-best arm instead — regret $603.6$, arm 4 pulled $1{,}975$ times,
the best arm's probability driven to $0.000$ and never recovered, because a
saturated softmax stops sampling the arm that would correct it. At
$\alpha = 0.1$ all twelve streams end with the best arm above $0.97$ (regret
$82$–$283$): the small step cannot be trapped the same way, it only learns
slowly. The contrast with the value methods is the section's point in miniature:
$\epsilon$-greedy and UCB1 keep estimates and act on them; REINFORCE keeps no
estimates at all, and its exploration is the policy's own randomness, which the
gradient spends down as it learns.
References
Nocedal & Wright, Numerical Optimization, 2nd ed., Springer, 2006 — the working
reference for General Optimization Methods: gradient descent and its convergence, Newton's
method and its quasi-Newton descendants, line searches, and the derivative tests made
algorithmic.
Polyak, Some methods of speeding up the convergence of iteration methods, USSR Computational Mathematics and Mathematical Physics 4(5), 1964, 1–17 — the heavy-ball method behind the Optimizer Race demo: a velocity that accumulates along persistent gradient directions and cancels across a valley's zigzag.
Kingma & Ba, Adam: A method for stochastic optimization, Proc. ICLR 2015 — the race's third runner: bias-corrected first- and second-moment estimates giving a per-coordinate step size, with the defaults β₁ = 0.9, β₂ = 0.999 used in the demo.
Boyd & Vandenberghe, Convex Optimization, Cambridge University Press, 2004 — the
convex theory under the whole page: duality in full generality and the interior-point methods
that the Linear Programming part ends with.
Nelder & Mead, A simplex method for function minimization, The Computer Journal
7(4), 1965, 308–313 — the Derivative-Free Methods section's simplex: a geometric search that
reflects, expands and contracts its way downhill without ever evaluating a derivative (no
relation to Dantzig's simplex).
Holland, Adaptation in Natural and Artificial Systems, MIT Press, 1992 — the founding
text behind the Genetic Algorithm section: schemas, selection, crossover and mutation as a
search procedure over populations.
Bergstra & Bengio, Random search for hyper-parameter optimization, J. Mach.
Learn. Res. 13, 2012, 281–305 — the Random Search section's source: random draws dominate
grid search when only a few coordinates matter, with the $1-(1-q)^N$ hitting calculation.
Vanderbei, Linear Programming: Foundations and Extensions, 5th ed., Springer, 2020 —
the Linear Programming part's text: standard form, the simplex method, duality and shadow
prices, and the interior-point variants.
Karmarkar, A new polynomial-time algorithm for linear programming, Combinatorica 4,
1984, 373–395 — the paper that opens the Interior Point Methods section: projective scaling,
polynomial worst-case complexity, and the race with the simplex method that followed.
Pereira & Pinto, Multi-stage stochastic optimization applied to energy planning,
Mathematical Programming 52, 1991, 359–375 — the paper behind the SDDP section, written for
the page's own running example: stochastic dual dynamic programming for hydropower planning.
Shapiro, Dentcheva & Ruszczyński, Lectures on Stochastic Programming: Modeling and
Theory, 2nd ed., SIAM, 2014 — the theory behind the Multi-Stage Stochastic Optimization
part: scenario trees, risk measures, duality and the decomposition algorithms SDDP belongs
to.
Puterman, Markov Decision Processes: Discrete Stochastic Dynamic Programming, Wiley,
2005 (paperback reprint) — the dynamic-programming foundation the Reinforcement Learning part
builds on: value functions, the optimality equations and policy iteration, stated exactly.
Sutton & Barto, Reinforcement Learning: An Introduction, 2nd ed., MIT Press,
2018 — the Reinforcement Learning part's text: value functions and optimal policies,
temporal-difference learning, and the policy gradient methods that close the page.
Williams, Simple statistical gradient-following algorithms for connectionist
reinforcement learning, Machine Learning 8, 1992, 229–256 — REINFORCE: the
gradient-following update the Policy Gradient, Computed demo runs on the bandit,
with the running-mean baseline.
Lai & Robbins, Asymptotically efficient adaptive allocation rules, Advances in
Applied Mathematics 6, 1985, 4–22 — the bandit lower bound: expected regret grows at least
like $\sum_i 2 \ln t / \Delta_i$ for unit-variance Gaussian arms, the dashed curve in the
Bandit, Computed demo.
Auer, Cesa-Bianchi & Fischer, Finite-time analysis of the multiarmed bandit
problem, Machine Learning 47, 2002, 235–256 — UCB1 and its finite-time logarithmic
regret bound; the demo runs the algorithm beside $\epsilon$-greedy on one seeded stream.