ML 101
M13 · L03
Evolutionary Search

Designing a Fitness Function

The fitness function is not a detail of the implementation. It is the problem statement — and getting it wrong is the most common way a genetic algorithm fails.

01 / 13
ML 101
M13 · L03
One Number

All It Can See

The search cannot see your problem. It sees the single number fitness returns for each candidate, and selection multiplies whatever earns a high one. That is the whole mechanism.

Where This Comes From
Holland (1975) set out the framework in which selection acts on a population according to a measured payoff; Goldberg (1989) is the standard textbook treatment that follows it.
02 / 13
ML 101
M13 · L03
The Classic Mistake

Reward the Outcome

Evolving a sensor's duty cycle, it is tempting to reward "keeps the radio off" — you know the radio drains the battery. You will get exactly that: radio off, battery fine, no data delivered.

The Fix
Score useful readings delivered per charge. A fitness function encoding your assumed method can only rediscover your method.
03 / 13
ML 101
M13 · L03
Worked Example

Placing Sensors

  • 40 candidate positions over 200 grid cells; each has a coverage set and a cost
  • A candidate is a 40-bit string — bit i is 1 if position i is used
  • First fitness: cells covered. The winner selects almost everything
  • Nothing in that fitness mentions money, so the search never cared
04 / 13
ML 101
M13 · L03
Two Objectives

Weighted Sums

Collapse the objectives into one number with weights chosen in advance — after rescaling each objective, or your units decide the weights for you.

Weighted-Sum Fitness
F(\mathbf{x}) = \sum_{i=1}^{m} w_i \, \tilde{f}_i(\mathbf{x})
05 / 13
ML 101
M13 · L03
Refusing to Collapse

The Pareto Front

  • A dominates B when it is never worse and somewhere better
  • Solutions nothing dominates form the non-dominated set
  • Return a spread of compromises, then let a human choose
  • A weighted sum can never reach concave parts of the trade-off surface
06 / 13
ML 101
M13 · L03
Deb et al. (2002)

NSGA-II in Outline

  • Non-dominated sorting — partition the population into fronts; lower rank wins
  • Crowding distance — the tie-break inside a front; prefer sparse regions so the front stays spread
  • Elitism by combination — pool parents and offspring, sort, truncate
07 / 13
ML 101
M13 · L03
Hard Limits

Handling Constraints

  • Penalty — subtract a term that grows with the violation; infeasible genes survive
  • Rejection — worst possible fitness. Useless when feasible solutions are rare
  • Repair — make it feasible, then score it
  • Feasibility-preserving operators — an invalid child cannot be built
  • Report feasibility separately from fitness
08 / 13
ML 101
M13 · L03
Diversity Loss

Premature Convergence

Crossing two near-copies returns the same individual, so mutation becomes the only novelty — a slow random walk. From outside it looks like a finished run.

  • Best minus mean fitness collapsing early
  • Count of distinct genotypes falling steeply
  • Per-gene allele frequencies saturating at 0 or 1
09 / 13
ML 101
M13 · L03
Countermeasures

Keeping the Population Varied

  • Lower selection pressure — smaller tournaments, or rank-based selection
  • Raise mutation, adaptively when a diversity measure drops
  • Fitness sharing — a crowd is penalised for being a crowd (Goldberg, 1989)
  • Crowding replacement — a child replaces who it most resembles
  • Restarts and islands — keep an elite archive; let sub-populations diverge
10 / 13
ML 101
M13 · L03
Where the Time Goes

Budget in Evaluations

100 individuals over 200 generations is 20,000 evaluations. At two seconds each that is over eleven hours on one core — arithmetic to do before the run, not after.

Evaluation Budget
N_{\text{eval}} = P \cdot G
11 / 13
ML 101
Knowledge Check

Check what stuck

Four questions from this lesson. Answer to see why — the explanation appears whether you were right or wrong. Nothing is scored or saved.

Question 1 of 0
Score 0/0

12 / 13
ML 101
Key Takeaways
Summary

Key Takeaways

  • Fitness is the problem statement — suspect it first
  • Reward the outcome, never the behaviour you assume produces it
  • Weighted sums need rescaling; NSGA-II returns a front instead
  • Constraints: penalty, rejection, repair, or operators that cannot break them
  • Watch diversity, and counter its loss before the run flatlines
  • Cache, subsample, parallelise — evaluations are what cost you
13 / 13