liveBook · Manning

Gene

As explained in Grokking AI Algorithms, Second Edition

A gene is an individual value or position within an evolutionary algorithm chromosome that contributes to the encoded candidate solution.

A gene is one logical unit of an evolutionary algorithm chromosome. Its allele is the value stored there, while the complete chromosome represents a candidate solution. section 4.4

Genes contribute to solutions in several practical ways:

  • Represent a yes/no choice with binary values: 0 can exclude an item and 1 can include it. section 4.4 section 4.5
  • Keep every chromosome the same length, with each gene index referring to a particular decision or item. section 4.4
  • Change during mutation: select a gene at random and flip its binary value to introduce variation. section 4.15
  • Affect fitness because the represented choices determine the candidate solution's value and whether it violates constraints. section 4.7

A gene in the Knapsack Problem

A chromosome for 26 available items contains 26 genes. At one index, 0 means the item is excluded and 1 means it is included. The fitness calculation reads each gene, adds the selected item's weight and value, and assigns zero fitness when the total weight exceeds the limit. section 4.5 section 4.7

Figure 4.23 Bit-string mutation
04_23

Use the mutation figure to visualize how changing one gene produces a nearby chromosome and introduces variation. section 4.15

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains gene structure, encoding, mutation, population creation, and fitness effects, while deferring nonbinary mechanisms to later treatment.
Examples
Uses binary Knapsack Problem chromosomes, a nine-gene word-selection exercise, mutation figures, and Python fitness and population code.
What it assumes
Assumes basic candidate-solution and optimization ideas while teaching chromosome, allele, genotype, phenotype, and fitness terminology directly.
What you can do after
Build it from scratch by encoding decisions as genes, generating chromosomes, mutating values, and calculating fitness.
How it connects
Connects genes to chromosomes, alleles, genotypes, phenotypes, populations, mutation, reproduction, and fitness functions.

Also explained in

Compare how 5 books explain gene →

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.