OpenNN  2.2
Open Neural Networks Library
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
OpenNN::GeneticAlgorithm Class Reference

#include <genetic_algorithm.h>

Inheritance diagram for OpenNN::GeneticAlgorithm:
OpenNN::InputsSelectionAlgorithm

Classes

struct  GeneticAlgorithmResults
 

Public Types

enum  InitializationMethod { Random, Weigthed }
 
enum  CrossoverMethod { OnePoint, TwoPoint, Uniform }
 
enum  FitnessAssignment { ObjectiveBased, RankBased }
 
- Public Types inherited from OpenNN::InputsSelectionAlgorithm
enum  PerformanceCalculationMethod { Minimum, Maximum, Mean }
 
enum  StoppingCondition {
  MaximumTime, SelectionLossGoal, MaximumInputs, MinimumInputs,
  MaximumIterations, MaximumSelectionFailures, CorrelationGoal, AlgorithmFinished
}
 

Public Member Functions

 GeneticAlgorithm (void)
 
 GeneticAlgorithm (TrainingStrategy *)
 
 GeneticAlgorithm (const tinyxml2::XMLDocument &)
 
 GeneticAlgorithm (const std::string &)
 
virtual ~GeneticAlgorithm (void)
 
const Vector< Vector< bool > > & get_population (void) const
 
const Matrix< double > & get_loss (void) const
 
const Vector< double > & get_fitness (void) const
 
const InitializationMethodget_initialization_method (void) const
 
const CrossoverMethodget_crossover_method (void) const
 
const FitnessAssignmentget_fitness_assignment_method (void) const
 
const size_t & get_population_size (void) const
 
const double & get_mutation_rate (void) const
 
const size_t & get_elitism_size (void) const
 
const size_t & get_crossover_first_point (void) const
 
const size_t & get_crossover_second_point (void) const
 
const double & get_selective_pressure (void) const
 
const double & get_incest_prevention_distance (void) const
 
const bool & get_reserve_generation_mean (void) const
 
const bool & get_reserve_generation_standard_deviation (void) const
 
const bool & get_reserve_generation_minimum_selection (void) const
 
const bool & get_reserve_generation_optimum_loss (void) const
 
std::string write_initialization_method (void) const
 
std::string write_crossover_method (void) const
 
std::string write_fitness_assignment_method (void) const
 
void set_default (void)
 
void set_population (const Vector< Vector< bool > > &)
 
void set_loss (const Matrix< double > &)
 
void set_fitness (const Vector< double > &)
 
void set_inicialization_method (const InitializationMethod &)
 
void set_fitness_assignment_method (const FitnessAssignment &)
 
void set_crossover_method (const CrossoverMethod &)
 
void set_inicialization_method (const std::string &)
 
void set_fitness_assignment_method (const std::string &)
 
void set_crossover_method (const std::string &)
 
void set_population_size (const size_t &)
 
void set_mutation_rate (const double &)
 
void set_elitism_size (const size_t &)
 
void set_crossover_first_point (const size_t &)
 
void set_crossover_second_point (const size_t &)
 
void set_selective_pressure (const double &)
 
void set_incest_prevention_distance (const double &)
 
void set_reserve_generation_mean (const bool &)
 
void set_reserve_generation_standard_deviation (const bool &)
 
void set_reserve_generation_minimum_selection (const bool &)
 
void set_reserve_generation_optimum_loss (const bool &)
 
void initialize_population (void)
 
void initialize_random_population (void)
 
void initialize_weighted_population (void)
 
void evaluate_population (void)
 
void calculate_fitness (void)
 
void calculate_objetive_fitness (void)
 
void calculate_rank_fitness (void)
 
void evolve_population (void)
 
void perform_selection (void)
 
void perform_crossover (void)
 
void perform_1point_crossover (void)
 
void perform_2point_crossover (void)
 
void perform_uniform_crossover (void)
 
void perform_mutation (void)
 
size_t get_optimal_individual_index (void) const
 
GeneticAlgorithmResultsperform_inputs_selection (void)
 
Matrix< std::string > to_string_matrix (void) const
 
tinyxml2::XMLDocument * to_XML (void) const
 
void from_XML (const tinyxml2::XMLDocument &)
 
void write_XML (tinyxml2::XMLPrinter &) const
 
void save (const std::string &) const
 
void load (const std::string &)
 
- Public Member Functions inherited from OpenNN::InputsSelectionAlgorithm
 InputsSelectionAlgorithm (void)
 
 InputsSelectionAlgorithm (TrainingStrategy *)
 
 InputsSelectionAlgorithm (const std::string &)
 
 InputsSelectionAlgorithm (const tinyxml2::XMLDocument &)
 
virtual ~InputsSelectionAlgorithm (void)
 
const bool & get_approximation (void) const
 
TrainingStrategyget_training_strategy_pointer (void) const
 
bool has_training_strategy (void) const
 
const size_t & get_trials_number (void) const
 
const bool & get_reserve_parameters_data (void) const
 
const bool & get_reserve_loss_data (void) const
 
const bool & get_reserve_selection_loss_data (void) const
 
const bool & get_reserve_minimal_parameters (void) const
 
const PerformanceCalculationMethodget_loss_calculation_method (void) const
 
const bool & get_display (void) const
 
const double & get_selection_loss_goal (void) const
 
const size_t & get_maximum_iterations_number (void) const
 
const double & get_maximum_time (void) const
 
const double & get_maximum_correlation (void) const
 
const double & get_minimum_correlation (void) const
 
const double & get_tolerance (void) const
 
std::string write_loss_calculation_method (void) const
 
void set_approximation (const bool &)
 
void set_training_strategy_pointer (TrainingStrategy *)
 
void set_default (void)
 
void set_trials_number (const size_t &)
 
void set_reserve_parameters_data (const bool &)
 
void set_reserve_loss_data (const bool &)
 
void set_reserve_selection_loss_data (const bool &)
 
void set_reserve_minimal_parameters (const bool &)
 
void set_loss_calculation_method (const PerformanceCalculationMethod &)
 
void set_loss_calculation_method (const std::string &)
 
void set_display (const bool &)
 
void set_selection_loss_goal (const double &)
 
void set_maximum_iterations_number (const size_t &)
 
void set_maximum_time (const double &)
 
void set_maximum_correlation (const double &)
 
void set_minimum_correlation (const double &)
 
void set_tolerance (const double &)
 
Matrix< double > calculate_logistic_correlations (void) const
 
Vector< double > calculate_final_correlations (void) const
 
void set_neural_inputs (const Vector< bool > &)
 
Vector< double > perform_minimum_model_evaluation (const Vector< bool > &)
 
Vector< double > perform_maximum_model_evaluation (const Vector< bool > &)
 
Vector< double > perform_mean_model_evaluation (const Vector< bool > &)
 
Vector< double > get_final_losss (const TrainingStrategy::Results &) const
 
Vector< double > perform_model_evaluation (const Vector< bool > &)
 
Vector< double > get_parameters_inputs (const Vector< bool > &) const
 
void delete_selection_history (void)
 
void delete_loss_history (void)
 
void delete_parameters_history (void)
 
void check (void) const
 
size_t get_input_index (const Vector< Variables::Use >, const size_t)
 

Private Attributes

Vector< Vector< bool > > population
 
Matrix< double > loss
 
Vector< double > fitness
 
InitializationMethod initialization_method
 
CrossoverMethod crossover_method
 
FitnessAssignment fitness_assignment_method
 
Vector< Variables::Useoriginal_uses
 
size_t population_size
 
double incest_prevention_distance
 
double mutation_rate
 
size_t elitism_size
 
size_t crossover_first_point
 
size_t crossover_second_point
 
double selective_pressure
 
bool reserve_generation_mean
 
bool reserve_generation_standard_deviation
 
bool reserve_generation_minimum_selection
 
bool reserve_generation_optimum_loss
 

Additional Inherited Members

- Protected Attributes inherited from OpenNN::InputsSelectionAlgorithm
bool approximation
 
TrainingStrategytraining_strategy_pointer
 
Vector< Vector< bool > > inputs_history
 
Vector< double > selection_loss_history
 
Vector< double > loss_history
 
Vector< Vector< double > > parameters_history
 
size_t trials_number
 
PerformanceCalculationMethod loss_calculation_method
 
bool reserve_parameters_data
 
bool reserve_loss_data
 
bool reserve_selection_loss_data
 
bool reserve_minimal_parameters
 
bool display
 
double selection_loss_goal
 
size_t maximum_iterations_number
 
double maximum_correlation
 
double minimum_correlation
 
double maximum_time
 
double tolerance
 

Detailed Description

This concrete class represents a genetic algorithm for the inputs selection of a neural network.

Definition at line 47 of file genetic_algorithm.h.

Constructor & Destructor Documentation

◆ GeneticAlgorithm() [1/3]

OpenNN::GeneticAlgorithm::GeneticAlgorithm ( TrainingStrategy new_training_strategy_pointer)
explicit

Training strategy constructor.

Parameters
new_training_strategy_pointerPointer to a training strategy object.

Definition at line 36 of file genetic_algorithm.cpp.

◆ GeneticAlgorithm() [2/3]

OpenNN::GeneticAlgorithm::GeneticAlgorithm ( const tinyxml2::XMLDocument &  genetic_algorithm_document)
explicit

XML constructor.

Parameters
genetic_algorithm_documentPointer to a TinyXML document containing the genetic algorithm data.

Definition at line 60 of file genetic_algorithm.cpp.

◆ GeneticAlgorithm() [3/3]

OpenNN::GeneticAlgorithm::GeneticAlgorithm ( const std::string &  file_name)
explicit

File constructor.

Parameters
file_nameName of XML order selection file.

Definition at line 48 of file genetic_algorithm.cpp.

Member Function Documentation

◆ evaluate_population()

void OpenNN::GeneticAlgorithm::evaluate_population ( void  )

Evaluate a population. Perform the trainings of the neural networks and calculate their fitness.

Definition at line 1092 of file genetic_algorithm.cpp.

◆ evolve_population()

void OpenNN::GeneticAlgorithm::evolve_population ( void  )

Evolve the population to a new generation. Perform the selection, crossover and mutation of the current generation.

Definition at line 1259 of file genetic_algorithm.cpp.

◆ from_XML()

void OpenNN::GeneticAlgorithm::from_XML ( const tinyxml2::XMLDocument &  document)

Deserializes a TinyXML document into this genetic algorithm object.

Parameters
documentTinyXML document containing the member data.

Definition at line 2829 of file genetic_algorithm.cpp.

◆ load()

void OpenNN::GeneticAlgorithm::load ( const std::string &  file_name)

Loads a genetic algorithm object from a XML-type file.

Parameters
file_nameName of genetic algorithm XML-type file.

Definition at line 3398 of file genetic_algorithm.cpp.

◆ save()

void OpenNN::GeneticAlgorithm::save ( const std::string &  file_name) const

Saves to a XML-type file the members of the genetic algorithm object.

Parameters
file_nameName of genetic algorithm XML-type file.

Definition at line 3383 of file genetic_algorithm.cpp.

◆ set_crossover_first_point()

void OpenNN::GeneticAlgorithm::set_crossover_first_point ( const size_t &  new_crossover_first_point)

Sets the point of for the OnePoint and TwoPoint crossover. If it is set to 0, the algorithm will select it randomly for each crossover.

Parameters
new_crossover_first_pointPoint for the OnePoint and first point for TwoPoint crossover.

Definition at line 752 of file genetic_algorithm.cpp.

◆ set_crossover_method() [1/2]

void OpenNN::GeneticAlgorithm::set_crossover_method ( const CrossoverMethod new_crossover_method)

Sets a new method to perform the crossover in the algorithm.

Parameters
new_crossover_methodMethod to perform the crossover of the selected population(Uniform, OnePoint or TwoPoint).

Definition at line 573 of file genetic_algorithm.cpp.

◆ set_crossover_method() [2/2]

void OpenNN::GeneticAlgorithm::set_crossover_method ( const std::string &  new_crossover_method)

Sets a new crossover method from a string.

Parameters
new_crossover_methodString with the crossover method.

Definition at line 641 of file genetic_algorithm.cpp.

◆ set_crossover_second_point()

void OpenNN::GeneticAlgorithm::set_crossover_second_point ( const size_t &  new_crossover_second_point)

Sets the point of for the TwoPoint crossover. If it is set to 0, the algorithm will select it randomly for each crossover.

Parameters
new_crossover_second_pointSecond point for the TwoPoint crossover.

Definition at line 778 of file genetic_algorithm.cpp.

◆ set_elitism_size()

void OpenNN::GeneticAlgorithm::set_elitism_size ( const size_t &  new_elitism_size)

Sets the number of individuals with the greatest fitness selected.

Parameters
new_elitism_sizeSize of the elitism.

Definition at line 726 of file genetic_algorithm.cpp.

◆ set_fitness()

void OpenNN::GeneticAlgorithm::set_fitness ( const Vector< double > &  new_fitness)

Sets a new fitness for the population.

Parameters
new_fitnessNew fitness values.

Definition at line 514 of file genetic_algorithm.cpp.

◆ set_fitness_assignment_method() [1/2]

void OpenNN::GeneticAlgorithm::set_fitness_assignment_method ( const FitnessAssignment new_fitness_assignment_method)

Sets a new method to assign the fitness in the algorithm.

Parameters
new_fitness_assignment_methodMethod to assign the fitness(RankBased or ObjectiveBased).

Definition at line 563 of file genetic_algorithm.cpp.

◆ set_fitness_assignment_method() [2/2]

void OpenNN::GeneticAlgorithm::set_fitness_assignment_method ( const std::string &  new_fitness_assignment_method)

Sets a new fitness assignment method from a string.

Parameters
new_fitness_assignment_methodString with the fitness assignment method.

Definition at line 612 of file genetic_algorithm.cpp.

◆ set_incest_prevention_distance()

void OpenNN::GeneticAlgorithm::set_incest_prevention_distance ( const double &  new_incest_prevention_distance)

Sets a new value for the incest prevention distance used in the crossover.

Parameters
new_incest_prevention_distanceIncest prevention distance value.

Definition at line 840 of file genetic_algorithm.cpp.

◆ set_inicialization_method() [1/2]

void OpenNN::GeneticAlgorithm::set_inicialization_method ( const InitializationMethod new_initialization_method)

Sets a new method to initiate the population in the algorithm.

Parameters
new_initialization_methodMethod to initialize the population(Random or Weighted).

Definition at line 553 of file genetic_algorithm.cpp.

◆ set_inicialization_method() [2/2]

void OpenNN::GeneticAlgorithm::set_inicialization_method ( const std::string &  new_initialization_method)

Sets a new initialization method from a string.

Parameters
new_initialization_methodString with the crossover method.

Definition at line 583 of file genetic_algorithm.cpp.

◆ set_loss()

void OpenNN::GeneticAlgorithm::set_loss ( const Matrix< double > &  new_loss)

Sets a new training losses of the population.

Parameters
new_lossNew training losses.

Definition at line 478 of file genetic_algorithm.cpp.

◆ set_mutation_rate()

void OpenNN::GeneticAlgorithm::set_mutation_rate ( const double &  new_mutation_rate)

Sets a new rate used in the mutation. It is a number between 0 and 1.

Parameters
new_mutation_rateRate used for the mutation.

Definition at line 701 of file genetic_algorithm.cpp.

◆ set_population()

void OpenNN::GeneticAlgorithm::set_population ( const Vector< Vector< bool > > &  new_population)

Sets a new popualtion.

Parameters
new_populationNew population matrix.

Definition at line 401 of file genetic_algorithm.cpp.

◆ set_population_size()

void OpenNN::GeneticAlgorithm::set_population_size ( const size_t &  new_population_size)

Sets a new population size. It must be greater than 4.

Parameters
new_population_sizeSize of the population.

Definition at line 675 of file genetic_algorithm.cpp.

◆ set_reserve_generation_mean()

void OpenNN::GeneticAlgorithm::set_reserve_generation_mean ( const bool &  new_reserve_generation_mean)

Sets the reserve flag for the generation mean history.

Parameters
new_reserve_generation_meanFlag value.

Definition at line 850 of file genetic_algorithm.cpp.

◆ set_reserve_generation_minimum_selection()

void OpenNN::GeneticAlgorithm::set_reserve_generation_minimum_selection ( const bool &  new_reserve_generation_minimum_selection)

Sets the reserve flag for the generation minimum selection loss history.

Parameters
new_reserve_generation_minimum_selectionFlag value.

Definition at line 870 of file genetic_algorithm.cpp.

◆ set_reserve_generation_optimum_loss()

void OpenNN::GeneticAlgorithm::set_reserve_generation_optimum_loss ( const bool &  new_reserve_generation_optimum_loss)

Sets the reserve flag for the optimum loss error history.

Parameters
new_reserve_generation_optimum_lossFlag value.

Definition at line 880 of file genetic_algorithm.cpp.

◆ set_reserve_generation_standard_deviation()

void OpenNN::GeneticAlgorithm::set_reserve_generation_standard_deviation ( const bool &  new_reserve_generation_standard_deviation)

Sets the reserve flag for the generation standard deviation history.

Parameters
new_reserve_generation_standard_deviationFlag value.

Definition at line 860 of file genetic_algorithm.cpp.

◆ set_selective_pressure()

void OpenNN::GeneticAlgorithm::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.

Parameters
new_selective_pressureSelective pressure value.

Definition at line 815 of file genetic_algorithm.cpp.

◆ to_XML()

tinyxml2::XMLDocument * OpenNN::GeneticAlgorithm::to_XML ( void  ) const

Prints to the screen the genetic algorithm parameters, the stopping criteria and other user stuff concerning the genetic algorithm object.

Definition at line 2276 of file genetic_algorithm.cpp.

◆ write_XML()

void OpenNN::GeneticAlgorithm::write_XML ( tinyxml2::XMLPrinter &  file_stream) const

Serializes the genetic algorithm object into a XML document of the TinyXML library without keep the DOM tree in memory. See the OpenNN manual for more information about the format of this document.

Definition at line 2624 of file genetic_algorithm.cpp.

Member Data Documentation

◆ crossover_first_point

size_t OpenNN::GeneticAlgorithm::crossover_first_point
private

First point used in the OnePoint and TwoPoint crossover method. If it is 0 the algorithm selects a random point for each pair of offsprings.

Definition at line 324 of file genetic_algorithm.h.

◆ crossover_second_point

size_t OpenNN::GeneticAlgorithm::crossover_second_point
private

Second point used in the TwoPoint crossover method. If it is 0 the algorithm selects a random point for each pair of offsprings.

Definition at line 329 of file genetic_algorithm.h.

◆ elitism_size

size_t OpenNN::GeneticAlgorithm::elitism_size
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 319 of file genetic_algorithm.h.

◆ incest_prevention_distance

double OpenNN::GeneticAlgorithm::incest_prevention_distance
private

Incest prevention distance Distance between two individuals to prevent the crossover.

Definition at line 307 of file genetic_algorithm.h.

◆ mutation_rate

double OpenNN::GeneticAlgorithm::mutation_rate
private

Mutation rate. The mutation rate value must be between 0 and 1. This is a parameter of the mutation operator.

Definition at line 313 of file genetic_algorithm.h.

◆ selective_pressure

double OpenNN::GeneticAlgorithm::selective_pressure
private

Linear ranking allows values for the selective pressure greater than 0. This is a parameter of the fitness assignment operator.

Definition at line 334 of file genetic_algorithm.h.


The documentation for this class was generated from the following files: