Selection Probabilities

The probability that an individual is selected is roughly analogous to biological fitness, and so calculating it for different populations and selection schemes is useful. This portion of the library has tools for doing exactly that.

Tools for measuring the ecology of various evolutionary algorithms

ec_ecology_toolbox.selection_probabilities.LexicaseFitness(pop: List[List[float]], epsilon: float = 0.0) List[float]

Return a vector containing the probability that each member of the population will be selected by lexicase selection or epsilon lexicase selection.

For example, LexicaseFitness([[1, 2, 2], [2, 1, 2], [0, 0, 0]]) will return [.5, .5, 0], because the first two score vectors each have a 50% chance of being chosen and the third has no chance of being chosen.

Note: calculating these probabilities is an NP-Hard problem (Dolson, 2023). This function is optimized, but if you try to use it with too large of input it might take a very a long time.

Parameters:
  • pop (list of lists of floats) – The scores of each member of the population population on each test case/fitness criterion.

  • epsilon (float) – (optional) The epsilon value to use (if you want epsilon-lexicase selection probabilities; default value is 0, which is equivalent to standard lexicase selection).

Returns:

The probabilities of each individual in pop being selected by lexicase selection.

Return type:

List of floats

ec_ecology_toolbox.selection_probabilities.LexicaseFitnessIndividual(pop: List[List[float]], i: int, epsilon: float = 0.0) float

Returns the probability that a single individual is selected by lexicase selection.

Note: calculating these probabilities is an NP-Hard problem (Dolson, 2023). This function is optimized, but if you try to use it with too large of input it might take a very a long time. This version is faster than LexicaseFitness if you just need the probability for a single individual, but is still worst-case O(N!)

Parameters:
  • pop (list of lists of floats) – The scores of a population on each test case/fitness criterion.

  • i (int) – The index of the individual in pop to calculate selection probability for

  • epsilon (float) – (optional) The epsilon value to use (if you want epsilon-lexicase selection probabilities; default value is 0, which is equivalent to standard lexicase selection).

Returns:

The probability of individual i being selected by lexicase selection.

Return type:

float

class ec_ecology_toolbox.selection_probabilities.Random
__init__(self: ec_ecology_toolbox.selection_probabilities.Random, arg0: int) None
ec_ecology_toolbox.selection_probabilities.SharingFitness(pop: List[List[float]], t_size: int = 2, alpha: float = 1, sigma_share: float = 8.0) List[float]

Return a vector containing the probability that each member of the population will be selected under tournament selection with fitness sharing.

The numbers in the pop parameter are assumed to be scores on a set of test cases/fitness criteria/tasks. Similarity will be calculated as the euclidean distance between these scores. Overall “Fitness” will be calculated as the sum of these scores, divided by the fitness sharing niche count.

Parameters:
  • pop (list of lists of floats) – The scores of each member of the population population on each test case/fitness criterion.

  • t_size (int) – Tournament size; the number of individuals that will be randomly selected to compete against each other in each selection event.

  • alpha (float) – The alpha parameter of the fitness sharing function (controls shape of the sharing function)

  • sigma_share (float) – The sharing threshold (i.e. how similar do individuals need to be to share fitness)

Returns:

The probabilities of each individual in pop being selected.

Return type:

List of floats

ec_ecology_toolbox.selection_probabilities.TournamentFitness(pop: List[List[float]], t_size: int = 2) List[float]

Return a vector containing the probability that each member of the population will be selected under tournament selection.

The numbers in the pop parameter are assumed to be scores on a set of test cases/fitness criteria/tasks. Overall “Fitness” will be calculated as the sum of these scores.

Parameters:
  • pop (list of lists of floats) – The scores of each member of the population population on each test case/fitness criterion.

  • t_size (int) – Tournament size; the number of individuals that will be randomly selected to compete against each other in each selection event.

Returns:

The probabilities of each individual in pop being selected.

Return type:

List of floats

ec_ecology_toolbox.selection_probabilities.UnoptimizedLexicaseFitness(pop: List[List[float]], epsilon: float = 0.0) List[float]

Return a vector containing the probability that each member of the population will be selected by lexicase selection or epsilon lexicase selection.

For example, LexicaseFitness([[1, 2, 2], [2, 1, 2], [0, 0, 0]]) will return [.5, .5, 0], because the first two score vectors each have a 50% chance of being chosen and the third has no chance of being chosen.

Note: calculating these probabilities is an NP-Hard problem (Dolson, 2023). This function is optimized, but if you try to use it with too large of input it might take a very a long time.

Parameters:
  • pop (list of lists of floats) – The scores of each member of the population population on each test case/fitness criterion.

  • epsilon (float) – (optional) The epsilon value to use (if you want epsilon-lexicase selection probabilities; default value is 0, which is equivalent to standard lexicase selection).

Returns:

The probabilities of each individual in pop being selected by lexicase selection.

Return type:

List of floats