{"id":255,"date":"2026-11-13T12:36:03","date_gmt":"2026-11-13T04:36:03","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-simulated-annealing-accepts-an-uphill-move\/"},"modified":"2026-11-13T21:53:48","modified_gmt":"2026-11-13T13:53:48","slug":"how-simulated-annealing-accepts-an-uphill-move","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-simulated-annealing-accepts-an-uphill-move\/","title":{"rendered":"How simulated annealing accepts an uphill move"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Simulated annealing<\/strong> searches a rough cost surface by proposing a neighbor of the current state and accepting it when the cost falls. When the cost rises by \u0394, the move is accepted with probability <strong>e^{\u2212\u0394\/T}<\/strong>. The temperature T decreases on a schedule. High T accepts uphill moves and crosses barriers. Low T behaves like greedy local search. The method is a heuristic. A finite schedule does not promise the global minimum.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Greedy local search stops at the first local minimum. A cost surface with barriers needs a way back out. The Metropolis rule accepts a worse move with a probability that depends on how much worse it is and on the temperature. Slow cooling is the analogy with physical annealing, where a crystal reaches a low-energy state if cooled slowly enough.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The theory that an infinitely slow logarithmic schedule reaches the global minimum is real and useless as a clock. Practical schedules are geometric, T \u2190 \u03b1T with \u03b1 close to 1, and they are heuristics. The algorithm&#8217;s value is the uphill probability, not a certificate.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Each fixed temperature is a Metropolis chain on the state graph. If every state is reachable and the chain is run long enough, its stationary distribution prefers low costs, with the preference sharpening as T falls. A practical run uses a finite number of proposals per temperature and a geometric schedule, and it returns the best state seen, not a certified optimum. Extra memory is the current state and the best state.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The proposal distribution is part of the algorithm. A proposal that never changes a critical coordinate cannot repair it. The acceptance test uses the cost difference of that proposal, not a global ranking.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Start at a feasible state and a high temperature. Record the best state seen.<\/li>\n<li>Propose a neighbor. If its cost is lower, accept it. If its cost is higher by \u0394, accept it with probability e^{\u2212\u0394\/T}.<\/li>\n<li>Repeat a budget of proposals at this temperature, always updating the best-so-far when a new low cost appears.<\/li>\n<li>Cool, typically by multiplying T by a factor slightly below 1. Stop when T is tiny or the best cost has stalled.<\/li>\n<li>Return the best state seen, which may not be the final state. The chain at low T can sit above the best earlier discovery.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">A finite geometric schedule is a heuristic. The logarithmic schedule&#8217;s convergence theorem is not a description of that geometric schedule. Greedy search is the T = 0 limit. Metropolis-Hastings is the Markov-chain theory behind the acceptance rule, used in sampling as well as in optimization.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when an uphill move is never accepted<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Accept only improvements<\/td>\n<td>The temperature never acts. The search is greedy local search and stops in the first basin.<\/td>\n<\/tr>\n<tr>\n<td>Cool so fast that T is tiny before the state has moved<\/td>\n<td>The chain has not mixed at high temperature. Later uphill moves are rejected and the start is frozen in place.<\/td>\n<\/tr>\n<tr>\n<td>Return the final state rather than the best seen<\/td>\n<td>The last state is a sample from a cold chain, not a record of the lowest cost the run encountered.<\/td>\n<\/tr>\n<tr>\n<td>Cite the logarithmic-schedule theorem for a geometric schedule<\/td>\n<td>The theorem&#8217;s cooling is far slower than any geometric schedule used in practice. The practical run is a heuristic.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">Sampling from a distribution, rather than hunting a minimum, is Metropolis-Hastings with a fixed temperature. Greedy improvement is local search. Simulated annealing is the cooling Metropolis search.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment accepts an uphill move with probability e^{\u2212\u0394\/T} and cools the temperature. The state is a permutation and the cost is the length of a tiny tour. It prints the best length seen, <code>4<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import math, random\ncities = [(0, 0), (1, 0), (1, 1), (0, 1)]\n\ndef length(order):\n    total = 0\n    for a, b in zip(order, order[1:] + order[:1]):\n        dx = cities[a][0] - cities[b][0]\n        dy = cities[a][1] - cities[b][1]\n        total += abs(dx) + abs(dy)\n    return total\n\nrng = random.Random(0)\nstate = [0, 1, 2, 3]\ncur = best = length(state)\ntemp = 2.0\nfor _ in range(200):\n    i, j = sorted(rng.sample(range(4), 2))\n    trial = state[:]\n    trial[i:j + 1] = reversed(trial[i:j + 1])\n    nxt = length(trial)\n    if nxt &lt;= cur or rng.random() &lt; math.exp(-(nxt - cur) \/ temp):\n        state, cur = trial, nxt\n        best = min(best, cur)\n    temp *= 0.97\nassert best == 4\nprint(best)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\"><strong>TimberWolf<\/strong> and later chip placers used simulated annealing for VLSI placement, and the same cooling loop is a traveling-salesman heuristic. The temperature is what allows an uphill move. A pure greedy placement freezes into the first local minimum.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop annealing when the landscape is convex or a local move already has a proof. Use the exact method. Keep annealing as a heuristic on a combinatorial landscape full of local minima, and return the best state seen.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for simulated annealing returns the Metropolis acceptance probability and the warning that a practical schedule is a heuristic. <strong>Simulated annealing accepts an uphill move of size \u0394 with probability e to the minus \u0394 over T, and a finite cooling schedule is a heuristic rather than a global-minimum proof.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: Simulated annealing searches a rough cost surface by proposing a neighbor of the current state and accepting it when the cost falls. When the cost rises by \u0394, the move is accepted with probability e^{\u2212\u0394\/T}. The temperature T decreases on a schedule. High T accepts uphill moves&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,54],"tags":[],"class_list":["post-255","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-optimization"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"predecessor-version":[{"id":654,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/255\/revisions\/654"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}