liveBook · Manning

Genetic algorithm

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

A genetic algorithm is an evolutionary optimization method that encodes candidate traits as genes and applies selection and recombination to search for solutions.

A genetic algorithm (GA) is an evolutionary search method that represents each candidate solution as an individual with genes collected in a chromosome. A fitness function scores candidates, and repeated reproduction favors traits that better solve the target problem. section 1.1.1 section 2.5.2 section 2.6

Rather than updating one solution through gradients, a GA evolves a population. It begins with randomly initialized individuals, evaluates fitness, selects parents, recombines their genes through crossover, mutates offspring, and repeats until a generation limit or fitness target is reached. Population-wide fitness, not only the best individual, helps reveal whether evolution is progressing. section 2.5.8 section 2.6

Figure 2.12 The GA process

Follow the complete generation loop from random initialization through fitness evaluation, crossover, mutation, and stopping criteria. section 2.5.8

Design a GA around four choices:

  • Encode the problem as genes. A gene can be a Boolean, number, character, color, or a structured group of values; the chromosome holds the full candidate. section 2.5.2 section 3.5
  • Define fitness to measure the problem objective. Fitness may reward desirable behavior or minimize error, distance, or validation loss. section 2.6 section 3.3.1 section 8.4
  • Choose evolutionary pressure with population size, generations, selection, crossover rate, and mutation rate. Higher mutation increases variety but can prevent optimum performance; lower mutation favors specialization. section 2.5.9 section 2.6
  • Inspect results across generations with population statistics such as minimum, maximum, mean, and standard deviation fitness, then adjust encoding or operators experimentally. section 2.5.8 section 2.5.9

One Max: evolving binary strings

A deliberately simple implementation stores each individual as a row of binary genes and uses the row sum as fitness. Elite parents crossover at a chosen rate, offspring mutate, and repeated generations are plotted as fitness histograms. After 100 generations, the reported population reached maximum fitness 98, minimum 88, and mean 93.21. section 2.5.8

Route search with DEAP

For the traveling salesperson problem, an individual is a permutation of destination indexes. The fitness function sums route distance, while a DEAP population of 300 evolves with crossover probability 0.7, mutation probability 0.3, and up to 200 generations; a Hall of Fame retains the best route. section 3.3.1

GA representations can scale from simple arrays to structured designs. Polygon attributes can encode a drawing for image approximation; tokens can encode convolution, upsampling, batch-normalization, and dropout layers for autoencoder architecture search. GAs can also replace backpropagation by mapping an individual gene sequence directly onto a neural network’s weight tensors. section 3.5 section 8.2.1 section 6.2

Practical uses include pruning oversized deep-learning networks, tuning hyperparameters, optimizing network architectures, and balancing DCGAN training. These searches can be expensive: evolving image-like outputs may require substantial time, and autoencoder demonstrations reduce training data only to make evolution faster rather than to produce an optimized model. section 1.5.2 section 1.5.3 section 8.4 section 9.5

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Walks through encoding, fitness, selection, crossover, mutation, stopping criteria, Python simulation, DEAP implementations, and structured neural-network genomes.
Examples
Uses binary One Max populations, traveling salesperson routes, polygon image rendering, MLP weight search, autoencoders, and DCGANs.
What it assumes
Teaches genetic relationships and meiosis at a high level, while assuming enough Python and model knowledge to run notebook implementations.
What you can do after
Apply it via DEAP to encode candidates, configure operators, evaluate fitness, and evolve solutions for search and deep-learning optimization tasks.
How it connects
Connects evolutionary computation, natural selection, fitness functions, meiosis, hyperparameter optimization, neuroevolution, autoencoders, and GANs.

Also explained in

Compare how 7 books explain genetic algorithm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.