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

High-level orchestrator pairing a Loss with an Optimizer for a network/dataset. More...

#include <training_strategy.h>

Public Member Functions

 TrainingStrategy (NeuralNetwork *=nullptr, Dataset *=nullptr)
 Constructs the strategy with default loss (MSE) and optimizer (Adam) bound to the given network and dataset.
 
const Datasetget_dataset () const
 
Datasetget_dataset ()
 
const NeuralNetworkget_neural_network () const
 
NeuralNetworkget_neural_network ()
 
const Lossget_loss () const
 
Lossget_loss ()
 
const Optimizerget_optimization_algorithm () const
 
Optimizerget_optimization_algorithm ()
 
void set (NeuralNetwork *=nullptr, Dataset *=nullptr)
 Rebinds the strategy to a new network/dataset, resetting loss and optimizer to defaults.
 
void set_default ()
 Resets the loss and optimizer to their default types and hyperparameters.
 
void set_dataset (Dataset *new_dataset)
 
void set_neural_network (NeuralNetwork *new_neural_network)
 
void set_loss (const string &)
 Replaces the current loss with one selected by name (e.g. "MeanSquaredError", "CrossEntropy").
 
void set_optimization_algorithm (const string &)
 Replaces the current optimizer with one selected by name (e.g. "Adam", "SGD", "QuasiNewton", "LM").
 
TrainingResults train ()
 Runs the configured optimizer against the configured loss and returns the training history.
 
void from_JSON (const JsonDocument &)
 Restores the full strategy (loss + optimizer configurations) from a JSON document.
 
void to_JSON (JsonWriter &) const
 Serializes the full strategy (loss + optimizer configurations) to JSON.
 
void save (const filesystem::path &) const
 Writes the strategy configuration to a JSON file at the given path.
 
void load (const filesystem::path &)
 Loads the strategy configuration from a JSON file at the given path.
 

Detailed Description

High-level orchestrator pairing a Loss with an Optimizer for a network/dataset.

Constructor & Destructor Documentation

◆ TrainingStrategy()

opennn::TrainingStrategy::TrainingStrategy ( NeuralNetwork * = nullptr,
Dataset * = nullptr )

Constructs the strategy with default loss (MSE) and optimizer (Adam) bound to the given network and dataset.

Member Function Documentation

◆ from_JSON()

void opennn::TrainingStrategy::from_JSON ( const JsonDocument & )

Restores the full strategy (loss + optimizer configurations) from a JSON document.

◆ get_dataset() [1/2]

Dataset * opennn::TrainingStrategy::get_dataset ( )
inline

◆ get_dataset() [2/2]

const Dataset * opennn::TrainingStrategy::get_dataset ( ) const
inline

◆ get_loss() [1/2]

Loss * opennn::TrainingStrategy::get_loss ( )
inline

◆ get_loss() [2/2]

const Loss * opennn::TrainingStrategy::get_loss ( ) const
inline

◆ get_neural_network() [1/2]

NeuralNetwork * opennn::TrainingStrategy::get_neural_network ( )
inline

◆ get_neural_network() [2/2]

const NeuralNetwork * opennn::TrainingStrategy::get_neural_network ( ) const
inline

◆ get_optimization_algorithm() [1/2]

Optimizer * opennn::TrainingStrategy::get_optimization_algorithm ( )
inline

◆ get_optimization_algorithm() [2/2]

const Optimizer * opennn::TrainingStrategy::get_optimization_algorithm ( ) const
inline

◆ load()

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

Loads the strategy configuration from a JSON file at the given path.

◆ save()

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

Writes the strategy configuration to a JSON file at the given path.

◆ set()

void opennn::TrainingStrategy::set ( NeuralNetwork * = nullptr,
Dataset * = nullptr )

Rebinds the strategy to a new network/dataset, resetting loss and optimizer to defaults.

◆ set_dataset()

void opennn::TrainingStrategy::set_dataset ( Dataset * new_dataset)
inline

◆ set_default()

void opennn::TrainingStrategy::set_default ( )

Resets the loss and optimizer to their default types and hyperparameters.

◆ set_loss()

void opennn::TrainingStrategy::set_loss ( const string & )

Replaces the current loss with one selected by name (e.g. "MeanSquaredError", "CrossEntropy").

◆ set_neural_network()

void opennn::TrainingStrategy::set_neural_network ( NeuralNetwork * new_neural_network)
inline

◆ set_optimization_algorithm()

void opennn::TrainingStrategy::set_optimization_algorithm ( const string & )

Replaces the current optimizer with one selected by name (e.g. "Adam", "SGD", "QuasiNewton", "LM").

◆ to_JSON()

void opennn::TrainingStrategy::to_JSON ( JsonWriter & ) const

Serializes the full strategy (loss + optimizer configurations) to JSON.

◆ train()

TrainingResults opennn::TrainingStrategy::train ( )

Runs the configured optimizer against the configured loss and returns the training history.