关于「跳出局部最优:探索与利用」,《沙盘、宿命与主动推理》给出的定量结论是什么?
结论:爬山法几乎总停在离起点最近的小丘上(找到全局最高点的只有 2%,多是本来就从附近出发的)。模拟退火显著改善了平均到达的高度(从 0.99 到 2.16),找到全局最高点的比例也随步数增加,从 8% 升到 20%。但它远不是保证:理论上,只有当温度以对数速度极其缓慢地下降时,退火才以概率 1 找到全局最优 (Hajek 1988),实际中没人能等那么久。这个结果是一个诚实的提醒:探索提高了找到更好位置的机会,但不能保证找到最好的位置。
数据口径:本书不是心理治疗或诊断;关于「旧先验驱动重复挫折」的内容是假说与跨学科类比,绝不意味着受害者要为自己的遭遇负责。 书中以标注框区分已发表的证据、可运行的 Python 计算(15 段程序,全部核对)、原典与作者的假说。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 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 |
查看完整验算程序
# 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}")唯一数据源与引用
范雅福(Fan, Y.). (2026). 《沙盘、宿命与主动推理》第 4 章「跳出局部最优:探索与利用」(版本 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.23738794
DOI: 10.5281/zenodo.23738794 · 阅读本章所在专著 · 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}
}