Skip to content
Kudos AI
Lire en français
Search and Games

The Fix That Changed the Success Rate Far More Than the Cost

Allowing sideways moves takes hill climbing on 8 queens from 14.75% of runs solved to 94.55%, which reads like a six-fold improvement and is not one: with random restarts the expected cost of a solution goes from 21.9 steps to 23.1, and counted in moves evaluated it falls by 16%, from 1,547 to 1,298. Simulated annealing solves 98.8% and costs 1,622 evaluations. What changed was mostly the statistic, not the work.

5 min readKudos AI

Prerequisites: Classical Search: From Breadth-First to A*

A board improving one queen at a time until no move helps, then the same climb allowed to move across a plateau, and a third run accepting a worse board at a temperature that falls.

Eight queens, one per column, and a state is the eight rows they sit on. The cost of a state is the number of attacking pairs. Steepest-ascent hill climbing looks at all 8×7=568 \times 7 = 56 single-queen moves, takes the best one (a random one of the best, on a tie), and stops when nothing is better.

From 2,000 random starts it solves 14.75% of them, 295 runs, in 4.1 steps when it wins and 3.1 steps before it gets stuck.

A. The standard fix

It gets stuck because the landscape has plateaus: whole regions where every available move leaves the cost exactly where it is. The usual remedy is to allow sideways moves, up to some limit, on the theory that a plateau might be a shoulder with more descent on the other side.

Allow a hundred consecutive sideways moves and the same 2,000 starts give

94.55% solved,19.5 steps on success,63.6 on failure.94.55\% \text{ solved}, \qquad 19.5 \text{ steps on success}, \qquad 63.6 \text{ on failure}.

A success rate that goes from 14.75% to 94.55% is the kind of number a change gets adopted on.

B. What it costs to actually get an answer

Hill climbing is cheap and restartable, so nobody runs it once. The quantity that matters is the expected work until a solution appears:

E[steps]=1−pp E[steps∣fail]+E[steps∣succeed].\mathbb{E}[\text{steps}] = \frac{1 - p}{p}\,\mathbb{E}[\text{steps} \mid \text{fail}] + \mathbb{E}[\text{steps} \mid \text{succeed}].
Variantsolvedsteps on successon failureexpected total
no sideways moves14.75%4.073.0821.9
up to 100 sideways94.55%19.4663.5623.1
simulated annealing98.8%1780.186000.001853.1

The inputs are printed to two decimals because the formula needs them: from these columns it reproduces every total to the digit shown, and from the same inputs rounded to one decimal the second row would come out as 23.2.

The plain version fails about six times out of seven, but it fails in 3.1 steps and costs 21.9 steps overall. The improved version succeeds almost always, takes 19.5 steps to do it, and costs 23.1 overall. Counted in steps, the six-fold rise in success rate is worth, on this problem, slightly less than nothing.

It is not that sideways moves do not work. They do exactly what they claim: they carry the search across plateaus. It is that the failures they eliminated were cheap, and the successes they created are expensive, and those two facts nearly cancel. How nearly depends on what a step is, which is the next section.

Interactive: the success rate against the cost of a solution

Eight queens, steepest ascent, restarted until it solves.

expected steps to a solutionno sideways moves21.9up to 0 sideways21.9failed runs before the winthe winning run
Runs solved
14.75%
Steps when it solves
4.1
Steps when it sticks
3.1
Expected steps, with restarts
21.9
Failed runs per solution
5.78
Moves evaluated per solution
1,547

Plain steepest ascent solves 14.75% of 2000 starts, in 4.1 steps when it wins and 3.1 before it sticks. It fails 5.78 times for every solution, but each failure is cheap, and a solution costs 21.9 steps in all. Now allow sideways moves. Each run starts from its own random board, drawn from a copy of Python’s generator seeded as the article’s script seeds it; at the default 2,000 starts these are the article’s own runs, and a smaller count uses the first 2000 of them.

C. Comparing across different kinds of step

Simulated annealing looks far worse in that table, and the comparison is not fair as it stands. A hill-climbing step evaluates all 56 successors before moving; an annealing step evaluates at most one. So count the work, the successor costs actually computed, rather than the iterations. Two things the step count leaves out matter here. Every hill-climbing run that fails scans all 56 moves one last time, to find that none is good enough, and takes no step for it. And one annealing draw in eight lands on the queen's own row and evaluates nothing. Counting both, the expected work per solution is:

  • hill climbing, no sideways: 1,5471{,}547 evaluations
  • hill climbing, sideways: 1,2981{,}298
  • annealing: 1,6221{,}622

Multiplying the step totals by 56 would give 1,2241{,}224 and 1,2951{,}295 and miss the final scans. Those cost the plain version 5.78×56≈3245.78 \times 56 \approx 324 evaluations per solution, because it fails 5.78 times for every success, and cost the sideways version about 3. That one uncounted scan reverses the order: measured in evaluations, sideways moves make a solution 16% cheaper, where the step count said 6% dearer.

All three now sit within a factor of 1.25 of each other. Annealing buys the highest single-run success rate, 98.8%, at the highest cost of the three, though not by much once the same thing is counted on both sides.

That is the second half of the lesson. The table in section B counts steps, which are not the same unit on every row; this list counts evaluations, which are. They support different conclusions: a fix worth slightly less than nothing, or a fix worth 16%. Neither is the six-fold improvement the success rate suggests.

D. What to take from it

  • A success rate per run is not a cost. For any restartable procedure the figure of merit is expected work to a solution, and a method that fails six times out of seven can cost only 19% more than one that fails once in eighteen.
  • Measure the failures, not just the successes, and all of each failure. The difference here lives in what it costs to find out that a run is not going to work: 3.1 steps against 63.6, plus the final scan that finds nothing, which is a quarter of the cost of a failed plain run.
  • Count operations, not iterations, when the iterations differ. A step is whatever the implementation says it is, and comparing steps across two algorithms with different step sizes compares nothing. Counting operations also catches the work that is not a step at all.
  • Report the baseline you improved on, under the same accounting. A change that improves the headline number six-fold and the total by 16% is worth knowing about before it is adopted, not after.

References & further reading

  • Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson (3rd edition), 2010· Kudos AI reference library

Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.

Related reading

5 min readProbabilistic Reasoning

The Week That Cannot Have Happened

Take the most likely state on each day and write them down in order, and you have a report the model assigns probability exactly zero: on a four-day machine-monitoring example the day-by-day answer is healthy, healthy, failed, failed, and healthy to failed is a transition that cannot occur. What the two questions actually are, why smoothing and Viterbi answer different ones, and what the 0.411 posterior on the best path means for anyone who has to act on it.

Artificial IntelligenceProbability
5 min readNeural Networks

The Slowest Direction Sets the Pace

The step size you are allowed is fixed by the steepest direction and the number of steps you need is fixed by the flattest, so the cost of gradient descent is their ratio. The same least-squares fit, to the same ten decimal places, takes 1742 steps in one basis, 147 in a rescaled one and exactly 1 in an orthonormal one, and momentum buys back the square root of the ratio rather than the ratio.

Machine LearningMathematics
5 min readReinforcement Learning

The Parameter Nobody Chooses

The living reward in a grid world is written down once and never discussed, and the optimal policy is a step function of it: eight thresholds between -3 and 0, each flipping exactly one square. The textbook value of -0.04 sits 0.0048 away from the one that decides whether the agent takes the shortcut past the pit, and above -0.0221, when steps are nearly free, the optimal move in one corner is to walk into a wall on purpose.

Artificial Intelligence
← Back to all articles