OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::GeneticAlgorithm Class Referencefinal

Selects the optimal subset of input features using an evolutionary genetic algorithm. More...

#include <genetic_algorithm.h>

Inheritance diagram for opennn::GeneticAlgorithm:
[legend]

Public Member Functions

 GeneticAlgorithm (TrainingStrategy *=nullptr)
 Constructs the algorithm bound to an optional training strategy.
 
Index get_individuals_number () const
 
Index get_genes_number () const
 
void set_default ()
 Restores default population size, mutation rate, elitism and other parameters.
 
Index get_minimum_inputs_number () const override
 Returns the minimum number of input variables that the algorithm may select.
 
Index get_maximum_inputs_number () const override
 Returns the maximum number of input variables that the algorithm may select.
 
void set_minimum_inputs_number (const Index new_minimum)
 
void set_maximum_inputs_number (const Index)
 Sets the upper bound on the number of selected inputs.
 
void set_individuals_number (const Index new_individuals_number=4)
 Sets the size of the population evolved by the algorithm.
 
void set_initialization_method (string method)
 
void set_mutation_rate (const float rate)
 
void set_elitism_size (const Index size)
 
InputsSelectionResults perform_input_selection () override
 Runs the genetic algorithm until the stopping criterion is met.
 
void from_JSON (const JsonDocument &) override
 Loads algorithm configuration from a JSON document.
 
void to_JSON (JsonWriter &) const override
 Writes algorithm configuration to a JSON writer.
 
- Public Member Functions inherited from opennn::InputsSelection
 InputsSelection (TrainingStrategy *=nullptr)
 Constructs the algorithm bound to an optional training strategy.
 
virtual ~InputsSelection ()=default
 
const TrainingStrategyget_training_strategy () const
 
bool has_training_strategy () const
 
bool get_display () const
 
void set (TrainingStrategy *new_training_strategy)
 
void set_trials_number (const Index new_trials_number)
 
void set_display (bool new_display)
 
void set_validation_error_goal (const float new_validation_error_goal)
 
void set_maximum_epochs (const Index new_maximum_epochs)
 
void set_maximum_validation_failures (const Index new_maximum_validation_failures)
 
void set_maximum_time (const float new_maximum_time)
 
void check () const
 Verifies that the training strategy and its dependencies are valid for inputs selection.
 
string get_name () const
 
void save (const filesystem::path &) const
 Saves the algorithm configuration to disk.
 
void load (const filesystem::path &)
 Loads the algorithm configuration from disk.
 
virtual void print () const
 Prints a human-readable description of the algorithm to stdout.
 

Additional Inherited Members

- Public Types inherited from opennn::InputsSelection
enum class  StoppingCondition {
  MaximumTime , SelectionErrorGoal , MaximumInputs , MaximumEpochs ,
  MaximumSelectionFailures
}
 Reasons the inputs selection loop may terminate. More...
 
- Protected Attributes inherited from opennn::InputsSelection
TrainingStrategytraining_strategy = nullptr
 
Index trials_number = 1
 
bool display = true
 
float validation_error_goal
 
Index maximum_epochs
 
Index maximum_validation_failures = 100
 
float maximum_time
 
string name
 

Detailed Description

Selects the optimal subset of input features using an evolutionary genetic algorithm.

Constructor & Destructor Documentation

◆ GeneticAlgorithm()

opennn::GeneticAlgorithm::GeneticAlgorithm ( TrainingStrategy * = nullptr)

Constructs the algorithm bound to an optional training strategy.

Member Function Documentation

◆ from_JSON()

void opennn::GeneticAlgorithm::from_JSON ( const JsonDocument & )
overridevirtual

Loads algorithm configuration from a JSON document.

Implements opennn::InputsSelection.

◆ get_genes_number()

Index opennn::GeneticAlgorithm::get_genes_number ( ) const
inline

◆ get_individuals_number()

Index opennn::GeneticAlgorithm::get_individuals_number ( ) const
inline

◆ get_maximum_inputs_number()

Index opennn::GeneticAlgorithm::get_maximum_inputs_number ( ) const
inlineoverridevirtual

Returns the maximum number of input variables that the algorithm may select.

Implements opennn::InputsSelection.

◆ get_minimum_inputs_number()

Index opennn::GeneticAlgorithm::get_minimum_inputs_number ( ) const
inlineoverridevirtual

Returns the minimum number of input variables that the algorithm may select.

Implements opennn::InputsSelection.

◆ perform_input_selection()

InputsSelectionResults opennn::GeneticAlgorithm::perform_input_selection ( )
overridevirtual

Runs the genetic algorithm until the stopping criterion is met.

Returns
Selection results including the best individual's inputs and error history.

Implements opennn::InputsSelection.

◆ set_default()

void opennn::GeneticAlgorithm::set_default ( )

Restores default population size, mutation rate, elitism and other parameters.

◆ set_elitism_size()

void opennn::GeneticAlgorithm::set_elitism_size ( const Index size)
inline

◆ set_individuals_number()

void opennn::GeneticAlgorithm::set_individuals_number ( const Index new_individuals_number = 4)

Sets the size of the population evolved by the algorithm.

◆ set_initialization_method()

void opennn::GeneticAlgorithm::set_initialization_method ( string method)
inline

◆ set_maximum_inputs_number()

void opennn::GeneticAlgorithm::set_maximum_inputs_number ( const Index )

Sets the upper bound on the number of selected inputs.

◆ set_minimum_inputs_number()

void opennn::GeneticAlgorithm::set_minimum_inputs_number ( const Index new_minimum)
inline

◆ set_mutation_rate()

void opennn::GeneticAlgorithm::set_mutation_rate ( const float rate)
inline

◆ to_JSON()

void opennn::GeneticAlgorithm::to_JSON ( JsonWriter & ) const
overridevirtual

Writes algorithm configuration to a JSON writer.

Implements opennn::InputsSelection.