|
OpenNN
Open-source neural networks library
|
Genetic-algorithm based input feature selection. More...
#include <genetic_algorithm.h>
Public Member Functions | |
| GeneticAlgorithm (TrainingStrategy *training_strategy=nullptr) | |
| Constructs the algorithm. | |
| Index | get_individuals_number () const |
| Number of individuals in the current population. | |
| Index | get_genes_number () const |
| Number of genes per chromosome (= number of original inputs). | |
| void | set_default () |
| Resets all hyperparameters to their default values. | |
| Index | get_minimum_inputs_number () const override |
| Minimum number of selected inputs allowed in any individual. | |
| Index | get_maximum_inputs_number () const override |
| Maximum number of selected inputs allowed in any individual. | |
| void | set_minimum_inputs_number (const Index new_minimum) |
| Sets the minimum number of selected inputs. | |
| void | set_maximum_inputs_number (const Index) |
| Sets the maximum number of selected inputs. | |
| void | set_individuals_number (const Index new_individuals_number=4) |
| Sets the population size. | |
| void | set_initialization_method (string method) |
| Sets the population initialization strategy. | |
| void | set_mutation_rate (const float rate) |
| Sets the mutation rate. | |
| void | set_elitism_size (const Index size) |
| Sets the elitism size. | |
| InputsSelectionResults | perform_input_selection () override |
| Runs the genetic algorithm. | |
| void | from_JSON (const JsonDocument &) override |
| Loads hyperparameters from a parsed JSON document. | |
| void | to_JSON (JsonWriter &) const override |
| Writes hyperparameters to a streaming JSON writer. | |
Public Member Functions inherited from opennn::InputsSelection | |
| InputsSelection (TrainingStrategy *training_strategy=nullptr) | |
| Constructs the selector. | |
| virtual | ~InputsSelection ()=default |
| Virtual destructor. | |
| const TrainingStrategy * | get_training_strategy () const |
| Read-only access to the bound training strategy. | |
| bool | has_training_strategy () const |
| Whether a training strategy has been bound. | |
| bool | get_display () const |
| Whether progress should be printed to stdout. | |
| void | set (TrainingStrategy *new_training_strategy) |
| Re-initializes the selector by setting its training strategy. | |
| void | set_trials_number (const Index new_trials_number) |
| Sets the number of training trials per candidate (mean is used). | |
| void | set_display (bool new_display) |
| Toggles per-iteration progress printing. | |
| void | set_validation_error_goal (const float new_validation_error_goal) |
| Sets the validation error goal. | |
| void | set_maximum_epochs (const Index new_maximum_epochs) |
| Sets the maximum training epochs per evaluation. | |
| void | set_maximum_validation_failures (const Index new_maximum_validation_failures) |
| Sets the maximum number of consecutive validation-error increases tolerated. | |
| void | set_maximum_time (const float new_maximum_time) |
| Sets the maximum wall-clock selection time. | |
| void | check () const |
| Validates the bound configuration; throws if anything is missing. | |
| string | get_name () const |
| Canonical name of the selector (set by subclasses). | |
| void | save (const filesystem::path &) const |
| Saves the selector configuration to a file. | |
| void | load (const filesystem::path &) |
| Loads the selector configuration from a file. | |
| virtual void | print () const |
| Prints a human-readable summary of the selector to stdout. | |
Additional Inherited Members | |
Public Types inherited from opennn::InputsSelection | |
| enum class | StoppingCondition { MaximumTime , SelectionErrorGoal , MaximumInputs , MaximumEpochs , MaximumSelectionFailures } |
| Reasons that can terminate an input-selection run. More... | |
Protected Attributes inherited from opennn::InputsSelection | |
| TrainingStrategy * | training_strategy = nullptr |
| Training strategy used to evaluate candidate subsets; not owned. | |
| Index | trials_number = 1 |
| Number of independent training runs averaged per candidate. | |
| bool | display = true |
| Whether progress should be printed to stdout during selection. | |
| float | validation_error_goal |
| Validation error goal; selection stops when reached. | |
| Index | maximum_epochs |
| Maximum training epochs per evaluation. | |
| Index | maximum_validation_failures = 100 |
| Maximum consecutive validation-error increases tolerated. | |
| float | maximum_time |
| Maximum wall-clock selection time in seconds. | |
| string | name |
| Canonical name of the selector (set by subclasses). | |
Genetic-algorithm based input feature selection.
Encodes each candidate input subset as a binary chromosome (one gene per input variable), evolves a population of chromosomes through selection, crossover and mutation, and returns the subset that achieved the lowest validation error.
| opennn::GeneticAlgorithm::GeneticAlgorithm | ( | TrainingStrategy * | training_strategy = nullptr | ) |
Constructs the algorithm.
| training_strategy | Training strategy used to evaluate candidates. |
|
overridevirtual |
Loads hyperparameters from a parsed JSON document.
Implements opennn::InputsSelection.
|
inline |
Number of genes per chromosome (= number of original inputs).
|
inline |
Number of individuals in the current population.
|
inlineoverridevirtual |
Maximum number of selected inputs allowed in any individual.
Implements opennn::InputsSelection.
|
inlineoverridevirtual |
Minimum number of selected inputs allowed in any individual.
Implements opennn::InputsSelection.
|
overridevirtual |
Runs the genetic algorithm.
Implements opennn::InputsSelection.
| void opennn::GeneticAlgorithm::set_default | ( | ) |
Resets all hyperparameters to their default values.
|
inline |
Sets the elitism size.
| size | Number of best individuals carried unchanged to the next generation, clamped to [0, individuals_number]. |
| void opennn::GeneticAlgorithm::set_individuals_number | ( | const Index | new_individuals_number = 4 | ) |
Sets the population size.
| new_individuals_number | Number of individuals to maintain. |
|
inline |
Sets the population initialization strategy.
| method | Strategy name ("Random" or "Correlations"). |
| void opennn::GeneticAlgorithm::set_maximum_inputs_number | ( | const Index | ) |
Sets the maximum number of selected inputs.
Receives the new upper bound on the number of selected inputs.
|
inline |
Sets the minimum number of selected inputs.
| new_minimum | New lower bound on the number of selected inputs. |
|
inline |
Sets the mutation rate.
| rate | Per-gene flip probability, clamped to [0, 1]. |
|
overridevirtual |
Writes hyperparameters to a streaming JSON writer.
Implements opennn::InputsSelection.