Simulated Annealing
A randomized optimization method, inspired by how slowly-cooled metal settles into a low-energy crystal structure, that occasionally accepts a worse move on purpose — with the chance of doing so shrinking over time — to escape local minima that pure downhill search would get stuck in.
Prerequisites: Non-Convex Optimization Landscapes, Gradient Descent
Gradient descent and its relatives only ever move downhill, which means on a bumpy non-convex landscape, once they roll into a shallow local dip, they're stuck — there's no downhill move available, even if a much deeper valley sits just beyond a nearby ridge. Simulated annealing takes a deliberately different approach: sometimes accept a step that makes things worse, so the search can climb out of a shallow trap, but make that willingness fade over time so the search still eventually settles down rather than wandering forever.
An analogy: cooling metal into a strong crystal
The method borrows its name and logic from metallurgy. Heat a metal and let it cool slowly, and its atoms have enough thermal energy early on to jostle into many different configurations, occasionally settling briefly into a poor, high-energy arrangement before jostling free of it again — but as the temperature drops, that jostling weakens, and the atoms increasingly can only accept moves that lower their energy, eventually locking into a strong, low-energy crystal lattice. Cool it too fast (quench it) and the atoms get frozen into whatever disordered arrangement they happened to be in — a weak, defect-riddled structure, exactly analogous to gradient descent getting stuck in the first local minimum it meets.
The method, one symbol at a time
At each step, given current point with objective value , propose a random nearby candidate . If (a genuine improvement), always accept it. If (a worse move), accept it anyway with probability
where is a temperature parameter that starts high and is gradually lowered according to a cooling schedule. In plain English: a slightly worse move is often accepted, but a much worse move is rarely accepted, and the tolerance for worse moves shrinks as falls — early on the search happily wanders through the landscape (exploration), and late in the process it behaves almost exactly like plain downhill descent (exploitation), because by then is so small that only genuine improvements have any real chance of being accepted.
Worked example 1: computing acceptance probability by hand
Suppose the search is at a point with , and a proposed move has — a worsening of . At high temperature : , so this worse move is accepted about 67% of the time — the search is still exploring freely. Later, once the schedule has cooled to : , so the same-sized worsening is now accepted only about 1.8% of the time — the search has become nearly pure downhill descent. The exact same move (same ) is treated very differently depending purely on how far along the cooling schedule the search is.
Worked example 2: escaping a local minimum on the two-dip function
Recall from non-convex landscapes, with a local minimum near (value ) and the true global minimum near (value ). Plain gradient descent from gets stuck at . Simulated annealing starting from the same point, with a moderately high initial temperature, will sometimes accept moves that temporarily raise — for instance stepping from (value ) to (value , much worse, ) has acceptance probability ; at that's , a real chance of accepting. Enough such uphill excursions, tried repeatedly across many candidate moves, let the search occasionally cross the local max separating the two dips and discover the deeper global minimum near — something gradient descent from that same starting point can never do.
What this means in practice
Simulated annealing is a practical, easy-to-implement heuristic for hard combinatorial or non-convex problems where an exact method is too slow or doesn't apply — portfolio construction with awkward discrete constraints, scheduling execution across venues, or tuning strategy parameters on a genuinely bumpy backtest-performance surface. It comes with no guarantee of finding the true global optimum in finite time, but empirically it often finds much better solutions than plain hill-climbing on the same problem, for a modest extra computational cost.
Simulated annealing deliberately accepts some worse moves, with a probability controlled by a temperature parameter that starts high and cools over time, letting the search escape shallow local minima early on while still converging to a stable, near-greedy answer by the end.
The cooling schedule is the entire game and there's no universally correct choice: cool too fast, and the method behaves just like plain gradient descent — it "quenches" into whatever local minimum it's near before it ever gets a real chance to explore, defeating the whole purpose. Cool too slowly, and the search wastes enormous computational effort wandering with little to show for it. Reporting a simulated annealing result without specifying and justifying the cooling schedule used is a common oversight — the same problem instance can give very different quality answers under different schedules.
Related concepts
Practice in interviews
Further reading
- Kirkpatrick, Gelatt & Vecchi, Optimization by Simulated Annealing
- Aarts & Korst, Simulated Annealing and Boltzmann Machines