What does The Sandbox, Determinism and Active Inference conclude, in numbers, about “Escaping the Local Optimum: Exploration and Exploitation”?
Answer: Hill climbing nearly always stops on the hill nearest its start (it reaches the global peak in only 2 % of starts, mostly ones that began nearby). Simulated annealing raises the mean height reached considerably (from 0.99 to 2.16), and the share of starts that reach the global peak rises with the number of steps, from 8 % to 20 %. But it is far from a guarantee: in theory annealing finds the global optimum with probability one only if the temperature falls logarithmically, extremely slowly (Hajek 1988), and in practice nobody can wait that long. The result is an honest reminder: exploration raises the chance of finding a better position but cannot guarantee finding the best one.
Scope of the numbers: Marked boxes separate published evidence, runnable Python calculations (15 programs, all checked), classical sources and the author's hypotheses. This book is not psychotherapy or diagnosis; its account of old priors driving repeated setbacks is a hypothesis and a cross-disciplinary analogy and never implies that victims are responsible for what happened to them.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 0.99, 2.16, 20
| local peaks: 72; global peak at x = 813, height 3.50 | |
| hill climbing : found the global peak in 2% of 300 starts; mean height reached 0.99 | |
| annealing, 1,000 steps : found the global peak in | 8% of 300 starts; mean height reached 1.82 |
| annealing, 4,000 steps : found the global peak in | 12% of 300 starts; mean height reached 1.94 |
| annealing, 16,000 steps: found the global peak in | 20% of 300 starts; mean height reached 2.16 |
Show the full program
# Hill climbing versus simulated annealing (Kirkpatrick, Gelatt & Vecchi 1983) on a rugged landscape
# of 1,000 positions. A move is one step left or right. Annealing sometimes accepts a worse step,
# with probability exp(delta / T), and lowers the temperature T as it goes.
import math, random
def f(x):
return (math.sin(x / 9.0) + 0.6 * math.sin(x / 2.3) + 0.35 * math.sin(x / 1.7)) + 2.0 * math.exp(-((x - 820) / 60) ** 2)
XS = range(1000)
GLOBAL = max(XS, key=f)
peaks = sum(1 for x in range(1, 999) if f(x) > f(x - 1) and f(x) > f(x + 1))
print(f"local peaks: {peaks}; global peak at x = {GLOBAL}, height {f(GLOBAL):.2f}")
def climb(x, rng, steps=4000):
for _ in range(steps):
y = min(999, max(0, x + rng.choice((-1, 1))))
if f(y) >= f(x):
x = y
return x
def anneal(x, rng, steps=4000, t0=2.0, t1=0.01):
best = x
for i in range(steps):
temp = t0 * (t1 / t0) ** (i / steps) # geometric cooling
y = min(999, max(0, x + rng.choice((-3, -2, -1, 1, 2, 3))))
d = f(y) - f(x)
if d >= 0 or rng.random() < math.exp(d / temp):
x = y
if f(x) > f(best):
best = x
return best
rng = random.Random(5)
starts = [rng.randrange(1000) for _ in range(300)]
runs = (("hill climbing", lambda x, r: climb(x, r)), ("annealing, 1,000 steps", lambda x, r: anneal(x, r, steps=1000)),
("annealing, 4,000 steps", lambda x, r: anneal(x, r)), ("annealing, 16,000 steps", lambda x, r: anneal(x, r, steps=16000)))
for name, fn in runs:
ends = [fn(x0, random.Random(i)) for i, x0 in enumerate(starts)]
hit = sum(f(x) > f(GLOBAL) - 0.05 for x in ends) / len(ends)
mean_h = sum(f(x) for x in ends) / len(ends)
print(f"{name:23s}: found the global peak in {hit:4.0%} of 300 starts; mean height reached {mean_h:.2f}")Single source and citation
Fan, Y. (2026). The Sandbox, Determinism and Active Inference (Version 1.0.0), Chapter 4: Escaping the Local Optimum: Exploration and Exploitation. 5D Library. https://doi.org/10.5281/zenodo.23738794
DOI: 10.5281/zenodo.23738794 · Read the monograph · 5DL-B-015 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026015,
author = {Fan, Yafu},
title = {The Sandbox, Determinism and Active Inference},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
doi = {10.5281/zenodo.23738794},
url = {https://doi.org/10.5281/zenodo.23738794}
}Other chapter answers in this book
- Chapter 1 · The Bayesian Brain and the Self-Fulfilling Prophecy
- Chapter 2 · Two Routes: Change the Mind, or Change the World
- Chapter 3 · Markov Blankets and the Boundary of the Individual
- Chapter 5 · Structured Sandboxes and the Reshaping of Priors
- Chapter 6 · Determinism, Chaos and Agency
- Chapter 8 · Practice and a Pre-Registered Trial