liveBook · Manning

Chromosome

As explained in Grokking AI Algorithms, Second Edition

A chromosome is an encoded representation of a candidate solution in an evolutionary algorithm, consisting of gene or solution-value components.

A chromosome is an encoded candidate solution in an evolutionary algorithm. It contains a fixed number of genes, each storing an allele, or actual gene value. A collection of chromosomes forms a population. The genotype is the encoded representation; the phenotype is the resulting real-world solution. section 4.4 section 5.22

Choose an encoding that matches the structure of the problem:

  • Use binary encoding when each decision is discrete, such as yes/no or included/excluded; represent each gene with 0 or 1. section 4.5
  • Use real-value or permutation encodings when precise decimal values or ordered sequences matter; binary encoding can make those solutions harder to find. section 4.5
  • Keep chromosomes valid during population initialization, using constraints, penalties, or a repair function to correct invalid solutions. section 4.6
  • Modify chromosomes through evolutionary operators: crossover combines parent parts, while mutation changes selected gene values. section 4.13 section 4.15

Knapsack encoding

For 26 available items, create a 26-character chromosome. Gene index 3 contains 1 when item 3 is included and 0 when it is excluded. The complete string therefore describes one possible knapsack, while the population contains many such candidate solutions. Solutions exceeding the weight limit must be penalized, repaired, or excluded. section 4.4 section 4.6

Figure 4.11 Binary-encoding the Knapsack Problem
04_11

Visualizes how a chromosome encodes item inclusion and exclusion for the Knapsack Problem. section 4.4

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines genes, alleles, genotypes, and phenotypes, then works through binary encoding, validity, crossover, and mutation; defers other encodings.
Examples
Uses binary Knapsack chromosomes, a nine-gene word-selection chromosome, two-point crossover, and bit-string mutation.
What you can do after
Build it from scratch by encoding solutions, generating valid populations, and applying crossover or mutation to chromosome genes.
How it connects
Connects chromosomes with genes, alleles, genotypes, phenotypes, populations, fitness functions, crossover, mutation, and encoding.

Also explained in

Compare how 5 books explain chromosome →

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.