Epoch.py

meow

class Organisms.GA.Epoch.Epoch(epoch_settings, path, fitness_operator, population)

This class is responsible for the epoch method used during the genetic algorithm run

Parameters:
  • epoch_settings (dict.) – This is a dictionary of all the epoch settings.

  • path (str.) – This is the path to store the epoch information in after each generation has completed. This information allows the genetic algorithm run to continue with information of the epoch from the last completed generation.

backup()

Make a backup of the epoch data stored on disk

change_fitness_function(fitness_operator)
check_for_backup()

Checks to see that a backup exists. If not, something has gone wrong and the algorithm needs to stop.

did_get_data_from_backup()

Determine if the data was obtained from backup epoch file or not. True for yes, False for no. If no epoch method was used, return False, since we dont need to deal with previous epoch information if no epoch method was used.

returns Did the epoch information come from the backup epoch file or not. True for yes, False for no. If no epoch method was used, return False, since we dont need to deal with previous epoch information if no epoch method was used. rtype bool.

does_backup_exist()

Determine if a backup of the epoch information stored on disk exists.

returns If a backup of the epoch information stored on disk exists. True for yes, False for no. rtype bool.

does_epoch_data_exist_on_disk()

Determine if a backup of the epoch information stored on disk exists.

returns If a backup of the epoch information stored on disk exists. True for yes, False for no. rtype bool.

get_resumed_mean_energy_epoch_details(epoch_settings, get_epoch_data_from)

This contains the information required to set up the mean_energy epoch method.

Parameters:
  • epoch_settings (dict.) – This is a dictionary of all the epoch settings.

  • get_epoch_data_from (str.) – The path of the epoch document to get information from if the genetic algorithm is being resumed.

get_resumed_same_population_epoch_details(epoch_settings, get_epoch_data_from)

This contains the information required to set up the same_population epoch method.

Parameters:
  • epoch_settings (dict.) – This is a dictionary of all the epoch settings.

  • get_epoch_data_from (str.) – The path of the epoch document to get information from if the genetic algorithm is being resumed.

information_from_the_same_generation(generation_number)

Determine if the epoch file contains the relavant information for the generation to resume from.

Parameters:

generation_number (int) – The number of the last successful generation

returns If the epoch information from the epoch file is for the current generation. True if yes, False if no. This value is True if no epoch method is used, as we dont need to deal with any epoch information if no epoch is used. rtype bool.

initialise_mean_energy_epoch_details()

This contains the information required to set up the mean_energy epoch method.

Parameters:

epoch_settings (dict.) – This is a dictionary of all the epoch settings.

initialise_same_population_epoch_details()

This contains the information required to set up the same_population epoch method.

Parameters:

epoch_settings (dict.) – This is a dictionary of all the epoch settings.

no_epoch(collection, generation_number)

The procedure to determine if an epoch should occur.

Since no epoch is included in this algorithm, return False to mean do not perform an epoch

Parameters:
  • collection (Organisms.GA.Collection) – This is the collection to use to determine if the genetic algorithm should epoch. This Collection should be the Population.

  • generation_number (int) – The number of the last successful generation

returns Should an epoch occur. False for no, since this genetic algorithm has not been told to epoch. rtype bool.

perform_epoch(generation_number, population, energyprofile, population_reset_settings, epoch_due_to_population_energy_convergence)

Perform an epoch by resetting all the clusters in the population.

Parameters:
  • generation_number (int) – The number of the last successful generation

  • population (Organisms.GA.Population) – The number of the last successful generation

  • energyprofile (Organisms.GA.EnergyProfile) – The energyprofile to write epoch information to.

  • population_reset_settings (dict.) – This is a dict that contains all the information requied to epoch the population with a set of randomly generated clusters.

  • epoch_due_to_population_energy_convergence (bool.) – Did the Epoch occur because the population converged? True if yes, False if no.

returns The name of the more recently generated cluster before the epoch method was performed. rtype bool.

perform_epoch_mean_energy(generation_number)

This method writes the current epoch data to file for the mean_energy epoch method.

Parameters:

generation_number (int) – The number of the last successful generation

perform_epoch_no_epoch(generation_number)

This method is needed, but does not do anything.

Parameters:

generation_number (int) – The number of the last successful generation

perform_epoch_same_population(generation_number)

This method writes the current epoch data to file for the same_population epoch method.

Parameters:

generation_number (int) – The number of the last successful generation

remove_backup()

Remove the backup of the epoch data stored on disk

replace_with_backup()

Replace the current epoch data with the backup epoch data.

set_settings(epoch_settings, fitness_operator, population)

This sets up the epoch as desired.

Parameters:

epoch_settings (dict.) – This is a dictionary of all the epoch settings.

setting_up_epoch_to_resume_GA()

This method will load the data from the epoch data on disk in order to resume.

should_epoch(collection, generation_number)

Determines if the genetic algorithm should epoch.

Parameters:
  • collection (Organisms.GA.Collection) – This is the collection to use to determine if the genetic algorithm should epoch. This Collection should be the Population.

  • generation_number (int) – The number of the last successful generation

returns Should an epoch occur. True if yes, False if no. rtype bool.

should_epoch_using_mean_energy_epoch(collection, generation_number)

The procedure to determine if an epoch should occur, using the mean_energy epoch method.

Parameters:
  • collection (Organisms.GA.Collection) – This is the collection to use to determine if the genetic algorithm should epoch. This Collection should be the Population.

  • generation_number (int) – The number of the last successful generation

returns Should an epoch occur. True if yes, False if no. rtype bool.

should_epoch_using_same_population_epoch(collection, generation_number)

The procedure to determine if an epoch should occur, using the same_population epoch method.

Since no epoch is included in this algorithm, return False to mean do not perform an epoch

Parameters:
  • collection (Organisms.GA.Collection) – This is the collection to use to determine if the genetic algorithm should epoch. This Collection should be the Population.

  • generation_number (int) – The number of the last successful generation

returns Should an epoch occur. True if yes, False if no. rtype bool.