Simulated Annealing
A probabilistic walk that escapes local optima as it cools.
- Quality
- Medium to High
- Speed
- Moderate
- Budget
- O(N)
How it works
Simulated Annealing borrows an idea from metalworking: heat lets a material explore many shapes, and slow cooling locks in a good one.
It starts from a random parameter set and proposes a small change each cycle. A better result is always kept. A worse result is sometimes kept too, with a probability that shrinks over time. That willingness to occasionally go downhill early is what lets it climb back out of a shallow dip toward a higher peak.
As the run cools, those uphill-only late cycles converge on the best region the early wandering uncovered.
Under the hood
The temperature follows a linear schedule, T = 1 minus i / N across the run. For numeric parameters the neighbourhood size scales with T, so proposals are large early and fine near the end, always clamped to your range and snapped to the step grid.
Booleans flip with a fixed 30% probability rather than a temperature-scaled one, since a bit has no continuous neighbourhood. There is no separate restart logic: the single cooling pass is the whole algorithm.
It is a strong middle ground. With four to ten parameters on a bumpy surface it beats coordinate descent and random, while staying cheaper to reason about than a full Bayesian model.
- Temperature
- Linear
- T = 1 - i / N
- Numeric step
- Scales with T
- Boolean flip
- 30% per cycle
Configure Simulated Annealing
How Simulated Annealing is set up and what it does under the hood, as copy-ready reference. Set parameter ranges and the optimization target on the methods overview .
Annealing cooling schedule
PythonTemperature falls linearly across the run. The numeric neighbourhood scales with temperature (wide early, fine late); booleans flip at a fixed rate rather than a temperature-scaled one.
def temperature(i, n):
return 1 - i / n # 1.0 at the start, ~0 at the end
BOOLEAN_FLIP_PROB = 0.30 # fixed, not temperature-scaled
temperature(0, 100), temperature(50, 100), temperature(99, 100) # 1.0, 0.5, 0.01 When to use it
Reach for it when
- Three to ten parameters with a bumpy metric landscape
- When a plain hill-climb keeps getting stuck in local optima
- As a middle ground between Random and Bayesian search
Reach for something else when
- Very large spaces where TPE is more sample-efficient
- When you need a deterministic, repeatable plan
Auto-selected: Auto-selected when 4 to 10 parameters are enabled.
Want to see optimization in action? Browse our strategy backtesting and robustness examples on NVDA, TSLA, and AAPL.
New to this? Read how to run your first optimization or learn how to choose the right optimization method for your strategy.
Related methods
-
Recommended
TPE (Bayesian)
Builds a probabilistic model of what works and spends your cycles where the payoff is most likely.
Quality 5 of 5Speed 5 of 5O(N) How it works -
Random
Picks a fresh independent parameter set every cycle. No memory, hard to beat as a baseline.
Quality 3 of 5Speed 5 of 5O(N) How it works