OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::NeuronSelection Class Referenceabstract

Abstract base class for hidden-layer-size selection methods. More...

#include <neuron_selection.h>

Inheritance diagram for opennn::NeuronSelection:
[legend]

Public Types

enum class  StoppingCondition {
  MaximumTime , SelectionErrorGoal , MaximumEpochs , MaximumSelectionFailures ,
  MaximumNeurons
}
 Reasons that can terminate a neurons-selection run. More...
 

Public Member Functions

 NeuronSelection (TrainingStrategy *training_strategy=nullptr)
 Constructs the selector.
 
virtual ~NeuronSelection ()=default
 Virtual destructor.
 
const TrainingStrategyget_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 *)
 Re-initializes the selector by setting its training strategy.
 
void set_training_strategy (TrainingStrategy *new_training_strategy)
 Sets the training strategy directly.
 
void set_default ()
 Resets all hyperparameters to their default values.
 
void set_maximum_neurons (const Index new_maximum_neurons)
 Sets the maximum hidden-layer size considered.
 
void set_minimum_neurons (const Index new_minimum_neurons)
 Sets the minimum hidden-layer size considered.
 
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.
 
virtual NeuronsSelectionResults perform_neurons_selection ()=0
 Runs the selection algorithm.
 
string get_name () const
 Canonical name of the selector (set by subclasses).
 
virtual void from_JSON (const JsonDocument &)=0
 Loads selector hyperparameters from a parsed JSON document.
 
virtual void to_JSON (JsonWriter &) const =0
 Writes selector hyperparameters to a streaming JSON writer.
 
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.
 

Protected Attributes

TrainingStrategytraining_strategy = nullptr
 Training strategy used to evaluate candidates; not owned.
 
VectorR validation_error_history
 Per-iteration validation error of the best candidate so far.
 
VectorR training_error_history
 Per-iteration training error of the best candidate so far.
 
Index minimum_neurons = 0
 Lower bound on the hidden-layer size.
 
Index maximum_neurons = 0
 Upper bound on the hidden-layer size.
 
Index trials_number = 1
 Number of independent training runs averaged per candidate.
 
float validation_error_goal = 0
 Validation error goal; selection stops when reached.
 
Index maximum_epochs = 10
 Maximum training epochs per evaluation.
 
Index maximum_validation_failures = 100
 Maximum consecutive validation-error increases tolerated.
 
float maximum_time = 0
 Maximum wall-clock selection time in seconds.
 
bool display = true
 Whether progress should be printed to stdout during selection.
 
string name
 Canonical name of the selector (set by subclasses).
 

Detailed Description

Abstract base class for hidden-layer-size selection methods.

Holds a pointer to a TrainingStrategy used to evaluate candidate architectures, the common stopping criteria and trial averaging. Subclasses implement perform_neurons_selection() to drive the search.

Member Enumeration Documentation

◆ StoppingCondition

Reasons that can terminate a neurons-selection run.

Enumerator
MaximumTime 

Configured time budget exhausted.

SelectionErrorGoal 

Validation error reached the configured goal.

MaximumEpochs 

Configured epoch budget exhausted.

MaximumSelectionFailures 

Validation error increased too many times.

MaximumNeurons 

Maximum hidden-layer size reached.

Constructor & Destructor Documentation

◆ NeuronSelection()

opennn::NeuronSelection::NeuronSelection ( TrainingStrategy * training_strategy = nullptr)

Constructs the selector.

Parameters
training_strategyTraining strategy used to evaluate candidate sizes.

◆ ~NeuronSelection()

virtual opennn::NeuronSelection::~NeuronSelection ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ check()

void opennn::NeuronSelection::check ( ) const

Validates the bound configuration; throws if anything is missing.

◆ from_JSON()

virtual void opennn::NeuronSelection::from_JSON ( const JsonDocument & )
pure virtual

Loads selector hyperparameters from a parsed JSON document.

Implemented in opennn::GrowingNeurons.

◆ get_display()

bool opennn::NeuronSelection::get_display ( ) const
inline

Whether progress should be printed to stdout.

◆ get_name()

string opennn::NeuronSelection::get_name ( ) const
inline

Canonical name of the selector (set by subclasses).

◆ get_training_strategy()

const TrainingStrategy * opennn::NeuronSelection::get_training_strategy ( ) const
inline

Read-only access to the bound training strategy.

◆ has_training_strategy()

bool opennn::NeuronSelection::has_training_strategy ( ) const
inline

Whether a training strategy has been bound.

◆ load()

void opennn::NeuronSelection::load ( const filesystem::path & )

Loads the selector configuration from a file.

Receives the source path.

◆ perform_neurons_selection()

virtual NeuronsSelectionResults opennn::NeuronSelection::perform_neurons_selection ( )
pure virtual

Runs the selection algorithm.

Returns
Best-of-run hidden-layer size and supporting statistics.

Implemented in opennn::GrowingNeurons.

◆ print()

virtual void opennn::NeuronSelection::print ( ) const
inlinevirtual

Prints a human-readable summary of the selector to stdout.

◆ save()

void opennn::NeuronSelection::save ( const filesystem::path & ) const

Saves the selector configuration to a file.

Receives the destination path.

◆ set()

void opennn::NeuronSelection::set ( TrainingStrategy * )

Re-initializes the selector by setting its training strategy.

Receives the training strategy used to evaluate candidates.

◆ set_default()

void opennn::NeuronSelection::set_default ( )

Resets all hyperparameters to their default values.

◆ set_display()

void opennn::NeuronSelection::set_display ( bool new_display)
inline

Toggles per-iteration progress printing.

Parameters
new_displayTrue to print progress to stdout.

◆ set_maximum_epochs()

void opennn::NeuronSelection::set_maximum_epochs ( const Index new_maximum_epochs)
inline

Sets the maximum training epochs per evaluation.

Parameters
new_maximum_epochsEpoch budget for each candidate's training.

◆ set_maximum_neurons()

void opennn::NeuronSelection::set_maximum_neurons ( const Index new_maximum_neurons)
inline

Sets the maximum hidden-layer size considered.

Parameters
new_maximum_neuronsUpper bound on the number of neurons.

◆ set_maximum_time()

void opennn::NeuronSelection::set_maximum_time ( const float new_maximum_time)
inline

Sets the maximum wall-clock selection time.

Parameters
new_maximum_timeTime budget in seconds.

◆ set_maximum_validation_failures()

void opennn::NeuronSelection::set_maximum_validation_failures ( const Index new_maximum_validation_failures)
inline

Sets the maximum number of consecutive validation-error increases tolerated.

Parameters
new_maximum_validation_failuresFailure budget for early stopping.

◆ set_minimum_neurons()

void opennn::NeuronSelection::set_minimum_neurons ( const Index new_minimum_neurons)
inline

Sets the minimum hidden-layer size considered.

Parameters
new_minimum_neuronsLower bound on the number of neurons.

◆ set_training_strategy()

void opennn::NeuronSelection::set_training_strategy ( TrainingStrategy * new_training_strategy)
inline

Sets the training strategy directly.

Parameters
new_training_strategyStrategy used to evaluate candidates.

◆ set_trials_number()

void opennn::NeuronSelection::set_trials_number ( const Index new_trials_number)
inline

Sets the number of training trials per candidate (mean is used).

Parameters
new_trials_numberNumber of independent training runs averaged.

◆ set_validation_error_goal()

void opennn::NeuronSelection::set_validation_error_goal ( const float new_validation_error_goal)
inline

Sets the validation error goal.

Parameters
new_validation_error_goalSelection stops when validation error reaches this value.

◆ to_JSON()

virtual void opennn::NeuronSelection::to_JSON ( JsonWriter & ) const
pure virtual

Writes selector hyperparameters to a streaming JSON writer.

Implemented in opennn::GrowingNeurons.

Member Data Documentation

◆ display

bool opennn::NeuronSelection::display = true
protected

Whether progress should be printed to stdout during selection.

◆ maximum_epochs

Index opennn::NeuronSelection::maximum_epochs = 10
protected

Maximum training epochs per evaluation.

◆ maximum_neurons

Index opennn::NeuronSelection::maximum_neurons = 0
protected

Upper bound on the hidden-layer size.

◆ maximum_time

float opennn::NeuronSelection::maximum_time = 0
protected

Maximum wall-clock selection time in seconds.

◆ maximum_validation_failures

Index opennn::NeuronSelection::maximum_validation_failures = 100
protected

Maximum consecutive validation-error increases tolerated.

◆ minimum_neurons

Index opennn::NeuronSelection::minimum_neurons = 0
protected

Lower bound on the hidden-layer size.

◆ name

string opennn::NeuronSelection::name
protected

Canonical name of the selector (set by subclasses).

◆ training_error_history

VectorR opennn::NeuronSelection::training_error_history
protected

Per-iteration training error of the best candidate so far.

◆ training_strategy

TrainingStrategy* opennn::NeuronSelection::training_strategy = nullptr
protected

Training strategy used to evaluate candidates; not owned.

◆ trials_number

Index opennn::NeuronSelection::trials_number = 1
protected

Number of independent training runs averaged per candidate.

◆ validation_error_goal

float opennn::NeuronSelection::validation_error_goal = 0
protected

Validation error goal; selection stops when reached.

◆ validation_error_history

VectorR opennn::NeuronSelection::validation_error_history
protected

Per-iteration validation error of the best candidate so far.