Fitness function

Also known as: fitness

On this page 7

A fitness function is the objective that scores each candidate solution in a population, so that selection can favor better individuals and the search moves toward good solutions. In evolutionary computation, it is the only channel through which the algorithm learns what the problem is: genetic algorithms, evolution strategies, genetic programming and swarm methods all depend on it.

The value it returns, often simply called fitness, can be a cost to minimize, a quality to maximize or a vector of several objectives. Because the algorithm optimizes exactly what the function measures, designing the fitness function is usually the hardest and most consequential decision in an evolutionary project.

A fitness function maps a decoded candidate to a number or vector. The genotype, such as a bit string or a tree, is first translated through the genotype-phenotype mapping into a phenotype, for example a schedule, a circuit or a controller, and the phenotype is then evaluated.

Fitness values feed selection, which decides who becomes a parent, and often survivor selection, which decides who stays in the next generation. Operators such as crossover and mutation never see the problem directly; they only receive information through fitness-based selection.

Most selection schemes need only relative ordering, not absolute values. Tournament and rank-based selection compare individuals, so any monotonic transformation of the fitness leaves the search unchanged. Fitness proportionate selection, by contrast, depends on the actual magnitudes and therefore on scaling.

Types of fitness functions

Fitness functions vary in how they are computed and how much noise they carry. The table summarizes the main families and where each appears.

TypeHow fitness is computedTypical application
AnalyticClosed-form formulaBenchmark functions, parameter tuning
Simulation-basedRun a simulator and measure outcomeRobot controllers, engineering design
Data-drivenError on a training data setSymbolic regression, classifier evolution
Noisy or stochasticAverage over random trialsGames, policies under uncertainty
Multi-objectiveVector of separate objectivesCost versus performance trade-offs
Relative or competitiveOutcome against other individualsCoevolution, game strategies
InteractiveHuman judgmentArt, design, music generation
Common kinds of fitness functions

In multi-objective evolutionary algorithms such as NSGA-II, the fitness function returns several values, and the algorithm ranks individuals by Pareto dominance instead of a single scalar. This avoids choosing weights in advance and yields a front of trade-off solutions.

Design properties that make a fitness function work

A good fitness function provides a gradient of improvement, meaning that partially correct solutions score better than worse ones. A function that returns only success or failure produces a flat fitness landscape, and the search degenerates into random sampling.

The following properties determine how well a fitness function guides the search.

PropertyWhat it meansEffect if missing
Graded signalPartial progress raises the scoreSearch stalls on plateaus
AlignmentScore reflects the true goalSolutions exploit loopholes
Low evaluation costFast to compute per individualFew generations within budget
Low noiseRepeat evaluations agreeSelection rewards luck
Smooth landscapeSmall changes give small score changesOperators behave like random jumps
Constraint handlingInfeasible solutions are ranked sensiblyPopulation drifts into invalid regions
Properties of an effective fitness function

Constraints are typically handled through penalty terms added to the score, repair operators that fix invalid candidates, or feasibility rules that always rank feasible individuals above infeasible ones. Penalty weights need tuning: too small and invalid solutions dominate, too large and the search cannot cross infeasible regions.

The fitness function is closely related to objective, loss and reward functions, and the differences are mostly about how the score is used. The table compares these terms.

ConceptFieldKey difference
Fitness functionEvolutionary computationDrives population selection, no gradient needed
Objective functionMathematical optimizationGeneral term for the quantity optimized
Loss functionMachine learningUsually differentiable, minimized by gradient descent
Reward functionReinforcement learningScores individual actions or steps over time
Novelty metricNovelty searchRewards behavioral difference instead of quality
Fitness function compared with similar scoring concepts

The fitness landscape is a separate concept: it is the surface formed by fitness values over the whole search space, and its ruggedness, neutrality and deception describe how hard a given fitness function is to optimize.

Pitfalls in practice

The best-known failure is specification gaming, where evolution finds a solution that maximizes the score while missing the intent. Evolved simulated creatures that exploit physics engine bugs are a classic illustration.

  • Deceptive fitness: local optima lead away from the global optimum; novelty search and quality diversity methods such as MAP-Elites help.
  • Expensive evaluations: surrogate models or fitness approximation can replace most true evaluations.
  • Noise: re-evaluating elites or averaging several runs prevents lucky individuals from dominating.
  • Bloat in genetic programming: adding a size penalty, called parsimony pressure, keeps programs compact.
  • Overfitting: data-driven fitness should be validated on held-out data.

Practitioners also watch for premature convergence caused by fitness design. When one individual scores far above the rest, proportionate selection lets it flood the population within a few generations. Rank-based selection, fitness scaling or niching with fitness sharing preserves diversity long enough for the search to explore.

Evaluation budget is the final practical constraint. In real projects, fitness evaluation often accounts for more than 90 percent of runtime, because each call may involve a simulation, a training run or a physical test. Parallel evaluation across processors, caching of repeated genotypes and early termination of clearly poor candidates are standard ways to reduce wall-clock time without changing the search.

A non-technical view

A fitness function is the judge in a contest. The computer creates many possible answers. The judge gives each one a score. The best ones are kept and mixed to make new answers.

The judge must be fair and precise. If it rewards the wrong thing, the computer will happily produce the wrong thing. A clear scoring rule is the key to good results.

A concrete example

An engineering team uses a genetic algorithm to design a lightweight bracket for an aircraft cabin. Each candidate encodes the thickness of 40 structural members. The fitness function runs a quick finite element analysis and returns the mass in grams plus a penalty for any member whose stress exceeds the allowed limit.

Early runs produce very light brackets that fail under load, because the penalty weight is too small. The team raises it and adds a second objective, maximum deflection, turning the problem into multi-objective optimization with a population of 100 over 300 generations.

The final Pareto front offers several designs. The team picks one that is about 18 percent lighter than the previous part while meeting all stress and stiffness requirements, confirmed by a full-detail simulation.