liveBook · Manning

DEAP

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

DEAP is a Python framework for rapid prototyping of evolutionary algorithms and other computational intelligence techniques.

DEAP (Distributed Evolutionary Algorithms in Python) is a Python framework for rapidly assembling evolutionary-computation solvers. Rather than hand-writing an evolutionary-computation framework, define individuals and fitness, register operators in a toolbox, and run an evolutionary loop. Its abstractions support genetic algorithms and other evolutionary methods. section 3.1 section 3.6

A typical setup has four parts: creator definitions specify fitness direction and individual representation; a toolbox registers gene, individual, population, evaluation, crossover, mutation, and selection functions; a hall of fame preserves top individuals; and statistics record population metrics. The representation and operators must fit the problem: bit sequences for One Max, destination-index permutations for traveling-salesman routes, or structured numeric sequences for image-rendering polygons. section 3.1.1 section 3.3.1 section 3.5

Listing 3.2 EDL_3_1_OneMax_DEAP.ipynb: The toolbox
toolbox = base.Toolbox()                                           #1
 
toolbox.register("attr_bool", random.randint, 0, 1)                #2
 
toolbox.register("individual",                                     #3
tools.initRepeat, creator.Individual, toolbox.attr_bool, n=100)
 
toolbox.register("population", tools.initRepeat, 
 list, toolbox.individual)                                       #4

The toolbox registration pattern separates problem representation from the operators that initialize and evolve it. section 3.1.1

Use DEAP by following an explicit experiment loop:

  • Install the package, create fitness and individual classes, then register initialization functions for genes, individuals, and populations. section 3.1.1
  • Register a problem-specific evaluation function plus compatible crossover, mutation, and selection operators. section 3.1.1 section 3.4
  • Run evolution with chosen population size, crossover and mutation probabilities, generations, statistics, and hall of fame. section 3.1.1
  • Change gene count, population size, and operator rates, then rerun to inspect their effects on the final solution. section 3.1.2

From One Max to design search

A 100-bit One Max solver demonstrates the basic creator/toolbox pattern with two-point crossover, bit-flip mutation, tournament selection, and a 300-member population. The same approach evolves a traveling-salesman route and can encode drawing polygons whose coordinates, color, and transparency are rendered and scored by mean squared error. section 3.1.1 section 3.3.1 section 3.5

Operator choice is a tuning decision, not a fixed recipe. Operators can often be swapped, although some require particular individual types; population diversity histograms and genealogy plots help inspect stagnation, crossover behavior, and selection effects. Evolution can also become costly when each fitness evaluation trains a model, so reduced datasets or caching discretized candidates may make demonstrations feasible while limiting optimization quality or exploration. section 3.4 section 8.4 section 9.5

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

How deep it goes
Walks through creator, toolbox, operators, evolution loops, metrics, and problem-specific encodings; defers broader operator details to documentation.
Examples
Uses One Max, traveling-salesman routes, EvoLisa polygon painting, autoencoder architecture evolution, and DCGAN optimization.
What it assumes
Builds from prior straight-Python genetic algorithms while using Python notebooks, pip installation, and custom evaluation functions.
What you can do after
Apply it via DEAP to configure individuals, operators, metrics, and evolutionary runs for varied optimization problems.
How it connects
Connects genetic algorithms with evolutionary computation, genetic programming, particle swarm optimization, hyperparameter optimization, autoencoders, and DCGANs.

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.