Genetic algorithm basics
Basic principles of genetic algorithms: representation, population, selection, crossover, mutation, schema theorem and how they combine to search for optima.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Genetic algorithms (GAs) are a class of optimisation and search methods inspired by natural evolution. An engineer uses them when the search space is large, multimodal or poorly understood (for example, tuning weights in hybrid soft-computing systems or combinatorial design problems) because GAs can find good solutions without gradients or convexity.
Key ideas
Population — a multiset of N chromosomes evaluated in one generation. Replacement strategies: generational replacement (replace all N) or steady-state replacement (replace a few at a time); elitism copies the top e individuals unchanged to the next generation to preserve the best-so-far solution.
Fitness — a non-negative scalar measure f(x) of how good a chromosome x is for the given optimisation objective. The algorithm uses fitness for selection. If objective is to minimise, convert to a fitness proportional to inverse or use rank-based fitness. For roulette-wheel methods ensure non-negative fitness; when using inverse transformations add a positive shift to avoid division by zero, e.g., f(x) = 1/(1 + objective(x)).
Selection — the process that picks parents for reproduction. Proportionate (roulette-wheel) selection assigns selection probability p_i = f_i / Σ_j f_j. Tournament selection picks k random individuals and chooses the best among them; repeated to form mating pool. Tournament size k controls selection pressure (larger k increases pressure; typical k = 2..5). Stochastic universal sampling (SUS) can be used with proportionate selection to reduce sampling variance.
Crossover (recombination) — operator that takes two parent chromosomes and exchanges parts to create offspring. For single-point crossover, choose a crossover point c uniformly from {1,..,l-1} and swap bits right of c. Parameter pc is crossover probability per chosen pair.
Mutation — small random changes applied to offspring; for binary chromosomes flip each bit with probability pm independently (bitwise mutation). Typical rule-of-thumb: pm ≈ 1/l (one bit flip per chromosome on average).
Schema (plural schemata) — a pattern over positions using fixed symbols (0 or 1) and wildcards
*. Example H = 1*0**1 on length l=6. Define:- order o(H): number of fixed positions in H (number of 0/1 symbols).
- defining length δ(H): distance between the leftmost and rightmost fixed positions (index difference).
A schema represents a family of chromosomes that match the fixed positions.
Population dynamics under selection: if m(H,t) is the number of chromosomes matching schema H at generation t, and f(H) is the average fitness of those members, then under proportionate selection (before crossover and mutation): the expected number of copies after selection is E[m(H,t+1)] = m(H,t) · f(H) / f̄, where f̄ is the average fitness of the whole population. (This assumes sampling with replacement and selection based only on fitness.)
Schema theorem (Holland) — gives a lower bound on the expected number of copies of schema H after one generation when selection, single-point crossover (probability pc) and bitwise mutation (probability pm per bit) are applied. Under assumptions: fixed-length binary strings, proportionate selection, single-point crossover uniformly random, independent bitwise mutation, the theorem (lower bound form) is:
E[m(H,t+1)] ≥ m(H,t) · (f(H)/f̄) · (1 - pc · (δ(H)/(l-1))) · (1 - pm)^{o(H)}.
For small pm this is often approximated by replacing (1 - pm)^{o(H)} with 1 - o(H)·pm.
Assumptions and limits: this is a lower bound (not exact), it applies per-generation expectation and assumes no linkage exceptions, and it uses a simple model of crossover destruction. It does not prove convergence to global optimum. Related idea: the building-block hypothesis suggests that GAs combine short, low-order, above-average schemata (“building blocks”) to construct better solutions over generations.
Termination — stop when a fixed number of generations reached, fitness threshold reached, or population converges (no change) or computational budget exhausted.
Diagram(s) to draw (exam):
- Flowchart of GA: draw boxes labelled "Initialise population (N)" → "Evaluate fitness" → "Selection (mating pool)" → "Crossover (pc)" → "Mutation (pm)" → "Form new population (replacement)" → arrow back to Evaluate fitness. Label decisions like pc and pm, and where generation count t increments.
- Single-point crossover illustration: draw two parent bitstrings length l, mark a crossover point c between positions c and c+1, and show children produced after swapping right segments. Label indices 1..l and show defining length δ(H) between fixed bits of a schema.
Formulas
p_i = f_i / Σ_j f_j — p_i is selection probability of individual i (dimensionless). Applies for proportionate selection.
E[copies of individual i after selection] = N · p_i — expected number of copies in a population of size N (dimensionless). Assumes sampling N draws with replacement.
E[m(H,t+1)] = m(H,t) · (f(H) / f̄) — expected number of members of schema H after pure proportionate selection (dimensionless). f(H) is average fitness of H-members, f̄ is population average fitness.
Survival probability to single-point crossover ≈ 1 - pc · (δ(H) / (l - 1)) — probability schema H is not cut by crossover (dimensionless). Assumes uniform crossover point.
Survival probability to mutation = (1 - pm)^{o(H)} ≈ 1 - o(H)·pm (for small pm) — probability none of the fixed bits are mutated (dimensionless). pm is per-bit mutation probability.
Schema theorem (lower bound): E[m(H,t+1)] ≥ m(H,t) · (f(H)/f̄) · (1 - pc · (δ(H)/(l-1))) · (1 - pm)^{o(H)} — lower bound on expected number of instances of schema H after one generation.
pm (recommended) ≈ 1 / l — rule of thumb: mutation probability about inverse of chromosome length. (Verify per-problem tuning needed.)
Typical parameter ranges used in practice: pc ≈ 0.6..0.9, pm ≈ 1/l (dimensionless). These are heuristics. Population size N is often 20–200+ (problem-dependent); elitism rate e/N ≈ 1–5%; tournament size k ≈ 2–5.
Worked examples
- Numerical example: expected copies of a schema after selection, crossover and mutation.
Data (binary chromosomes length l = 6, population N = 4):
- Chromosome A = 110011, fitness f_A = 15
- Chromosome B = 101100, fitness f_B = 10
- Chromosome C = 000111, fitness f_C = 4
- Chromosome D = 111000, fitness f_D = 8
Let schema H be defined by positions {1,3}: H = 1 * 0 * * * (position 1 = 1, position 3 = 0). Then m(H,t) = 1 (only A matches). f(H) = 15. Population average f̄ = (15+10+4+8)/4 = 37/4 = 9.25.
Step 1 — selection only: Formula: E[m(H,t+1)] = m(H,t)·(f(H)/f̄) Compute: E[m(H,t+1)] = 1 · (15 / 9.25) = 1.621621...
Step 2 — include crossover and mutation. Use pc = 0.7, pm = 1/l = 1/6 ≈ 0.1666667. Order o(H) = 2 (two fixed bits). Defining length δ(H) = 3 - 1 = 2 (distance between fixed positions). l - 1 = 5.
Survival due to crossover ≈ 1 - pc · (δ/(l-1)) = 1 - 0.7 · (2/5) = 1 - 0.28 = 0.72. Survival due to mutation = (1 - pm)^{o(H)} = (1 - 1/6)^2 = (5/6)^2 = 25/36 ≈ 0.694444.
Apply schema theorem lower bound: E[m(H,t+1)] ≥ 1.621621 · 0.72 · 0.694444 = 0.811 (rounded)
Final answer: Expected number of copies after one generation ≥ 0.811.
- Schema theorem derivation (model answer for theory question):
- Step A (selection): Under proportionate selection, each instance of H has expected reproductive success multiplied by its fitness relative to population. So expected copies after selection = m(H,t)·f(H)/f̄.
- Step B (crossover): A schema H is destroyed by single-point crossover only if the cut point falls between the leftmost and rightmost fixed bits. There are (l-1) possible cut points; δ(H) of them cut H. If crossover occurs with probability pc, probability of destruction by crossover ≈ pc·(δ(H)/(l-1)). So survival prob ≈ 1 - pc·(δ(H)/(l-1)).
- Step C (mutation): To survive mutation, none of o(H) fixed bits must flip. Probability = (1 - pm)^{o(H)}.
- Multiplying selection expectation by survival probabilities yields the inequality given in the Formulas section. This is a lower bound because we used pessimistic destruction probabilities and independence assumptions.
Common mistakes
- Confusing average fitness f̄ (population mean) with f(H) (mean for members of a schema).
- Treating the schema theorem as a proof of convergence to the global optimum — it is only a statement about short-term expected growth of low-order, short defining-length schemata.
- Using (1 - pm)^{o} ≈ 1 - o·pm without stating small-pm assumption.
- Drawing crossover diagrams without labelling indices 1..l, showing cut between positions; neglecting elitism and losing the current best solution; using too large a tournament size (excessive selection pressure) causing premature convergence.
For your exam
Typical question types:
- Definitions and short notes: define chromosome, schema, order, defining length, selection methods.
- Derivations: derive the schema theorem lower bound step-by-step and state assumptions.
- Numericals: compute selection probabilities, expected copies after selection, apply crossover and mutation survival probabilities with given pc and pm.
- Diagrams: draw GA flowchart and single-point crossover illustration and label schema positions, δ(H), o(H).
What full-marks answers include:
- Clear definitions of all terms used (bold them if allowed), explicit assumptions, correct formulas with symbols defined, stepwise algebra in derivations, correct numeric arithmetic with units (dimensionless here) and a concluding bold final numerical answer.
Reviewer note about uncertainty: I have followed the classical (Holland) schema theorem formula. I am reasonably confident about the form of the lower-bound inequality and the assumptions stated. I am less certain about the exact conventional phrasing of the crossover-destruction term (some texts use (l-1) in denominator; others phrase it with uniform cut-points); please verify that the version used here matches the course syllabus.
Quick check
- What is the defining length δ(H) of schema H = 1 * 0 * 1 on a string of length 6?
- Give the formula for selection probability under proportionate selection.
- If pm = 0.01 and a schema has order o(H) = 3, what is the survival probability under mutation (exact, not approximated)?
Answers: δ(H) = 4 (distance between leftmost fixed at pos1 and rightmost fixed at pos5); p_i = f_i / Σ_j f_j; survival = (1 - 0.01)^3 = 0.970299.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?