catlearn.ga¶
catlearn.ga.algorithm¶
The GeneticAlgorithm class methods.
-
class
catlearn.ga.algorithm.
GeneticAlgorithm
(fit_func, features, targets, population_size='auto', population=None, operators=None, fitness_parameters=1, nsplit=2, accuracy=None, nprocs=1, dmax=None)¶ Bases:
object
Genetic algorithm for parameter optimization.
-
search
(steps, natural_selection=True, convergence_operator=None, repeat=5, verbose=False, writefile=None)¶ Do the actual search.
Parameters: - steps (int) – Maximum number of steps to be taken.
- natural_selection (bool) – A flag that when set True will perform natural selection.
- convergence_operator (object) – The function to perform the convergence check. If None is passed then the no_progress function is used.
- repeat (int) – Number of repeat generations with no progress.
- verbose (bool) – If True, will print out the progress of the search. Default is False.
- writefile (str) – Name of a json file to save data too.
-
population
¶ The current population.
Type: list
-
fitness
¶ The fitness for the current population.
Type: list
-
catlearn.ga.convergence¶
Functions to check for convergence in the GA.
-
class
catlearn.ga.convergence.
Convergence
¶ Bases:
object
Class to check convergence.
-
no_progress
(fitness, repeat)¶ Convergence based on a lack of any progress in the search.
Parameters: - fitness (array) – A List of fitnesses from the search.
- repeat (int) – Number of repeat generations with no progress.
Returns: converged – True if convergence has been reached, False otherwise.
Return type: bool
-
stagnation
(fitness, repeat)¶ Convergence based on a stagnation of the population.
Parameters: - fitness (array) – A List of fitnesses from the search.
- repeat (int) – Number of repeat generations with no progress.
Returns: converged – True if convergence has been reached, False otherwise.
Return type: bool
-
catlearn.ga.initialize¶
Function to initialize a population.
-
catlearn.ga.initialize.
initialize_population
(pop_size, dimension, dmax=None)¶ Generate a random starting population.
Parameters: - pop_size (int) – Population size.
- d_param (int) – Dimension of parameters in model.
catlearn.ga.io¶
Functions to read and write GA data.
-
catlearn.ga.io.
read_data
(writefile)¶ Funtion to read population and fitness.
Parameters: writefile (str) – Name of the JSON file to read. Returns: - population (array) – The population saved from a previous search.
- fitness (array) – The fitness associated with the saved population.
catlearn.ga.mating¶
Cut and splice mating function.
-
catlearn.ga.mating.
cut_and_splice
(parent_one, parent_two, index='random')¶ Perform cut_and_splice between two parents.
Parameters: - parent_one (list) – List of params for first parent.
- parent_two (list) – List of params for second parent.
- index (str) – Define how to choose size of each cut index.
Returns: offspring – A new child candidate from the two parents.
Return type: array
catlearn.ga.mutate¶
Define some mutation functions.
-
catlearn.ga.mutate.
probability_include
(parent_one)¶ A mutation that will include features with a certain probability.
Parameters: parent_one (list) – List of params for first parent. Returns: p1 – Mutated parameter list based on the parent parameters provided. Return type: list
-
catlearn.ga.mutate.
probability_remove
(parent_one)¶ A mutation that will remove features with a certain probability.
Parameters: parent_one (list) – List of params for first parent. Returns: p1 – Mutated parameter list based on the parent parameters provided. Return type: list
-
catlearn.ga.mutate.
random_permutation
(parent_one)¶ Perform a random permutation on a parameter index.
Parameters: parent_one (list) – List of params for first parent. Returns: p1 – Mutated parameter list based on the parent parameters provided. Return type: list
catlearn.ga.natural_selection¶
Functions to perform some natural selection.
-
catlearn.ga.natural_selection.
population_reduction
(pop, fit, population_size)¶ Method to reduce population size to constant.
Parameters: - pop (list) – Extended population.
- fit (list) – Extended fitness assignment.
- population_size (int) – The population size.
- pareto (bool) – Flag to specify whether search is for Pareto optimal set.
Returns: - population (list) – The population after natural selection.
- fitness (list) – The fitness for the current population.
-
catlearn.ga.natural_selection.
remove_duplicates
(population, fitness, accuracy)¶ Function to delete duplicate candidates based on fitness.
Parameters: - population (array) – The current population.
- fitness (array) – The fitness for the current population.
- accuracy (int) – Number of decimal places to include when finding unique.
Returns: - population (list) – The population after duplicates deleted.
- fitness (list) – The fitness for the population after duplicates deleted.
catlearn.ga.predictors¶
Some generic prediction functions.
-
catlearn.ga.predictors.
minimize_error
(train_features, train_targets, test_features, test_targets)¶ A generic fitness function.
This fitness function will minimize the cost function.
Parameters: - train_features (array) – The training features.
- train_targets (array) – The training targets.
- test_features (array) – The test feaatures.
- test_targets (array) – The test targets.
-
catlearn.ga.predictors.
minimize_error_descriptors
(train_features, train_targets, test_features, test_targets)¶ A generic fitness function.
This fitness function will minimize the cost function as well as the number of descriptors. This will provide a Pareto optimial set of solutions upon convergence.
Parameters: - train_features (array) – The training features.
- train_targets (array) – The training targets.
- test_features (array) – The test feaatures.
- test_targets (array) – The test targets.
-
catlearn.ga.predictors.
minimize_error_time
(train_features, train_targets, test_features, test_targets)¶ A generic fitness function.
This fitness function will minimize the cost function as well as the time to train the model. This will provide a Pareto optimial set of solutions upon convergence.
Parameters: - train_features (array) – The training features.
- train_targets (array) – The training targets.
- test_features (array) – The test feaatures.
- test_targets (array) – The test targets.