Sub topic 16
Nature-inspired algorithms
This chapter assumes you have read the earlier chapters on the three levels of mimicry (form, process, system) and on abstracting function from an organism. It also assumes you can read short Python snippets. Nothing here needs advanced mathematics.
Biomimicry without a physical product
Most of this tutorial has dealt with material things: fasteners, surfaces, trains and buildings. Nature also solves problems of search, routing and learning, and those strategies can be copied into software. This is computational biomimicry. The "organism" is a process, such as evolution by selection or foraging by an ant colony. What gets copied is the logic of that process.
In the three-level scheme, these algorithms usually mimic process or system. A genetic algorithm copies the process of variation and selection. An ant colony method copies a system, in which many simple agents coordinate through marks left in a shared environment. Almost none of them copy form.
Function first, as in physical cases
The same abstraction step applies here. You state the function without naming the organism, then look for strategies that perform it.
| Biological source | Mechanism in nature | Abstracted function | Algorithm family |
|---|---|---|---|
| Evolution by natural selection | Variation, inheritance, differential survival | Improve candidate solutions over many rounds without a gradient | Genetic and evolutionary algorithms |
| Ant foraging | Pheromone trails that evaporate and are reinforced | Find short paths through a network using shared, decaying memory | Ant colony optimization |
| Bird flocks and fish schools | Each individual follows its own best position and its neighbours | Explore a space with a population that shares information | Particle swarm optimization |
| Brain tissue | Weighted connections strengthened by experience | Learn a mapping from examples | Artificial neural networks |
The first column is the organism, and the third is what you would search by. If your challenge is "find a short route through a changing network," ant foraging is a candidate even though your problem has no ants in it.
A worked example: a genetic algorithm
The abstracted function is "improve candidate solutions through repeated variation and selection." A candidate is a list of bits. Fitness is the number of 1s, so the best possible solution is all 1s. This toy problem is called OneMax. It is easy on purpose, so you can see the mechanism.
import random
random.seed(1)
LENGTH = 40
def fitness(bits):
return sum(bits)
def mutate(bits, rate=0.02):
return [1 - b if random.random() < rate else b for b in bits]
def crossover(a, b):
point = random.randrange(1, len(a))
return a[:point] + b[point:]
def select(population):
a, b = random.sample(population, 2) # tournament of two
return a if fitness(a) >= fitness(b) else b
def evolve(pop_size=30, generations=60):
population = [[random.randint(0, 1) for _ in range(LENGTH)]
for _ in range(pop_size)]
for gen in range(generations):
best = max(population, key=fitness)
if gen % 10 == 0:
print("generation", gen, "best fitness", fitness(best))
children = [mutate(crossover(select(population), select(population)))
for _ in range(pop_size - 1)]
population = [best] + children # keep the best one unchanged
return max(population, key=fitness)
winner = evolve()
print("final best fitness", fitness(winner), "out of", LENGTH)Each biological idea maps to one function:
- Variation comes from
mutate(random changes) andcrossover(recombining two parents). - Selection comes from
select, where fitter candidates are more likely to become parents. - Inheritance is the fact that children are built from parent data.
- Elitism, keeping the best candidate unchanged, has no strict equivalent in nature. It is an engineering addition that stops progress from being lost by chance.
That last point matters. The algorithm is not a faithful copy of evolution. It keeps the functional core and adds whatever makes it work on the task.
Where the biology stops and the tuning starts
The biological source gives you an idea. Real performance depends on parameters the biology does not supply:
- Population size. Too small and the population loses diversity and gets stuck. Too large and each generation is slow.
- Mutation rate. Too low and the search stalls. Too high and it becomes random guessing.
- Selection pressure. Strong selection converges fast but may lock onto a mediocre solution, called a local optimum.
- Evaluation cost. If scoring one candidate takes an hour of simulation, 30 candidates for 60 generations is already 1,800 hours.
You should treat these like any other engineering parameters. Test them on your own problem rather than assuming nature's values apply.
Limits and criticism
Nature-inspired algorithms attract a specific criticism. Researchers have published many "new" methods named after animals or natural events, such as various insects, birds and mammals. Reviews of this literature have found that many differ little from older methods once the metaphor is stripped away. They are often compared against weak baselines, and the nature story is used as a selling point instead of evidence.
Two ideas help you judge such claims.
- No free lunch. Averaged over all possible problems, no search method beats any other. An algorithm only wins when its assumptions match the structure of your problem. A biological origin does not guarantee a good match.
- A mathematical description is needed. A method should be defined by its update rules, not by its story. If you cannot state what it does without mentioning the animal, be cautious.
Compare this with the physical case studies. The lotus effect can be checked with measured contact angles and the Cassie-Baxter relation. An algorithm should likewise be checked against measured results on stated benchmarks, including simple non-biological baselines such as random search or gradient-based methods.
A checklist for choosing
- Write the problem as a function, such as "find the best configuration under a score" or "find a short path."
- Ask whether the score is smooth and cheap to compute. If so, try conventional methods first.
- If the score is noisy, discontinuous or only available through a simulation, consider an evolutionary or swarm method.
- Compare against a plain baseline on the same problem and the same evaluation budget.
- Report the result without relying on the biological story.
Exercise
In the genetic algorithm above, set the mutation rate in mutate to 0.5 and run it again. Predict what happens to the best fitness over the generations, and name the biological idea that breaks down.
Show answer
Progress stalls or becomes erratic. With a 50 percent chance to flip each bit, a child is almost a random string, so it keeps none of its parents' useful structure. Inheritance, the idea that offspring resemble parents, no longer holds, and the search turns into random guessing. Only elitism keeps the best earlier candidate, so the best fitness stays near its early value instead of climbing toward 40.
Exercise
A paper presents an algorithm based on the hunting behaviour of a rarely studied animal and reports that it beats three other nature-inspired algorithms. Give two checks you would make before trusting the result.
Show answer
First, check whether it was compared with strong, standard baselines, such as random search, a gradient method or a well-tuned genetic algorithm, under the same evaluation budget. Second, check whether the update rules can be written down without the animal metaphor and whether they differ in substance from an existing method. Also confirm that the benchmark problems resemble your own, since no free lunch means a win on one set says little about another.