Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Run one simulated annealing iteration

Use when: you have a current point x, its value f(x), a temperature T, and a candidate neighbor x' to consider

Goal: the next current point and the cooled temperature to carry into the next iteration

Taught in Simulated annealing

  1. 1

    \Delta E = f(x') - f(x), the candidate's value minus the current point's.

    Example

    Current x=3 with f(x)=4; candidate x'=1 with f(x')=16: \Delta E = 16-4=12.

    Why: the SIGN of \Delta E decides which acceptance rule below applies; the size decides how likely an uphill move is to be accepted.

  2. 2

    The rule branches on the sign of \Delta E from the step above.

    Example

    With T=2: P=e^{-12/2}=e^{-6}\approx0.00248. A draw u=0.05 has u\not<P, so reject; x stays at 3.

    • \Delta E \le 0 — always accept, x \leftarrow x'.
    • \Delta E > 0 — compute P=e^{-\Delta E/T}, draw a random u \in [0,1), accept (x\leftarrow x') only if u<P.

    Why: this is what lets the search occasionally climb out of a local dip (Section 6's own layman analogy) instead of only ever moving downhill.

  3. 3

    Update T \leftarrow \gamma T for a fixed cooling factor \gamma<1 (commonly 0.8-0.99).

    Example

    T=2, \gamma=0.9: next temperature is 2(0.9)=1.8.

    Why: a slower cooling schedule (gamma closer to 1) explores longer before committing to refine one region, at the cost of more iterations.

Common mistakes

  • Accepting an uphill move only when u \le P using a bad inequality direction, or forgetting to draw a FRESH random number each time.
  • Comparing \Delta E to T directly instead of computing e^{-\Delta E/T} -- a bigger \Delta E makes the move LESS likely, not proportionally rejected.
  • Cooling T before deciding the current iteration's accept/reject, which uses the wrong temperature for this step's own decision.