liveBook · Manning

Fitness

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

A fitness function maps an individual or candidate solution to a numerical value representing its closeness to a target or performance in an optimization problem.

Fitness is the numerical score assigned to an individual candidate to express how well it survives, performs, or solves the target problem. In evolutionary computation, this score is the basis for judging a population's success and deciding which individuals are preferable for reproduction. section 1.1.1 section 2.6

A fitness function turns the goal into a calculation. It may maximize a desirable quantity, minimize a cost, or transform a measured result so that the evolutionary setup can rank candidates consistently. The choice of direction matters: a genetic algorithm can maximize the count of desired genes, while another setup minimizes path distance or uses inverse accuracy as fitness. section 2.5.4 section 3.3.1 section 7.5

A practical evaluation loop has three parts:

  • Represent each candidate with the traits, genes, path indices, network architecture, or program that evolution will vary. section 2.4.1 section 3.3.1
  • Evaluate the candidate against a concrete target and return its numerical fitness. section 2.6 section 10.2
  • Use the resulting scores during selection, then reevaluate offspring after crossover and mutation. section 2.4.1 section 2.6

Max-one fitness

For a binary chromosome, fitness can be the sum of its genes. Maximizing that sum drives the population toward an individual whose genes are all 1. With 100 binary genes, the ideal score is 100; a histogram of initial scores makes the randomized population visible before evolution proceeds. section 2.5.4

Fitness can combine task-specific measurements

A route evaluator sums the distances along a closed path, making total path length the score. A DCGAN evaluator derives partial values from real, generated, and fake losses, then averages them. For an evolved CNN, accuracy is clamped and inverted so lower fitness corresponds to better accuracy. section 3.3.1 section 9.5 section 7.5

Listing 2.15 EDL_2_5_Genetic_Algorithms.ipynb: Calculating fitness
fitness = np.sum(pop,axis=1)    #1
plt.hist(fitness)

This compact NumPy calculation shows a fitness function directly: sum each population row to score every binary individual, then plot the score distribution. section 2.5.4

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

How deep it goes
Works through several executable fitness calculations, from gene sums to network accuracy and combined GAN losses, without formal derivations.
Examples
Uses binary max-one chromosomes, cell traits, traveling-salesperson routes, XOR networks, evolved CNNs, DCGANs, and food-seeking ants.
What it assumes
Builds from simple simulated traits and binary genes while using Python and NumPy implementations.
What you can do after
Apply it via NumPy, DEAP, and NEAT-Python evaluation functions to score candidates for evolutionary search.
How it connects
Connects fitness to selection, crossover, mutation, evaluation, genetic algorithms, NEAT, convolutional neural networks, and DCGANs.

Also explained in

Compare how 6 books explain fitness →

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.