Ga
Ga
- class gaggle.ga.ga.GA(population_manager: PopulationManager = None, ga_args: GAArgs = None, selection: Selection = None, crossover: Crossover = None, mutation: Mutation = None, problem_args: ProblemArgs = None, sys_args: SysArgs = None, outdir_args: OutdirArgs = None, individual_args: IndividualArgs = None, problem: Problem = None)[source]
Bases:
object
The parent class for any GA. Is used to store all the information related to the GA algorithm and organize the order of the operators.
Ga_factory
- class gaggle.ga.ga_factory.GAFactory[source]
Bases:
object
Factory that generates pre-existing available GA algorithms. GAFactory.gas stores said GAs as a dictionary with their name as key and the uninitialized GA object as value.
- classmethod from_ga_args(population_manager: PopulationManager = None, ga_args: GAArgs = None, selection: Selection = None, crossover: Crossover = None, mutation: Mutation = None, problem_args: ProblemArgs = None, sys_args: SysArgs = None, outdir_args: OutdirArgs = None, individual_args: IndividualArgs = None, problem: Problem = None) GA [source]
Initializes the requested GA from the dictionary of available GAs.
This is done by using the attribute ga_args.ga_name as the lookup key to GAFactory.gas.
- Parameters:
population_manager –
ga_args –
selection –
crossover –
mutation –
problem_args –
sys_args –
outdir_args –
individual_args –
problem –
- Returns:
An initialized GA class object.
- gas = {'simple': <class 'gaggle.ga.simple_ga.SimpleGA'>}
Simple_ga
- class gaggle.ga.simple_ga.SimpleGA(population_manager: PopulationManager = None, ga_args: GAArgs = None, selection: Selection = None, crossover: Crossover = None, mutation: Mutation = None, problem_args: ProblemArgs = None, sys_args: SysArgs = None, outdir_args: OutdirArgs = None, individual_args: IndividualArgs = None, problem: Problem = None)[source]
Bases:
GA
Implements a Simple Genetic Algorithm following Mitchell.
- display_metrics(display_train: bool = True, display_test: bool = True)[source]
Displays the metrics computed and stored in self.saved_metrics. Only displays and saves the metrics whose keys are in self.metrics_to_plot. The graphs are also saved to a file in the output folder specified in outdir_args.
- Parameters:
display_train –
display_test –
Returns:
- get_fitness_metric(fitness: dict[slice(<class 'int'>, <class 'float'>, None)], save: bool = False, mode: str = 'train')[source]
Outputs basic fitness metrics for a population, like avg fitness, best & worst fitness :param fitness: dictionary of fitness :param save: whether to save the metrics :param mode: what to save :return: metrics: dictionary of metrics
- save_individual(individual: Individual, fitness)[source]
Saves the individual provided as well as its fitness to the folder path specified in the outdir_args as ‘best.pt’.
- Parameters:
individual –
fitness –
Returns:
- save_metrics(save_train: bool = True, save_test: bool = True)[source]
Saves the metrics computed and stored in self.saved_metrics. The metrics are saved to files in the output folder specified in outdir_args.
- Parameters:
save_train –
save_test –
Returns:
- test(save: bool = True)[source]
Tests population by computing the fitness and its associated metrics without updating the population manager.
- Parameters:
save –
Returns:
- train(test: bool = True, callbacks: List[Callable] = None, display_train_metrics: bool = True, display_test_metrics: bool = True)[source]
Call to begin the training process of the population using the arguments stored in this SimpleGA object.
- Parameters:
test –
callbacks –
display_train_metrics –
display_test_metrics –
Returns: