SCM_and_Energy_Fitness_Operator.py
Meow
- class Organisms.GA.Fitness_Operators.SCM_and_Energy_Fitness_Operator.SCM_and_Energy_Fitness_Operator(fitness_information, predation_operator, population, generations, no_of_cpus, print_details)
This class controls the how the fitness values for the Structural Comparison Method (SRM)-based predation operator are obtained.
- Parameters:
fitness_information (dict.) – This is all the information that is needed about the fitness class
predation_operator (Organisms.GA.Predation_Operator) – This is the predation operator that this fitness class will take information from if needed to obtain a fitness.
population (Organisms.GA.Population) – The population to assign fitnesses to
generations (int) – The number of generations that will be performed in the genetic algorithm.
no_of_cpus (int) – the number of cpus to use when multiprocessing
print_details (bool) – Print the details of the energy fitness operator. True if yes, False if no
- add_to_database(collection)
Add clusters similarities to the CNA database to be stored for future generations.
- Parameters:
collection (Organisms.GA.Collection.Collection) – update the fitnesses of clusters in the collection.
- assign_all_fitnesses_after_assessing_against_predation_operator(all_offspring_pools, current_generation_no, offspring_to_remove)
This method is to be used in the GA program. This will assign all the fitnesses of all clusters in the current generation (population and offspring) after the offspring are assessed to understand if they violate the predation operator (i.e. an offspring is Class 1 similar to a cluster in the population, or another offspring).
See the description given for the “assign_all_fitnesses” def on what the crux of this method is.
If you write your own diversiy and fitness classes, you do not need to implement this method in your fitness class.
- Parameters:
all_offspring_pools (list of Organisms.GA.Offspring_Pool) – All of the offspring_pools
current_generation_no (int) – The current generation
offspring_to_remove (list of int) – a list of all the names of clusters in the offspring that will be removed. Currently not needed, but kept in case.
- assign_all_fitnesses_after_natural_selection(current_generation_no)
This method is to be used in the GA program. This will assign all the fitnesses to all the clusters in the population before the offspring are assessed to understand if they violate the predation operator (i.e. an offspring is Class 1 similar to a cluster in the population, or another offspring).
See the description given for the “assign_population_fitnesses” def on what the crux of this method is.
If you write your own diversiy and fitness classes, you do not need to implement this method in your fitness class.
- Parameters:
current_generation_no (int) – The current generation
- assign_all_fitnesses_before_assessing_against_predation_operator(all_offspring_pools, current_generation_no)
This method is to be used in the GA program. This will assign all the fitnesses of all clusters in the current generation (population and offspring) before the offspring are assessed to understand if they violate the predation operator (i.e. an offspring is Class 1 similar to a cluster in the population, or another offspring).
See the description given for the “assign_all_fitnesses” def on what the crux of this method is.
If you write your own diversiy and fitness classes, you do not need to implement this method in your fitness class.
- Parameters:
all_offspring_pools (list of Organisms.GA.Offspring_Pool) – list of all the offspring pools of offspring to assign fitness values to.
current_generation_no (int) – The current generation
- assign_initial_population_fitnesses()
This method is designed to assign fitness values to the clusters of the population only at the start of the GA, when the population has been initialised
- assign_resumed_population_fitnesses(resume_from_generation)
This method is designed to assign fitness values to the clusters of the population only at the beginning of a resumed GA.
- Parameters:
resume_from_generation (int) – The current generation to resume from.
- convert_population_fitness_to_SCM_fitness_contribution(population_fitness)
This method will take the population fitness and use this to determine what the new coefficients (weights) for the energy and SCM coefficients are.
- Parameters:
population_fitness (float) – The population ‘fitness value’. This value is some value between 0.0 and 1.0.
- get_population_fitness(cluster_SCM_simiarities, population_fitness_function)
Obtain the ‘fitness’ of the population. This population fitness is based on the similarity values from all clusters in the population. This python definition will take the similarity values from all clusters in the population and get a ‘similarity value’ of the population. This definition will then take this population similarity value and convert it into a population fitness value. The population fitness value must be a read value between (and including) 0.0 and 1.0.
- Parameters:
cluster_SCM_simiarities (list of floats) – The similarities of clusters of the population as obtained by the SCM. These are the sigma 1/2 similarities.
population_fitness_function (def) – The python def that turns the population similarity value into a population fitness value.
- is_there_an_similarity_range(similarity_rounding)
Determines if there is a range of similarities in the collection
- Parameters:
rounding (float) – The rounding of the similarity of the cluster
returns Is there a range of similarities in the collection rtype bool
- print_initial_message()
At the start of the GA run, this message will be shown so that the user knows what their energy and fSRM (CNA)-based itness contributions are at the start of the GA.
- remove_from_database(cluster_names_to_remove)
Clusters to remove from the CNA database
- Parameters:
cluster_names_to_remove (list of ints) – A list of the names of all the clusters to remove from the CNA database
- reset()
Reset the CNA database with no inputs