OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::ModelSelection Class Reference

Searches for the best generalizing architecture for a model. More...

#include <model_selection.h>

Public Member Functions

 ModelSelection (TrainingStrategy *new_training_strategy=nullptr)
 Constructs a model selection bound to a training strategy.
 
const TrainingStrategyget_training_strategy () const
 Returns the underlying training strategy.
 
bool has_training_strategy () const
 Reports whether a training strategy is configured.
 
void set (TrainingStrategy *new_training_strategy)
 Replaces the underlying training strategy.
 
void set_default ()
 Picks default selection algorithms.
 
void check () const
 Validates that all components needed for selection are set.
 
NeuronsSelectionResults perform_neurons_selection ()
 Runs the configured neuron-selection algorithm.
 
InputsSelectionResults perform_input_selection ()
 Runs the configured input-selection algorithm.
 
void from_JSON (const JsonDocument &document)
 Restores the model-selection state from a JSON document.
 
void to_JSON (JsonWriter &writer) const
 Serializes the model-selection state to JSON.
 
void save (const filesystem::path &file_name) const
 Saves the model-selection state to a JSON file on disk.
 
void load (const filesystem::path &file_name)
 Loads the model-selection state from a JSON file on disk.
 

Detailed Description

Searches for the best generalizing architecture for a model.

Wraps two pluggable algorithms:

Both algorithms run on top of a user-supplied TrainingStrategy, which provides the underlying NeuralNetwork, Dataset and Loss they consume to score candidate architectures.

Constructor & Destructor Documentation

◆ ModelSelection()

opennn::ModelSelection::ModelSelection ( TrainingStrategy * new_training_strategy = nullptr)

Constructs a model selection bound to a training strategy.

Picks default selection algorithms (GrowingInputs and GrowingNeurons).

Parameters
new_training_strategyNon-owning pointer to the strategy used to evaluate candidate architectures. May be null and supplied later via set().

Member Function Documentation

◆ check()

void opennn::ModelSelection::check ( ) const

Validates that all components needed for selection are set.

Verifies the training strategy, its loss, the network behind the loss, the dataset, and that the dataset has at least one validation sample.

Exceptions
runtime_errorif any required component is missing.

◆ from_JSON()

void opennn::ModelSelection::from_JSON ( const JsonDocument & document)

Restores the model-selection state from a JSON document.

Parameters
documentParsed JSON produced by to_JSON().

◆ get_training_strategy()

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

Returns the underlying training strategy.

Returns
Const pointer to the strategy (may be nullptr).

◆ has_training_strategy()

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

Reports whether a training strategy is configured.

Returns
true if a non-null TrainingStrategy is set.

◆ load()

void opennn::ModelSelection::load ( const filesystem::path & file_name)

Loads the model-selection state from a JSON file on disk.

Parameters
file_nameSource path.

◆ perform_input_selection()

InputsSelectionResults opennn::ModelSelection::perform_input_selection ( )

Runs the configured input-selection algorithm.

Returns
Results of the search (selected feature subset, error history, etc.).

◆ perform_neurons_selection()

NeuronsSelectionResults opennn::ModelSelection::perform_neurons_selection ( )

Runs the configured neuron-selection algorithm.

Returns
Results of the search (best size found, error history, etc.).

◆ save()

void opennn::ModelSelection::save ( const filesystem::path & file_name) const

Saves the model-selection state to a JSON file on disk.

Parameters
file_nameDestination path.
Exceptions
runtime_errorif the file cannot be opened for writing.

◆ set()

void opennn::ModelSelection::set ( TrainingStrategy * new_training_strategy)
inline

Replaces the underlying training strategy.

Parameters
new_training_strategyNon-owning pointer to the new strategy.

◆ set_default()

void opennn::ModelSelection::set_default ( )

Picks default selection algorithms.

Sets the neurons-selection algorithm to "GrowingNeurons" and the inputs-selection algorithm to "GrowingInputs".

◆ to_JSON()

void opennn::ModelSelection::to_JSON ( JsonWriter & writer) const

Serializes the model-selection state to JSON.

Parameters
writerJSON writer that receives the configuration tree.