liveBook · Manning

Stopping criterion

As explained in Grokking AI Algorithms, Second Edition

A stopping condition is a rule that determines when an iterative algorithm terminates.

A stopping criterion is the rule that tells an iterative algorithm when to finish and return its best solution. Without one, a search could keep running indefinitely. Choosing the rule is like deciding how long to keep looking: more attempts may help, but they also cost time. section 4.19 section 7.9

Three useful rules answer different questions:

  • Fixed limit: Stop after a chosen number of generations or iterations. This makes the amount of searching predictable. section 4.19 section 6.10
  • Target fitness: Stop when a solution reaches a known minimum fitness, even if the solution itself was not known beforehand. section 4.19
  • Stagnation: Compare the best solution across iterations and stop after too little improvement. A plateau is a reason to consider stopping, not proof that no better solution exists. section 4.19 section 6.10

Counting tours, then checking progress

In ant colony optimization, one iteration is a complete tour by every ant. Set the limit to 10 iterations, and each ant makes 10 tours before the search ends. Alternatively, track the best fitness after each iteration: if it is 100 at iteration 20 and remains 100 through iteration 30, a stagnation rule could stop the search. That plateau does not guarantee the best possible solution has been found. section 6.10 section 6.4

Place the check in the search loop, then return the best solution found when it is met. In particle swarm optimization, stopping ends position updates and returns the swarm’s best position. Give a search enough time to explore, but weigh extra iterations against computation time. If progress stalls, stopping is one option; adjusting parameters to encourage more exploration is another. section 7.5 section 7.9 section 4.20

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Details fixed limits, target fitness, and stagnation, but shows a fixed-iteration loop rather than an adaptive-stop implementation.
Examples
Uses repeated ant tours, a fitness-100 plateau from iterations 20 to 30, and Python iteration loops.
What it assumes
Builds on iterations and fitness comparisons while defining stagnation as little or no improvement in the best solution.
What you can do after
Operate/configure it: Choose a limit or fitness-based rule while weighing solution quality against computation time.
How it connects
Links fitness, stagnation, exploration, and exploitation to stopping decisions in evolutionary algorithms and swarm intelligence.

Also explained in

Compare how 11 books explain stopping criterion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.