OpenNN
2.2
Open Neural Networks Library
|
#include <evolutionary_algorithm.h>
Classes | |
struct | EvolutionaryAlgorithmResults |
Public Types | |
enum | FitnessAssignmentMethod { LinearRanking } |
enum | SelectionMethod { RouletteWheel } |
enum | RecombinationMethod { Line, Intermediate } |
enum | MutationMethod { Normal, Uniform } |
Additional Inherited Members | |
Protected Attributes inherited from OpenNN::TrainingAlgorithm | |
PerformanceFunctional * | performance_functional_pointer |
size_t | display_period |
size_t | save_period |
std::string | neural_network_file_name |
bool | display |
This concrete class represents an evolutionary training algorithm for a performance functional of a neural network.
Definition at line 40 of file evolutionary_algorithm.h.
|
explicit |
Default constructor. It creates a evolutionary training algorithm not associated to any performance functional. It also initializes the class members to their default values.
Definition at line 27 of file evolutionary_algorithm.cpp.
|
explicit |
Performance functional constructor. It creates a evolutionary training algorithm associated to a performance functional. It also initializes the class members to their default values.
new_performance_functional_pointer | Pointer to a performance functional object. |
Definition at line 40 of file evolutionary_algorithm.cpp.
|
explicit |
XML constructor. It creates a evolutionary training algorithm not associated to any performance functional. It also loads the class members from a XML document.
evolutionary_algorithm_document | TinyXML document with the evolutionary algorithm object members. |
Definition at line 54 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::evaluate_population | ( | void | ) |
Evaluates the performance functional of all individuals in the population. Results are stored in the performance vector.
Definition at line 2064 of file evolutionary_algorithm.cpp.
|
virtual |
Loads a evolutionary algorithm object from a XML document. Please mind about the file format, wich is specified in the User's Guide.
document | TinyXML document with the evolutionary algorithm object members. |
Reimplemented from OpenNN::TrainingAlgorithm.
Definition at line 3678 of file evolutionary_algorithm.cpp.
const double & OpenNN::EvolutionaryAlgorithm::get_best_performance_goal | ( | void | ) | const |
Returns the goal value for the performance. This is used as a stopping criterion when training a multilayer perceptron
Definition at line 317 of file evolutionary_algorithm.cpp.
const double & OpenNN::EvolutionaryAlgorithm::get_error_parameters_norm | ( | void | ) | const |
Returns the value for the norm of the parameters vector at wich an error message is written to the screen and the program exits.
Definition at line 306 of file evolutionary_algorithm.cpp.
Vector< double > OpenNN::EvolutionaryAlgorithm::get_individual | ( | const size_t & | i | ) | const |
Returns the Vector of parameters corresponding to the individual i in the population.
i | Index of individual in the population. |
Definition at line 1086 of file evolutionary_algorithm.cpp.
const bool & OpenNN::EvolutionaryAlgorithm::get_reserve_best_norm_history | ( | void | ) | const |
Returns true if the norm of the best individual in the population history vector is to be reserved, and false otherwise.
Definition at line 409 of file evolutionary_algorithm.cpp.
const bool & OpenNN::EvolutionaryAlgorithm::get_reserve_standard_deviation_norm_history | ( | void | ) | const |
Returns true if the standard deviation of the population norm history vector is to be reserved, and false otherwise.
Definition at line 398 of file evolutionary_algorithm.cpp.
const bool & OpenNN::EvolutionaryAlgorithm::get_reserve_standard_deviation_performance_history | ( | void | ) | const |
Returns true if the standard deviation of the performance history vector is to be reserved, and false otherwise.
Definition at line 430 of file evolutionary_algorithm.cpp.
const double & OpenNN::EvolutionaryAlgorithm::get_warning_parameters_norm | ( | void | ) | const |
Returns the minimum value for the norm of the parameters vector at wich a warning message is written to the screen.
Definition at line 295 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::initialize_population | ( | const double & | new_value | ) |
Initializes the population matrix with a given value.
new_value | Initialization value. |
Definition at line 1733 of file evolutionary_algorithm.cpp.
|
virtual |
Default random initialization for a training algorithm object. It just sets a random display value.
Reimplemented from OpenNN::TrainingAlgorithm.
Definition at line 4084 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::perform_intermediate_recombination | ( | void | ) |
Performs inediate recombination between pairs of selected individuals to generate a new population. Each selected individual is to be recombined with two other selected individuals chosen at random. Results are stored in the population matrix.
Definition at line 2259 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::perform_line_recombination | ( | void | ) |
Performs line recombination between pairs of selected individuals to generate a new population. Each selected individual is to be recombined with two other selected individuals chosen at random. Results are stored in the population matrix.
Definition at line 2387 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::perform_linear_ranking_fitness_assignment | ( | void | ) |
Ranks all individuals in the population by their performance, so that the least fit individual has rank 1 and the fittest individual has rank [population size]. It then assigns them a fitness value linearly proportional to their rank. The smallest fitness corresponds to the smallest performance, and the greatest fitness to the greatest performance. Results are stored in the fitness vector.
Definition at line 2141 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::perform_normal_mutation | ( | void | ) |
Performs normal mutation to all individuals in order to generate a new population. Results are stored in the population matrix.
Definition at line 2512 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::perform_roulette_wheel_selection | ( | void | ) |
This metod performs selection with roulette wheel selection. It selects half of the individuals from the population. Results are stored in the selection vector.
Definition at line 2165 of file evolutionary_algorithm.cpp.
|
virtual |
Trains a neural network with an associated performance function according to the evolutionary algorithm. Training occurs according to the training operators and their related parameters.
Implements OpenNN::TrainingAlgorithm.
Definition at line 2866 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::perform_uniform_mutation | ( | void | ) |
Performs uniform mutation to all individuals in order to generate a new population. Results are stored in the population matrix.
Definition at line 2550 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::randomize_population_normal | ( | void | ) |
Initializes the parameters of all the individuals in the population with random values chosen from a normal distribution with mean 0 and standard deviation 1.
Definition at line 1817 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::randomize_population_normal | ( | const double & | mean, |
const double & | standard_deviation | ||
) |
Initializes the parameters of all the individuals in the population with random values chosen from a normal distribution with a given mean and a given standard deviation.
mean | Mean of normal distribution. |
standard_deviation | Standard deviation of normal distribution. |
Definition at line 1831 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::randomize_population_normal | ( | const Vector< double > & | mean, |
const Vector< double > & | standard_deviation | ||
) |
Initializes the parameters of all the individuals in the population with random values chosen from normal distributions with different mean and standard deviation for each free parameter.
Definition at line 1846 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::randomize_population_uniform | ( | void | ) |
Initializes the parameters of all the individuals in the population at random, with values comprised between -1 and 1.
Definition at line 1745 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::randomize_population_uniform | ( | const double & | minimum, |
const double & | maximum | ||
) |
Initializes the parameters of all the individuals in the population at random, with values comprised between a minimum and a maximum value.
minimum | Minimum initialization value. |
maximum | Maximum initialization value. |
Definition at line 1759 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::randomize_population_uniform | ( | const Vector< double > & | minimum, |
const Vector< double > & | maximum | ||
) |
Initializes the parameters of all the individuals in the population at random, with values comprised between different minimum and maximum values for each variable.
minimum | Vector of minimum initialization values. |
maximum | Vector of maximum initialization values. |
Definition at line 1773 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set | ( | void | ) |
Sets the performance functional pointer of this object to NULL. It also sets the rest of members to their default values.
Definition at line 451 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set | ( | PerformanceFunctional * | new_performance_functional_pointer | ) |
Sets a new performance functional pointer to the evolutionary algorithm object. It also sets the rest of members to their default values.
Definition at line 464 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_best_performance_goal | ( | const double & | new_best_performance_goal | ) |
Sets a new goal value for the performance. This is used as a stopping criterion when training a multilayer perceptron.
new_best_performance_goal | Goal value for the performance. |
Definition at line 1243 of file evolutionary_algorithm.cpp.
|
virtual |
Sets the members of the evolutionary algorithm object to their default values. Training operators:
Training parameters:
Stopping criteria:
Training history:
User stuff:
Reimplemented from OpenNN::TrainingAlgorithm.
Definition at line 515 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_display_period | ( | const size_t & | new_display_period | ) |
Sets a new number of iterations between the training showing progress.
new_display_period | Number of iterations between the training showing progress. |
Definition at line 1320 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_elitism_size | ( | const size_t & | new_elitism_size | ) |
Sets a new elitism size to the evolutionary algorithm. The elitism size is the number of individuals which will always be selected for recombination.
new_elitism_size | Elitism size to be set. |
Definition at line 1479 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_error_parameters_norm | ( | const double & | new_error_parameters_norm | ) |
Sets a new value for the parameters vector norm at which an error message is written to the screen and the program exits.
new_error_parameters_norm | Error norm of parameters vector value. |
Definition at line 1212 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_fitness | ( | const Vector< double > & | new_fitness | ) |
Sets a new population fitness vector.
new_fitness | Population fitness values. |
Definition at line 887 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_fitness_assignment_method | ( | const FitnessAssignmentMethod & | new_fitness_assignment_method | ) |
Sets a new fitness assignment method to be used for training.
new_fitness_assignment_method | Fitness assignment method chosen for training. |
Definition at line 1684 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_fitness_assignment_method | ( | const std::string & | new_fitness_assignment_method_name | ) |
Sets a new method for fitness assignment from a string containing the name. Possible values are:
new_fitness_assignment_method_name | String with name of method for fitness assignment. |
Definition at line 681 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_individual | ( | const size_t & | i, |
const Vector< double > & | individual | ||
) |
Sets a new Vector of parameters to the individual i in the population.
i | Index of individual in the population. |
individual | Vector of parameters to be assigned to individual i. |
Definition at line 1122 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_maximum_generalization_performance_decreases | ( | const size_t & | new_maximum_generalization_performance_decreases | ) |
Sets a new maximum number of generalization failures.
new_maximum_generalization_performance_decreases | Maximum number of iterations in which the generalization evalutation decreases. |
Definition at line 1254 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_maximum_generations_number | ( | const size_t & | new_maximum_generations_number | ) |
Sets a new value for the maximum number of generations to perform_training. The maximum number of generations value must be a positive number.
new_maximum_generations_number | Maximum number of generations value. |
Definition at line 1611 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_maximum_time | ( | const double & | new_maximum_time | ) |
Sets a new maximum training time.
new_maximum_time | Maximum training time. |
Definition at line 1265 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_mean_performance_goal | ( | const double & | new_mean_performance_goal | ) |
Sets a new value for the mean performance goal stopping criterion.
new_mean_performance_goal | Goal value for the mean performance of the population. |
Definition at line 1642 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_mutation_method | ( | const MutationMethod & | new_mutation_method | ) |
Sets a new mutation method to be used for training.
new_mutation_method | Mutation method chosen for training. |
Definition at line 1722 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_mutation_method | ( | const std::string & | new_mutation_method_name | ) |
Sets a new method for mutation from a string containing the name. Possible values are:
new_mutation_method_name | String with name of method for mutation. |
Definition at line 771 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_mutation_range | ( | const double & | new_mutation_range | ) |
Sets a new value for the mutation range parameter. The mutation range value must be 0 or a positive number.
new_mutation_range | Mutation range value. This must be equal or greater than 0. |
Definition at line 1584 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_mutation_rate | ( | const double & | new_mutation_rate | ) |
Sets a new value for the mutation rate parameter. The mutation rate value must be between 0 and 1.
new_mutation_rate | Mutation rate value. This value must lie in the interval [0,1]. |
Definition at line 1556 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_performance | ( | const Vector< double > & | new_performance | ) |
Sets a new population performance vector.
new_performance | Population performance values. |
Definition at line 854 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_population | ( | const Matrix< double > & | new_population | ) |
Sets a new population.
new_population | Population Matrix. |
Definition at line 800 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_population_size | ( | const size_t & | new_population_size | ) |
Sets a new population with a new number of individuals. The new population size must be an even number equal or greater than four.
new_population_size | Number of individuals in the population. This must be an even number equal or greater than four. |
Definition at line 585 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_recombination_method | ( | const RecombinationMethod & | new_recombination_method | ) |
Sets a new recombination method to be used for training.
new_recombination_method | Recombination method chosen for training. |
Definition at line 1710 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_recombination_method | ( | const std::string & | new_recombination_method_name | ) |
Sets a new method for recombination from a string containing the name. Possible values are:
new_recombination_method_name | String with name of method for recombination. |
Definition at line 738 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_recombination_size | ( | const double & | new_recombination_size | ) |
Sets a new value for the recombination size parameter. The recombination size value must be equal or greater than 0.
new_recombination_size | Recombination size value. This must be equal or greater than 0. |
Definition at line 1530 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_all_training_history | ( | const bool & | new_reserve_all_training_history | ) |
Makes the training history of all variables to reseved or not in memory.
new_reserve_all_training_history | True if the training history of all variables is to be reserved, false otherwise. |
Definition at line 1056 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_best_individual_history | ( | const bool & | new_reserve_best_individual_history | ) |
Makes the best individual history vector of vectors to be reseved or not in memory.
new_reserve_best_individual_history | True if the best individual history vector of vectors is to be reserved, false otherwise. |
Definition at line 965 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_best_norm_history | ( | const bool & | new_reserve_best_norm_history | ) |
Makes the best norm history vector to be reseved or not in memory.
new_reserve_best_norm_history | True if the best norm history vector is to be reserved, false otherwise. |
Definition at line 1003 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_best_performance_history | ( | const bool & | new_reserve_best_performance_history | ) |
Makes the best performance history vector to be reseved or not in memory.
new_reserve_best_performance_history | True if the best performance history vector is to be reserved, false otherwise. |
Definition at line 1043 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_elapsed_time_history | ( | const bool & | new_reserve_elapsed_time_history | ) |
Makes the elapsed time over the iterations to be reseved or not in memory. This is a vector.
new_reserve_elapsed_time_history | True if the elapsed time history vector is to be reserved, false otherwise. |
Definition at line 1296 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_generalization_performance_history | ( | const bool & | new_reserve_generalization_performance_history | ) |
Makes the Generalization performance history to be reserved or not in memory. This is a vector.
new_reserve_generalization_performance_history | True if the Generalization performance history is to be reserved, false otherwise. |
Definition at line 1308 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_mean_norm_history | ( | const bool & | new_reserve_mean_norm_history | ) |
Makes the mean norm history vector to be reseved or not in memory.
new_reserve_mean_norm_history | True if the mean norm history vector is to be reserved, false otherwise. |
Definition at line 977 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_mean_performance_history | ( | const bool & | new_reserve_mean_performance_history | ) |
Makes the mean performance history vector to be reseved or not in memory.
new_reserve_mean_performance_history | True if the mean performance history vector is to be reserved, false otherwise. |
Definition at line 1016 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_population_history | ( | const bool & | new_reserve_population_history | ) |
Makes the population history vector of matrices to be reseved or not in memory.
new_reserve_population_history | True if the population history vector of matrices is to be reserved, false otherwise. |
Definition at line 953 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_standard_deviation_norm_history | ( | const bool & | new_reserve_standard_deviation_norm_history | ) |
Makes the standard deviation norm history vector to be reseved or not in memory.
new_reserve_standard_deviation_norm_history | True if the standard deviation norm history vector is to be reserved, false otherwise. |
Definition at line 991 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_reserve_standard_deviation_performance_history | ( | const bool & | new_reserve_standard_deviation_performance_history | ) |
Makes the standard deviation performance history vector to be reseved or not in memory.
new_reserve_standard_deviation_performance_history | True if the standard deviation performance history vector is to be reserved, false otherwise. |
Definition at line 1030 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_selection | ( | const Vector< bool > & | new_selection | ) |
Sets a new population selection vector.
new_selection | Population selection values. |
Definition at line 920 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_selection_method | ( | const SelectionMethod & | new_selection_method | ) |
Sets a new selection method to be used for training.
new_selection_method | Selection method chosen for training. |
Definition at line 1697 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_selection_method | ( | const std::string & | new_selection_method_name | ) |
Sets a new method for selection from a string containing the name. Possible values are:
new_selection_method_name | String with name of method for selection. |
Definition at line 709 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_selective_pressure | ( | const double & | new_selective_pressure | ) |
Sets a new value for the selective pressure parameter. Linear ranking allows values for the selective pressure greater than 0.
new_selective_pressure | Selective pressure value. |
Definition at line 1504 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_standard_deviation_performance_goal | ( | const double & | new_standard_deviation_performance_goal | ) |
Sets a new value for the standard deviation performance goal stopping criterion.
new_standard_deviation_performance_goal | Goal for the standard deviation performance of the population. |
Definition at line 1653 of file evolutionary_algorithm.cpp.
void OpenNN::EvolutionaryAlgorithm::set_warning_parameters_norm | ( | const double & | new_warning_parameters_norm | ) |
Sets a new value for the parameters vector norm at which a warning message is written to the screen.
new_warning_parameters_norm | Warning norm of parameters vector value. |
Definition at line 1181 of file evolutionary_algorithm.cpp.
|
virtual |
Returns a default (empty) string matrix containing the members of the training algorithm object.
Reimplemented from OpenNN::TrainingAlgorithm.
Definition at line 3221 of file evolutionary_algorithm.cpp.
|
virtual |
Prints to the screen the members of the evolutionary algorithm object.
Training operators:
Training parameters:
Stopping criteria:
User stuff:
Population matrix.
Reimplemented from OpenNN::TrainingAlgorithm.
Definition at line 3413 of file evolutionary_algorithm.cpp.
|
private |
Elitism size. It represents the number of individuals which will always be selected for recombination. This is a parameter of the selection operator.
Definition at line 461 of file evolutionary_algorithm.h.
|
private |
Number of generations where the generalization performance decreases. This is an early stopping method for improving generalization.
Definition at line 519 of file evolutionary_algorithm.h.
|
private |
Target value for the mean performance of the population. It is used as a stopping criterion.
Definition at line 501 of file evolutionary_algorithm.h.
|
private |
Mutation range. The mutation range value must be 0 or a positive number. This is a parameter of the mutation operator.
Definition at line 485 of file evolutionary_algorithm.h.
|
private |
Mutation rate. The mutation rate value must be between 0 and 1. This is a parameter of the mutation operator.
Definition at line 479 of file evolutionary_algorithm.h.
|
private |
Recombination size. The recombination size value must be equal or greater than 0. This is a parameter of the recombination operator.
Definition at line 473 of file evolutionary_algorithm.h.
|
private |
True if the history of the best individual ever is to be reserved, and false otherwise. The best individual history is a vector of vectors.
Definition at line 536 of file evolutionary_algorithm.h.
|
private |
True if the population history, which is a vector of matrices, is to be reserved, false otherwise. Reserving the population history can be compuationally expensive if the number of parameters, the population size and the number of generations are big numbers.
Definition at line 531 of file evolutionary_algorithm.h.
|
private |
Selective pressure. Linear ranking allows values for the selective pressure greater than 0. This is a parameter of the selection operator.
Definition at line 467 of file evolutionary_algorithm.h.
|
private |
Target value for the standard deviation of the population performance. It is used as a stopping criterion.
Definition at line 506 of file evolutionary_algorithm.h.