Selection Operators

Genetic Selection

sel_spea_2(individuals, sel_count)

Selects the next generation of individuals using the SPEA-II algorithm. Usually, the size of individuals should be larger than the sel_count parameter. If the size of individuals is equal to sel_count, the population will be sorted according to their pareto fronts.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

Returns

A list of selected individuals.

Return type

list

sel_nsga_2(individuals, sel_count, sorting='standard')

Selects the next generation of individuals using the NSGA-II algorithm. Usually, the size of individuals should be larger than the sel_count parameter. If the size of individuals is equal to sel_count, the population will be sorted according to their pareto fronts.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • sorting (str) – The algorithm to use for non-dominated sorting. Can be either ‘log’ or ‘standard’ string literal.

Returns

A list of selected individuals.

Return type

list

sel_nsga_3(individuals, sel_count, ref_points, sorting='log', best_point=None, worst_point=None, extreme_points=None, _memory=None)

Selects the next generation of individuals using the NSGA-III algorithm.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • ref_points (numpy.ndarray) – The reference points to use for the selection.

  • sorting (str) – The non-dominated sorting algorithm to use, optional.

  • best_point (Optional[numpy.ndarray]) – Best point of the previous generation, optional. If not provided, finds the best point from the current individuals.

  • worst_point (Optional[numpy.ndarray]) – Worst point of the previous generation, optional. If not provided, finds the worst point from the current individuals.

  • extreme_points (Optional[numpy.ndarray]) – Extreme points of the previous generation, optional. If not provided, finds the extreme points from the current individuals.

  • _memory (Optional[SelNSGA3WithMemory]) – This private parameter is used by the SelNSGA3WithMemory objects to store the best, the worst and the extreme points of the selection into itself. Not recommended for manual use.

Returns

A list of selected individuals.

Return type

list

class SelNSGA3WithMemory(ref_points, sorting='log')

The NSGA-III selection operator with memory for best, worst and extreme points. Instances of this class can be registered into a Toolbox.

Parameters
  • ref_points (numpy.ndarray) – Reference points for selection.

  • sorting (str) – The algorithm to use for non-dominated sorting. Can be either ‘log’ or ‘standard’ string literal.



Tournament Selection

sel_tournament(individuals, rounds, contestants, fit_attr='fitness')

Selects the best individual among the randomly chosen contestants for rounds times.

Parameters
  • individuals (list) – A list of individuals to select from.

  • rounds (int) – The number of rounds in the tournament.

  • contestants (int) – The number of individuals participating in each round.

  • fit_attr (str) – The attribute of individuals to use as the selection criterion.

Returns

A list of selected individuals.

Return type

list

sel_double_tournament(individuals, rounds, fitness_size, parsimony_size, fitness_first, fit_attr='fitness')

Tournament selection which uses the size of the individuals in order to discriminate good solutions. It can also be used for Genetic Programming as a bloat control technique.

Parameters
  • individuals (list) – A list of individuals to select from.

  • rounds (int) – The number of rounds in the tournament.

  • fitness_size (int) – The number of individuals participating in each fitness tournament.

  • parsimony_size (int) – The number of individuals participating in each size tournament. This value has to be a real number in the range of [1,2].

  • fitness_first (bool) – If set to True, the fitness tournament will be performed first.

  • fit_attr (str) – The attribute of individuals to use as the selection criterion.

Returns

A list of selected individuals.

Return type

list

sel_tournament_dcd(individuals, sel_count)

Tournament selection based on the dominance between two individuals, if the two individuals do not inter-dominate, then the selection is made based on their crowding distance. The individuals sequence length has to be a multiple of four only if the sel_count is equal to the length of individuals. This selection requires the individuals to have the crowding_dist attribute, which can be set by the assign_crowding_dist function.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

Returns

A list of selected individuals.

Return type

list



Lexicase Selection

sel_lexicase(individuals, sel_count)

Returns an individual that does the best on the fitness cases when considered one at a time in random order.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

Returns

A list of selected individuals.

Return type

list

sel_epsilon_lexicase(individuals, sel_count, epsilon=None)

Returns an individual that does the best on the fitness cases when considered one at a time in random order.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • epsilon (Optional[float]) – The epsilon parameter, optional. If not provided, the epsilon parameter is automatically calculated from the median of fitness values.

Returns

A list of selected individuals.

Return type

list



Various Selection

sel_random(individuals, sel_count)

Selects randomly sel_count individuals from the input individuals.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

Returns

A list of selected individuals.

Return type

list

sel_best(individuals, sel_count, fit_attr='fitness')

Selects the best sel_count individuals from the input individuals.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • fit_attr (str) – The attribute of individuals to use as the selection criterion.

Returns

A list of selected individuals.

Return type

list

sel_worst(individuals, sel_count, fit_attr='fitness')

Selects the worst sel_count individuals among the input individuals.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • fit_attr (str) – The attribute of individuals to use as the selection criterion.

Returns

A list of selected individuals.

Return type

list

sel_roulette(individuals, sel_count, fit_attr='fitness')

Selects sel_count individuals from the input individuals using sel_count spins of a roulette. The selection is made by looking only at the first objective of each individual. The returned list contains references to the input individuals.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • fit_attr (str) – The attribute of individuals to use as the selection criterion.

Returns

A list of selected individuals.

Return type

list

sel_stochastic_universal_sampling(individuals, sel_count, fit_attr='fitness')

Selects the sel_count individuals among the input individuals. The selection is made by using a single random value to sample all the individuals by choosing them at evenly spaced intervals. The returned list contains references to the input individuals.

Parameters
  • individuals (list) – A list of individuals to select from.

  • sel_count (int) – The number of individuals to select.

  • fit_attr (str) – The attribute of individuals to use as the selection criterion.

Returns

A list of selected individuals.

Return type

list



Helpers

assign_crowding_dist(individuals)

Assigns a crowding distance to each individual’s fitness. The crowding distance can be retrieved via the crowding_dist attribute of each individual’s fitness. The individuals are modified in-place.

Parameters

individuals (list) – A list of individuals with Fitness attributes.

Returns

Nothing.

Return type

None

uniform_reference_points(objectives, ref_ppo=4, scaling=None)

Generates reference points uniformly on the hyperplane intersecting each axis at 1. The scaling factor is used to combine multiple layers of reference points.

Parameters
  • objectives (int) – Number of objectives.

  • ref_ppo (int) – Number of reference points per objective, optional.

  • scaling (Optional[float]) – Scaling factor, optional.

Returns

Uniform reference points.

Return type

numpy.ndarray