bingo.evolutionary_optimizers package#
Submodules#
bingo.evolutionary_optimizers.archipelago module#
The abstract-base class for the Archipelago.
This module defines the data structure that manages a group of Islands. Archipelago implementations will control the generational steps for all the islands until convergence or until a maximal number of steps is reached.
- class bingo.evolutionary_optimizers.archipelago.Archipelago(num_islands, hall_of_fame=None, test_function=None)#
Bases:
EvolutionaryOptimizer
A collection of islands
Evolution of the Archipelago involves independent evolution of Islands combined with periodic migration of individuals between random pairs of islands.
- Parameters:
template_island (Island) – Island that will be used as a template for islands in the archipelago
num_islands (int) – The size of the archipelago; the number of islands it contains
- generational_age#
The number of generations the archipelago has been evolved
- Type:
int
- hall_of_fame#
An object containing the best individuals seen in the archipelago
- Type:
bingo.evolutionary_optimizers.checkpoint_controller module#
This module is a helper class for controlling times of checkpoints in a time-controlled evolutionary optimization.
- class bingo.evolutionary_optimizers.checkpoint_controller.CheckpointController(start_time, max_time, convergence_check_frequency, safety_factor=0.98)#
Bases:
object
Controller for times between checkpoints
- Parameters:
start_time (datetime) – starting time of the optimization
max_time (float) – maximum allowed time of optimization in seconds
convergence_check_frequency (int) – number of evolutionary generations between standard checkpoints
safety_factor (float, optional) – favctor by which to reuce maximum time to help ensure finishing on time, by default 0.97
- estimate_remaining_checkpoints()#
Estimate number of checkpoints that can be performed before time limit
- Returns:
estimated number of checkpoints that can be performed, can be fractional
- Return type:
float
- get_gens_to_evolve()#
Calculate the number of generations for next checkpoint
Returns the default value unless a fractional-sized checkpoint is needed to stay under the time limit
- Returns:
number of generations to evolve before next checkpoint
- Return type:
int
- record_check(num_generations)#
Records that a checkpoint has just been reached
- Parameters:
num_generations (int) – the number of generations that were evolved since the last checkpoint
bingo.evolutionary_optimizers.evolutionary_optimizer module#
This module contains the basic structure for evolutionary optimization in bingo. The general framework allows access to an evolve_until_convergence function.
- class bingo.evolutionary_optimizers.evolutionary_optimizer.EvolutionaryOptimizer(hall_of_fame=None, test_function=None)#
Bases:
object
Fundamental bingo object that coordinates evolutionary optimization
Abstract base class for evolutionary optimization. The primary role of this class is to house the evolve_until_convergence function. Classes which extend this one will have access to this function’s capability.
- Parameters:
hall_of_fame (HallOfFame (optional)) – The hall of fame object to be used for storing best individuals
- generational_age#
The number of generations the optimizer has been evolved
- Type:
int
- hall_of_fame#
(optional) An object containing the best individuals seen in the optimization
- Type:
HallOfFame
- test_function#
(optional) A function which can judges the fitness of an individual, independent of the FitnessFunction used in evolution
- Type:
FitnessFunction
- dump_to_file(filename)#
Dump the evolutionary_optimizers object to a pickle file
- Parameters:
filename (str) – the name of the pickle file to dump
- evolve(num_generations, hall_of_fame_update=True, suppress_logging=False)#
The function responsible for generational evolution.
- Parameters:
num_generations (int) – The number of generations to evolve
hall_of_fame_update (bool (optional)) – Used to manually turn on or off the hall of fame update. Default True.
suppress_logging (bool (optional)) – Used to manually suppress the logging output of this function
- evolve_until_convergence(max_generations, fitness_threshold, convergence_check_frequency=1, min_generations=0, stagnation_generations=None, max_fitness_evaluations=None, max_time=None, checkpoint_base_name=None, num_checkpoints=None)#
Evolution occurs until one of four convergence criteria is met
- Convergence criteria:
a maximum number of generations have been evolved
a fitness below an absolute threshold has been achieved
improvement upon best fitness has not occurred for a set number of generations
the maximum number of fitness function evaluations has been reached
- Parameters:
max_generations (int) – The maximum number of generations the optimization will run.
fitness_threshold (float) – The minimum fitness that must be achieved in order for the algorithm to converge.
convergence_check_frequency (int, default 1) – The number of generations that will run between checking for convergence.
min_generations (int, default 0) – The minimum number of generations the algorithm will run.
stagnation_generations (int) – (optional) The number of generations after which evolution will stop if no improvement is seen.
max_fitness_evaluations (int) – (optional) The maximum number of fitness function evaluations (approximately) the optimizer will run.
max_time (float) – (optional) The time limit for the evolution, in seconds.
checkpoint_base_name (str) – (optional) base file name for checkpoint files
num_checkpoints (int) – (optional) number of recent checkpoints to keep, previous ones are removed
- Returns:
Object containing information about the result of the evolution
- Return type:
OptimizeResult
- abstract get_best_fitness()#
Gets the fitness value of the most fit individual
- Returns:
fitness – Fitness of best individual
- Return type:
numeric
- abstract get_best_individual()#
Gets the most fit individual
- Returns:
Best individual
- Return type:
chromosomes
- abstract get_ea_diagnostic_info()#
Gets diagnostic info from the evolutionary algorithm(s)
- Returns:
summary of evolutionary algorithm diagnostics
- Return type:
- abstract get_fitness_evaluation_count()#
Gets the number of fitness evaluations performed
- Returns:
number of fitness evaluations
- Return type:
int
- update_hall_of_fame()#
Manually update the hall of fame
- class bingo.evolutionary_optimizers.evolutionary_optimizer.OptimizeResult(success, status, message, ngen, fitness, time, ea_diagnostics)#
Bases:
tuple
- ea_diagnostics#
Alias for field number 6
- fitness#
Alias for field number 4
- message#
Alias for field number 2
- ngen#
Alias for field number 3
- status#
Alias for field number 1
- success#
Alias for field number 0
- time#
Alias for field number 5
- bingo.evolutionary_optimizers.evolutionary_optimizer.load_evolutionary_optimizer_from_file(filename)#
Load an evolutionary_optimizers object from a pickle file
- Parameters:
filename (str) – the name of the pickle file to load
- Returns:
an evolutionary optimizer
- Return type:
str
bingo.evolutionary_optimizers.fitness_predictor module#
This module contains the utilities for fitness predictors.
Fitness predictors in bingo are chromosomes that encode information necessary to make a prediction of fitness for other chromosomes types. The type of fitness predictors used here are subset fitness predictors, which make a prediction of fitness by using only a subset of the training data used in preforming a full/true fitness calculation. Subset fitness predictors use the MultipleValueChromosome.
Check out the works of the works of Schmidt and Lipson for more details: e.g., “Coevolution of Fitness Predictors” (2008) .
- class bingo.evolutionary_optimizers.fitness_predictor.FitnessPredictorFitnessFunction(training_data, full_fitness_function, potential_trainers, num_trainers)#
Bases:
FitnessFunction
A fitness function for subset fitness predictors
A fitness function for fitness predictors. The fitness of a fitness predictor is based upon its ability to predict true/full fitness of trainer individuals.
- Parameters:
training_data (TrainingData) – Training data used in full/true fitness evaluation
full_fitness_function (FitnessFunction) – The fitness function to be used in prediction (based on the training data)
potential_trainers (list of Chromosome) – a list of individuals that could potentially be used as trainers
num_trainers (int) – number of trainers to use
- add_trainer(trainer)#
Add a trainer to the trainer population
Replaces one of the current trainers.
- Parameters:
trainer (Chromosome) – individual to add to the training population
- get_true_fitness_for_trainer(trainer)#
Gets true (full) fitness of trainer
True fitness is the fitness calculated using the entire set of training data.
- Parameters:
trainer (chromosomes) – The chromosome to be evaluated
- Returns:
fitness – true (full) fitness of trainer
- Return type:
numeric
- predict_fitness_for_trainer(individual, trainer)#
Get predicted value of fitness for a trainer
- Parameters:
individual (MultipleValueChromosome) – subset fitness predictor to use in calculating predicted fitness
trainer (Chromosome) – the trainer of which to calculate fitness
- Returns:
predicted fitness
- Return type:
float
- class bingo.evolutionary_optimizers.fitness_predictor.FitnessPredictorIndexGenerator(data_size)#
Bases:
object
Generator of ints within a range
- Parameters:
data_size (int) – maximum value of randomly generated int (exclusive)
bingo.evolutionary_optimizers.fitness_predictor_island module#
An Island implementation using fitness predictors
The primary goal of this island is to be more computationally efficient than the simple Island in cases where lots of TrainingData is needed for fitness evaluation. Fitness predictors use a subset of that training data to make a prediction of what fitness would be using the whole data set.
The fitness predictors are evolved concurrently with the main island population so that their predictive power is growing as the population becomes more fit. A full description of the method can be found in the works of Schmidt and Lipson [1].
- class bingo.evolutionary_optimizers.fitness_predictor_island.FitnessPredictorIsland(evolution_algorithm, generator, population_size, predictor_population_size=16, predictor_update_frequency=50, predictor_size_ratio=0.1, predictor_computation_ratio=0.1, trainer_population_size=16, trainer_update_frequency=50, hall_of_fame=None, test_function=None)#
Bases:
Island
An island utilizing co-evolving fitness predictors
The coevolution of fitness predictors is a evolutionary scheme meant to reduce computation cost and reduce overfitting and bloat. It is similar in spirit to the use of mini-batches in stochastic gradient descent.
- Parameters:
evolution_algorithm (EvolutionaryAlgorithm) – The desired algorithm to use in assessing the population
generator (Generator) – The generator class that returns an instance of a chromosome
population_size (int) – The desired size of the population
predictor_population_size (int (Optional)) – The number of co-evolving fitness predictors. Default is 16.
predictor_update_frequency (int (Optional)) – The number of generations between updates to the main fitness function. Default is 50.
predictor_size_ratio (float (0 - 1] (Optional)) – The fraction of the training data that will be used by fitness predictors. Default is 0.1.
predictor_computation_ratio (float [0 - 1) (Optional)) – The fraction of total computation that is devoted to evolution of fitness predictors. Default is 0.1.
trainer_population_size (int (Optional)) – The number of individuals used in training of fitness predictors. Default is 16.
trainer_update_frequency (int (Optional)) – The number of generations between updates to the trainer population. Default is 50.
hall_of_fame (HallOfFame (Optional)) – The hall of fame object to be used for storing best individuals
- generational_age#
The number of generational steps that have been executed
- Type:
int
- population#
The population that is evolving
- Type:
list of chromosomes
- hall_of_fame#
An object containing the best individuals seen in the optimization
- Type:
- get_best_individual()#
Finds the individual with the lowest fitness in a population.
This assures that the fitness is the true fitness value and not the predicted fitness.
- Returns:
best – The chromosomes with the lowest fitness value
- Return type:
chromosomes
- property hall_of_fame#
The hall of fame object which is updated during evolution
bingo.evolutionary_optimizers.island module#
This module contains the code for an island in an island-based GA optimization
it is general enough to work on any representation/fitness
- class bingo.evolutionary_optimizers.island.Island(evolution_algorithm, generator, population_size, hall_of_fame=None, test_function=None)#
Bases:
EvolutionaryOptimizer
Island: a basic unit of evolutionary optimization. It performs the generation and evolution of a single population using a generator and evolutionary algorithm, respectively.
- Parameters:
evolution_algorithm (EvolutionaryAlgorithm) – The desired algorithm to use in assessing the population
generator (Generator) – The generator class that returns an instance of a chromosome
population_size (int) – The desired size of the population
hall_of_fame (HallOfFame) – (optional) The hall of fame object to be used for storing best individuals
- generational_age#
The number of generational steps that have been executed
- Type:
int
- population#
The population that is evolving
- Type:
list of chromosomes
- hall_of_fame#
An object containing the best individuals seen in the optimization
- Type:
HallOfFame
- test_function#
(optional) A function which can judges the fitness of an individual, independent of the FitnessFunction used in evolution
- Type:
FitnessFunction
- dump_fraction_of_population(fraction)#
Dumps a portion of the population to a list
- Parameters:
fraction (float [0.0 - 1.0]) – The fraction of the population to dump
- Returns:
A portion of the population
- Return type:
list of chromosomes
- evaluate_population()#
Manually trigger evaluation of population
- get_best_fitness()#
finds the fitness value of the most fit individual
- Returns:
fitness – Fitness of best individual
- Return type:
numeric
- get_best_individual()#
Finds the individual with the lowest fitness in a population
- Returns:
best – The chromosomes with the lowest fitness value
- Return type:
chromosomes
- get_ea_diagnostic_info()#
Gets diagnostic info from the evolutionary algorithm(s)
- Returns:
summary of evolutionary algorithm diagnostics
- Return type:
- get_fitness_evaluation_count()#
Gets the number of fitness evaluations performed
- Returns:
number of fitness evaluations
- Return type:
int
- regenerate_population()#
Randomly regenerates the population
- reset_fitness(population=None)#
Mark each individual in the population as needing fitness evaluation
- Parameters:
population (list of Chromosome) – (Optional) Population to be reset. Default: the island’s current population
bingo.evolutionary_optimizers.parallel_archipelago module#
The parallel implementation of the Archipelago
This module defines the Archipelago data structure that runs in parallel on multiple processors.
- class bingo.evolutionary_optimizers.parallel_archipelago.ParallelArchipelago(island, hall_of_fame=None, non_blocking=True, sync_frequency=10, test_function=None)#
Bases:
Archipelago
A collection of islands that evolves in parallel
Evolution of the Archipelago involves independent evolution of Islands combined with periodic migration of individuals between random pairs of islands. Each mpi process is responsible for the evolution of a single island which has two effects:
scaling to more islands requires use of more processes
scripts written for the Parallel Archipelago should be independent of the number of processors: i.e., scripts don’t need to be changed in order to run with more processors. Simply run the same script with more mpi processes.
- Parameters:
island (Island) – The island that the processor will evolve
non_blocking (bool) – Specifies whether to use blocking or non-blocking execution. Default is non-blocking (True).
sync_frequency (int, optional) – How frequently to update the average age for each island. Default 10.
- island#
The island where the current processor’s evolution occurs
- Type:
Island
- generational_age#
The number of generations the archipelago has been evolved
- Type:
int
- hall_of_fame#
An object containing the best individuals seen in the archipelago
- Type:
- dump_to_file(filename)#
Dump the ParallelArchipelago object to a pickle file
The file will contain a pickle dump of a list of all the processors’ ParallelArchipelago objects.
- Parameters:
filename (str) – the name of the pickle file to dump
- get_best_fitness()#
Gets the fitness of most fit member
- Returns:
fitness – Fitness of best individual in the archipelago
- Return type:
numeric
- get_best_individual()#
Returns the best individual
- Returns:
The individual with lowest fitness
- Return type:
chromosomes
- get_ea_diagnostic_info()#
Gets diagnostic info from the evolutionary algorithm(s)
- Returns:
summary of evolutionary algorithm diagnostics
- Return type:
- get_fitness_evaluation_count()#
Gets the total number of fitness evaluations performed
- Returns:
number of fitness evaluations
- Return type:
int
- bingo.evolutionary_optimizers.parallel_archipelago.load_parallel_archipelago_from_file(filename)#
Load a ParallelArchipelago objects from a pickle file
- Parameters:
filename (str) – the name of the pickle file to load
- Returns:
an evolutionary optimizer
- Return type:
str
bingo.evolutionary_optimizers.serial_archipelago module#
The serial implementation of the Archipelago
This module defines the Archipelago data structure that runs serially on one processor.
- class bingo.evolutionary_optimizers.serial_archipelago.SerialArchipelago(template_island, num_islands=2, hall_of_fame=None, test_function=None)#
Bases:
Archipelago
An collection of islands that evolve serially.
Evolution of the Archipelago involves independent evolution of Islands combined with periodic migration of individuals between random pairs of islands. The evolution occurs on one Island at a time.
- Parameters:
template_island (Island) – The island that acts as a template for all islands in the archipelago
num_islands (int) – The number of islands to create in the archipelago’s list of islands
- islands#
direct access to the islands in the archipelago
- Type:
list of Island
- generational_age#
The number of generations the archipelago has been evolved
- Type:
int
- hall_of_fame#
An object containing the best individuals seen in the archipelago
- Type:
- get_best_fitness()#
Gets the fitness of most fit member
- Returns:
fitness – Fitness of best individual in the archipelago
- Return type:
numeric
- get_best_individual()#
Returns the best individual
- Returns:
The individual with lowest fitness
- Return type:
Chromosome
- get_ea_diagnostic_info()#
Gets diagnostic info from the evolutionary algorithm(s)
- Returns:
summary of evolutionary algorithm diagnostics
- Return type:
EaDiagnosticsSummary
- get_fitness_evaluation_count()#
Gets the number of fitness evaluations performed
- Returns:
number of fitness evaluations
- Return type:
int