liveBook · Manning

Pheromone

As explained in Grokking AI Algorithms, Second Edition

Pheromone intensity is the numerical strength of a simulated pheromone signal associated with a path in ant colony optimization.

A pheromone is a signal ants leave as they travel. Other ants sense it and may follow the same path. In ant colony optimization (ACO), a pheromone trail is a number representing that signal’s strength on a possible path. It gives one ant a way to benefit from routes explored by others. section 6.1 section 6.5

Imagine ants choosing between two bridges to food. An ant can complete more trips on the shorter bridge, laying down pheromone more often. Its stronger trail attracts more ants, which reinforce it again. ACO uses this feedback to search for good routes, rather than requiring one ant to know the best route in advance. section 6.1

Pheromone intensity changes throughout an ACO run:

  • Start every available trail at the same value, such as 1, so no path has an initial advantage. Store intensities in a matrix indexed by the two destinations. section 6.5
  • When an ant chooses its next unvisited destination, combine trail intensity with a heuristic such as distance. Stronger trails and shorter paths receive larger shares of a probability-based choice; a less-favored path can still be explored. section 6.7
  • After tours finish, reduce existing intensities through evaporation and reinforce trails used by ants. Better tours have greater influence. Evaporation prevents early choices from retaining their influence indefinitely. section 6.8

Choosing a carnival attraction

From the circus, the carousel is 4 meters away and has trail intensity 8; the balloons are 8 meters away and have intensity 2. Both the shorter distance and stronger trail favor the carousel. A probability-based selection makes that visit more likely, not guaranteed. section 6.3 section 6.7

pheromone_trails = [
   [1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1]
]

This Python matrix shows equal initial pheromone intensities. Each row and column identifies a pair of attractions; later tours change the values. section 6.5

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Works through equal initialization, probability-based selection, evaporation, and tour-based reinforcement with Python snippets, without pursuing a theoretical proof.
Examples
Uses a short-versus-long bridge, a carnival attraction matrix, and Python trail initialization to make changing path strengths concrete.
What it assumes
Introduces trail matrices and simulated-ant state while using Python lists and classes without teaching Python syntax.
What you can do after
Build it from scratch by initializing trail intensities, using them in next-visit choices, and updating them after tours.
How it connects
Connects ant colony optimization to swarm intelligence, heuristic search, roulette-wheel selection, and exploration versus exploitation.

Also explained in

Compare how 2 books explain pheromone →

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.