IDCM_Predation_Operator.py

hello

IDCM_Predation_Operator.py, Geoffrey Weal, 25/12/2019

This is one of the Predation Operators that can be used by the genetic algorithm program. This is the IDCM Predation Operator.

This Operator works by preventing the population from having clusters with the same …

class Organisms.GA.Predation_Operators.IDCM_Predation_Operator.Cluster_Block(collection, collection_type, index)

This is used by the Remove_Cluster_Due_To_Predation_Violation definition to store information in an easy way to help the user understand what is going on in this method

Parameters:
  • collection (Population or Offspring_Pool) – This is the collection to record. This is either the instance of the Population or the Offspring_Pool

  • collection_type (str.) – This describes if the cluster recorded is in the population (given as ‘pop’) or the offspring (given as ‘off’).

  • index (int) – The position/index of the cluster in the collection.

class Organisms.GA.Predation_Operators.IDCM_Predation_Operator.IDCM_Predation_Operator(Predation_Information, population, no_of_cpus, print_details)

This is a Predation Operator for identifying if two clusters are identifcal using a style of a euclidean distance matrix.

This is based on the method given in MEGA to describe the IDCM Operator.

MEGA is described in more detail in https://pubs.acs.org/doi/abs/10.1021/acs.jpcc.6b12848

Parameters:
  • Predation_Information (dict.) – This contains all the information needed by the Predation Operator you want to use to run.

  • population (Organisms.GA.Population) – This is the population that this Operator will be controlling to make sure that no two clusters in the population have the same energy.

  • print_details (bool) – Print details of the predation operator, like verbose

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.

assess_for_violations(offspring_pool, force_replace_pop_clusters_with_offspring)

The offspring are assessed against clusters in the population. Offspring are removed from the offspring_pool if: 1) They are geometrically the same as another offspring 2) They are geometrically the same as another cluster in the population.

Must return the clusters that have been removed from population and offspring_pool lists.

Parameters:
  • offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection of offspring to assess for violations to the Predation Operator.

  • force_replace_pop_clusters_with_offspring (bool.) – This will tell the genetic algorithm whether to swap clusters in the population with offspring if the predation operator indicates they are the same but the predation operator has a better fitness value than the cluster in the population.

Returns:

A list of the names of the offspring to be removed * force_replacement (tuple of (int, int)): A list of the clusters in the population that should be replaced, and the offspring they should be replaced by.

Return type:

  • offspring_to_remove (tuple of ints)

assess_for_violations_force_replacement(offspring_pool)

The offspring are assessed against clusters in the population. Offspring are removed from the offspring_pool if: 1) They are geometrically the same as another offspring 2) They are geometrically the same as another cluster in the population.

Must return the clusters that have been removed from population and offspring_pool lists.

Parameters:

offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection of offspring to assess for violations to the Predation Operator.

Returns:

A list of the names of the offspring to be removed * force_replacement (tuple of (int, int)): A list of the clusters in the population that should be replaced, and the offspring they should be replaced by.

Return type:

  • offspring_to_remove (tuple of ints)

assess_for_violations_message(swap_cluster_in_pop_with_offspring, offspring_to_remove_as_too_many_pop_in_similar_common, offspring_to_remove_due_to_pop, offspring_to_remove_due_to_other_offspring)

This method will tell the information that offspring are removed or replaced and why.

Parameters:
  • swap_cluster_in_pop_with_offspring (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – The clusters in the population to swap out, and the offspring to swap in its place. These will be replaced because the offspring has a higher fitness than the cluster in the population, even though they are similar.

  • offspring_to_remove_as_too_many_pop_in_similar_common (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – Remove offspring because there are too many similar clusters to it in the population already.

  • offspring_to_remove_due_to_pop (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – Remove offspring because they are similar to a cluster in the population. These offspring are less fit than their similar counterparts in the population.

  • offspring_to_remove_due_to_other_offspring (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – Remove offpsring because they are similar to other clusters in the Offspring_Pool. This offspring is less fit than their similar counterparts in the offspring_pool.

assess_for_violations_no_force_replacement(offspring_pool)

The offspring are assessed against clusters in the population. Offspring are removed from the offspring_pool if: 1) They are geometrically the same as another offspring 2) They are geometrically the same as another cluster in the population.

Must return the clusters that have been removed from population and offspring_pool lists.

Parameters:

offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection of offspring to assess for violations to the Predation Operator.

Returns:

A list of the names of the offspring to be removed * force_replacement (tuple of (int, int)): A list of the clusters in the population that should be replaced, and the offspring they should be replaced by.

Return type:

  • offspring_to_remove (tuple of ints)

check_database(collections)

This method will check to make sure that all the clusters comparisons in the self.LoD_comparison_database are false

I.e. check that all the clusters in the collections are not idenitcal

Parameters:

collections (list of Organisms.GA.Collection.Collection) – This is a list of all the Populations and Offspring_Pool in your genetic algorithm to check.

check_initial_population(return_report=False)

This definition is responsible for making sure that the initialised population obeys the Predation Operator of interest.

Parameters:

return_report (bool.) – Will return a dict with all the information about what clusters are similar to what other clusters in the population.

Returns:

a list of the clusters to remove from the population as they violate the Predation Operator. Format is [(index in population, name fo cluster),…] * CNA_report (dict.): a dictionary with information on the clusters being removed and the other clusters in the population which have caused the violation to the SCM Predation Operator. This information is only used to display information so they know why there are violations to the Predation Operator when they occur. For is {removed cluster: [list of clusters that this cluster is similar to in the population.]}

Return type:

  • clusters_to_remove (list of ints)

get_identical_structures_initial_population()

This method is designed to identify which clusters in the LoD_database (from the initial population) are identify using this method.

This will place all the results from this into self.LoD_comparison_database

pop_identical_structures()

This method will identify which clusters need to be removed from self.LoD_comparison_database based on being identical via this method, and will remove the entries of those clusters from self.LoD_database and self.LoD_comparison_database

Returns:

a list of the clusters to remove from the population as they violate the Predation Operator. Format is [(index in population, name fo cluster),…] * identical_structures_report (dict.): a dictionary with information on the clusters being removed and the other clusters in the population which have caused the violation to the SCM Predation Operator. This information is only used to display information so they know why there are violations to the Predation Operator when they occur. For is {removed cluster: [list of clusters that this cluster is similar to in the population.]}

Return type:

  • clusters_to_remove (list of ints)

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

remove_similar_clusters_in_population(clusters_to_remove)

This method will remove the similar clusters from the population.

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

update_LoD_database(collection)

This methos will add the collection to the LoD_database.

Parameters:

collection (Organisms.GA.Population.Population or Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection to add to the LoD_database