geneticengine.algorithms.gp.operators.selection

Classes

TournamentSelection

TournamentSelection represents a tournament selection algorithm, where

BloatControlledTournamentSelection

Tournament selection with optional size limits and parsimony pressure.

LexicaseSelection

Implements Lexicase Selection

WeightedLexicaseSelection

Lexicase selection with accuracy-biased objective ordering.

PriorityLexicaseSelection

Priority Lexicase:

InformedDownsamplingSelection

Selects individuals using only test cases with highest variance.

Module Contents

class geneticengine.algorithms.gp.operators.selection.TournamentSelection(tournament_size, with_replacement=False)

Bases: geneticengine.algorithms.gp.structure.GeneticStep

TournamentSelection represents a tournament selection algorithm, where tournament_size individuals are selected at random, and only the best passes to the next generation.

Parameters:
  • tournament_size (int) – number of individuals from the population that will be randomly selected

  • with_replacement (bool) – whether the selected individuals can appear again in another tournament (default: False)

tournament_size
with_replacement = False
iterate(problem, evaluator, representation, random, population, target_size, generation)
Parameters:
Return type:

Iterator[geneticengine.solutions.individual.PhenotypicIndividual]

class geneticengine.algorithms.gp.operators.selection.BloatControlledTournamentSelection(tournament_size, max_nodes=None, parsimony_coefficient=0.0, with_replacement=False)

Bases: TournamentSelection

Tournament selection with optional size limits and parsimony pressure.

max_nodes may be an integer or a function of the generation, which enables dynamic bloat limits. Individuals over the limit are excluded when at least one eligible candidate exists. parsimony_coefficient adds a linear penalty for tree size to tournament comparisons.

Parameters:
  • tournament_size (int) – number of individuals from the population that will be randomly selected

  • with_replacement (bool) – whether the selected individuals can appear again in another tournament (default: False)

  • max_nodes (int | collections.abc.Callable[[int], int] | None)

  • parsimony_coefficient (float)

max_nodes = None
parsimony_coefficient = 0.0
_node_limit(generation)
Parameters:

generation (int)

Return type:

int | None

iterate(problem, evaluator, representation, random, population, target_size, generation)
Parameters:
Return type:

Iterator[geneticengine.solutions.individual.PhenotypicIndividual]

class geneticengine.algorithms.gp.operators.selection.LexicaseSelection(epsilon=False)

Bases: geneticengine.algorithms.gp.structure.GeneticStep

Implements Lexicase Selection (http://williamlacava.com/research/lexicase/).

Parameters:

epsilon (bool) – if True, espilon-lexicase is performed. We use the method given by equation 5 in https://dl.acm.org/doi/pdf/10.1145/2908812.2908898.

epsilon = False
static _assign_invalid_fitness(problem, individuals)

Attach an invalid fitness to every individual and return them.

Used when the evaluator drops all (or remaining) candidates so selection can continue instead of crashing on an empty pool.

Parameters:
Return type:

list[geneticengine.solutions.individual.PhenotypicIndividual]

_ensure_candidates(problem, candidates, original_population)

Rule 1: if the candidate pool is empty, refill from the original population.

Parameters:
Return type:

list[geneticengine.solutions.individual.PhenotypicIndividual]

_filter_case(problem, candidates_to_check, case)

Filter on one lexicase case.

Rule 2: if filtering would empty the pool (e.g. all-NaN fitness on that case), keep the pre-filter set instead.

Parameters:
Return type:

list[geneticengine.solutions.individual.PhenotypicIndividual]

iterate(problem, evaluator, representation, random, population, target_size, generation)
Parameters:
Return type:

Iterator[geneticengine.solutions.individual.PhenotypicIndividual]

class geneticengine.algorithms.gp.operators.selection.WeightedLexicaseSelection(epsilon=True, objective_weights=None)

Bases: LexicaseSelection

Lexicase selection with accuracy-biased objective ordering. Uses weighted random permutation: - Objectives [0,1,2] (accuracy splits): weight 4.0 each - Objectives [3,4] (costs): weight 1.0 each

Parameters:
objective_weights = None
_weighted_case_order(random, n_cases)
Parameters:
Return type:

list[int]

iterate(problem, evaluator, representation, random, population, target_size, generation)
Parameters:
Return type:

Iterator[geneticengine.solutions.individual.PhenotypicIndividual]

class geneticengine.algorithms.gp.operators.selection.PriorityLexicaseSelection(epsilon=True, objective_priorities=None)

Bases: LexicaseSelection

Priority Lexicase: - Lower integer means higher priority - Objectives in the same priority level are shuffled. Example: objective_priorities=[1, 1, 2, 3] -> [0/1 shuffled], then 2, then 3.

Parameters:
objective_priorities = None
_priority_case_order(random, n_cases)
Parameters:
Return type:

list[int]

iterate(problem, evaluator, representation, random, population, target_size, generation)
Parameters:
Return type:

Iterator[geneticengine.solutions.individual.PhenotypicIndividual]

class geneticengine.algorithms.gp.operators.selection.InformedDownsamplingSelection(max_sample_size=10, percent=0.1)

Bases: geneticengine.algorithms.gp.structure.GeneticStep

Selects individuals using only test cases with highest variance. Faster than standard Lexicase by reducing test case evaluations.

Parameters:
  • max_sample_size (int)

  • percent (float)

max_sample_size = 10
percent = 0.1
iterate(problem, evaluator, representation, random, population, target_size, generation)
Parameters:
Return type:

Iterator[geneticengine.solutions.individual.PhenotypicIndividual]