SELAB3 Python Code
Loading...
Searching...
No Matches
Functions
evolution.py File Reference

File that brings together all morphological evolution related function like the general evolution process and all related functions for mutation, crossover and selection. More...

Functions

List[Arm] morphevo.evolution.run_evolution (Optional[List[Arm]] children=None)
 Evolve arms with following scheme: More...
 
List[Arm] morphevo.evolution.selection (Callable selection_function, List[Arm] population)
 Do a selection on a list of parents given a selection function. More...
 
List[Arm] morphevo.evolution.mutate (Callable mutation_function, List[Arm] parents)
 Do a mutation on a list of parents given a mutation function. More...
 
List[Arm] morphevo.evolution.selection_fitness (List[Arm] population)
 Do selection on the fitness of the arm. More...
 
List[Arm] morphevo.evolution.selection_success_rate (List[Arm] population)
 Do selection on the success_rate of the arm. More...
 
List[Arm] morphevo.evolution.selection_fitness_diversity (List[Arm] population)
 Do selection in a fitness-diversity way. More...
 
Arm morphevo.evolution.select_next_parent (List[Arm] population, List[Arm] parents)
 Select the next parent that will be added to the parents. More...
 
float morphevo.evolution.calculate_fitness (Arm arm)
 Calculate the fitness of a genome by calculating its coverage. More...
 
float morphevo.evolution.calculate_diversity (Arm arm, List[Arm] others)
 calculate how diverse an arm is compared to others. More...
 
List[float] morphevo.evolution.calculate_selection_scores (List[float] population_fitnesses, List[float] population_diversities)
 Calculate a score on which selection can be done for fitness-diversity selection. More...
 
List[Arm] morphevo.evolution.mutate_with_crossover (List[Arm] parents)
 Do mutation with morphevo configuration parameters. More...
 
List[Arm] morphevo.evolution.mutate_with_crossover_coevolution (List[Arm] parents)
 Do mutation with coevolution configuration parameters. More...
 
def morphevo.evolution.create_crossover_children (List[Arm] parents, int amount)
 Function to create crossover children, pick 2 random parents, check if they are the same. More...
 
def morphevo.evolution.save_best_genome (Arm arm, int generation)
 Save the genome of an arm to a file. More...
 

Detailed Description

File that brings together all morphological evolution related function like the general evolution process and all related functions for mutation, crossover and selection.

Function Documentation

◆ calculate_diversity()

float morphevo.evolution.calculate_diversity ( Arm  arm,
List[Arm]  others 
)

calculate how diverse an arm is compared to others.

(others is probably the already selected parents in the fitness-diversity selection).

Parameters
armThe arm you want to compare to others to calculate diversity score.
othersThe other arms you want to compare to.
Returns
Average diversity compared to others.

◆ calculate_fitness()

float morphevo.evolution.calculate_fitness ( Arm  arm)

Calculate the fitness of a genome by calculating its coverage.

Parameters
armThe arm of which you want to calculate fitness.

◆ calculate_selection_scores()

List[float] morphevo.evolution.calculate_selection_scores ( List[float]  population_fitnesses,
List[float]  population_diversities 
)

Calculate a score on which selection can be done for fitness-diversity selection.

First normalize fitness and diversity scores. Then calculate the distance to (1,1). If fitness and diversity are 1,1 this means 100% fit and 100% diverse from all previously selected parents.

Parameters
population_fitnessesThe fitnesses of a population.
population_diversitiesThe diversities of a population.
Returns
List of scores that combined fitness and diversity.

◆ create_crossover_children()

def morphevo.evolution.create_crossover_children ( List[Arm]  parents,
int  amount 
)

Function to create crossover children, pick 2 random parents, check if they are the same.

If not do the crossover else pick again.

Parameters
parentsA list of parents to choose from.
amountThe amount of crossover children you want.
Returns
List of children resulting from crossover.

◆ mutate()

List[Arm] morphevo.evolution.mutate ( Callable  mutation_function,
List[Arm]  parents 
)

Do a mutation on a list of parents given a mutation function.

Parameters
mutation_functionThe function used for mutation.
parentsThe parents that will be mutated.
Returns
Mutated parents.

◆ mutate_with_crossover()

List[Arm] morphevo.evolution.mutate_with_crossover ( List[Arm]  parents)

Do mutation with morphevo configuration parameters.

First make normal children by mutating parents, after that crossover children are added if specified in config.

Parameters
parentsThe parents of which you want to make children.
Returns
List of mutated children.

◆ mutate_with_crossover_coevolution()

List[Arm] morphevo.evolution.mutate_with_crossover_coevolution ( List[Arm]  parents)

Do mutation with coevolution configuration parameters.

First make normal children by mutating parents, after that crossover children are added if specified in config.

Parameters
parentsThe parents of which you want to make children.
Returns
List of mutated children.

◆ run_evolution()

List[Arm] morphevo.evolution.run_evolution ( Optional[List[Arm]]   children = None)

Evolve arms with following scheme:

  • evaluate arms
  • select best arms (selection includes best arms previous generation)
  • mutate best arms
  • restart loop with mutated arms
    Parameters
    childrenOptional list of children to start from. Else children will be randomly generated.
    Returns
    List of evolved arms.

◆ save_best_genome()

def morphevo.evolution.save_best_genome ( Arm  arm,
int  generation 
)

Save the genome of an arm to a file.

Parameters
armThe arm of which you want to save the genome.
generationThe generation in which the genome was evaluated.

◆ select_next_parent()

Arm morphevo.evolution.select_next_parent ( List[Arm]  population,
List[Arm]  parents 
)

Select the next parent that will be added to the parents.

Do this by making a consideration between fitness and diversity.

Parameters
populationCurrent population.
parentsCurrent list of parents.
Returns
The parent that scores the highest on fitness-diversity compared to already selected parents.

◆ selection()

List[Arm] morphevo.evolution.selection ( Callable  selection_function,
List[Arm]  population 
)

Do a selection on a list of parents given a selection function.

Parameters
selection_functionThe function used for selection.
populationThe parents that will be selected from.
Returns
Selected parents.

◆ selection_fitness()

List[Arm] morphevo.evolution.selection_fitness ( List[Arm]  population)

Do selection on the fitness of the arm.

Parameters
populationThe population on which you want to do selection.
Returns
List of selected parents.

◆ selection_fitness_diversity()

List[Arm] morphevo.evolution.selection_fitness_diversity ( List[Arm]  population)

Do selection in a fitness-diversity way.

Parameters
populationThe population on which you want to do selection.
Returns
List of selected parents.

◆ selection_success_rate()

List[Arm] morphevo.evolution.selection_success_rate ( List[Arm]  population)

Do selection on the success_rate of the arm.

This is for the coevolution loop, success_rate is calculated in the rl step.

Parameters
populationThe population on which you want to do selection.
Returns
List of selected parents.