selection_algorithm (macula_tweann v0.18.1)

View Source

Selection algorithms for evolutionary processes.

This module provides various selection strategies for choosing surviving agents from a population based on fitness. Each strategy implements a different approach to balancing exploration vs exploitation:

- Competition: Top performers survive (pure exploitation) - Tournament: Random tournaments with best winner (balanced) - Steady State: Incremental replacement (conservative)

Selection Strategies

Competition Selection: - Sort population by fitness (descending) - Select top N agents based on survival rate - Guarantees best performers survive - Fast convergence but risks premature convergence - Best for well-understood fitness landscapes

Tournament Selection: - Run K tournaments of size TournamentSize - Each tournament selects best from random subset - Provides diversity through randomness - Tournament size controls selection pressure - Good balance of exploration and exploitation

Steady State Selection: - Replace worst N agents with offspring - Keep majority of population unchanged - Very conservative, slow convergence - Good for maintaining diversity - Useful when fitness landscape is deceptive

Fitness Comparison

All strategies use multi-objective fitness vectors [F1, F2, ...]. Comparison is by sum of components (weighted sum aggregation). For more sophisticated multi-objective optimization, use fitness_postprocessor module to apply Pareto dominance first.

Summary

Functions

Competition selection - select top performers.

Steady state selection - replace worst performers with new agents.

Tournament selection - run tournaments to select survivors.

Functions

competition(AgentFitnesses, SurvivalRate)

-spec competition([{term(), [float()]}], float()) -> [term()].

Competition selection - select top performers.

Sorts agents by fitness (descending) and selects the top N performers based on survival rate. This is the most aggressive selection strategy, providing strong selection pressure toward the best solutions.

Example: AgentFitnesses = [{agent1, [5.0]}, {agent2, [3.0]}, {agent3, [7.0]}] SurvivalRate = 0.5 Result = competition(AgentFitnesses, SurvivalRate) Result = [agent3, agent1] % Top 50% by fitness

steady_state(AgentFitnesses, SurvivalRate)

-spec steady_state([{term(), [float()]}], float()) -> [term()].

Steady state selection - replace worst performers with new agents.

This is the most conservative selection strategy. It keeps the majority of the population unchanged and only replaces the worst performers. Good for maintaining diversity and avoiding premature convergence.

The survival rate determines what fraction of the worst agents to replace. For example, SurvivalRate=0.8 means keep top 80% and replace bottom 20%.

Example: AgentFitnesses = [{agent1, [5.0]}, {agent2, [3.0]}, {agent3, [7.0]}, {agent4, [1.0]}, {agent5, [6.0]}] SurvivalRate = 0.6 Result = steady_state(AgentFitnesses, SurvivalRate) Result = [agent3, agent5, agent1] % Top 60% survive

tournament(AgentFitnesses, SurvivalRate, TournamentSize)

-spec tournament([{term(), [float()]}], float(), pos_integer()) -> [term()].

Tournament selection - run tournaments to select survivors.

Runs K tournaments where each tournament randomly selects TournamentSize agents and picks the best. This provides a good balance between selection pressure (controlled by tournament size) and diversity (through randomness).

Larger tournament sizes increase selection pressure (more elitist). Smaller tournament sizes increase diversity (more exploratory).

Example: AgentFitnesses = [{agent1, [5.0]}, {agent2, [3.0]}, {agent3, [7.0]}, {agent4, [4.0]}, {agent5, [6.0]}] SurvivalRate = 0.4 TournamentSize = 2 Result = tournament(AgentFitnesses, SurvivalRate, TournamentSize) Result might be [agent3, agent5] (winners of 2 tournaments)