population module

This module defines the Population class.

This module defines the Population class, used to create a population of individuals. It defines the methods allowed on populations including:

  • Mutation

  • Crossover

  • Elitism

class population.Population(config: Dict[str, Any])[source]

Bases: object

The Population class, used to define a population of individuals.

Defines a population of individuals, performs the mutations, evaluations and selection of individuals.

crossover(crossover_rate: Union[int, float])None[source]

Performs crossovers for a set of individuals in the population.

Given a crossover rate, performs crossovers for a set of randomly selected individuals in the population. To avoid the population’s score deprecating due to undesired crossovers, the best parent and the best child are kept (instead of removing both parents and adding both children).

Parameters

crossover_rate (Union[int, float]) – The crossover rate (percentage). This is the number of individuals in the population subject to crossovers.

evaluate()None[source]

Evaluates and sorts all individuals in the population from best to worst.

mutate(mutant_pop: Union[None, List[individual.Individual]] = None)None[source]

Performs random mutations on the population or a given subset.

Parameters
  • mutant_pop (Optional) – A list of individuals to mutate, generally a

  • of the population. (subset) –

scores()List[float][source]

Returns a list of fitness scores of all individuals in the population.

select()None[source]

Performs the selection of elites and mutates the rest of the population.

show()None[source]

Displays the populations 5 best and worst performing individuals.