This concrete class represents the stochastic gradient descent optimization algorithm[1] for a loss index of a neural network. More...
#include <stochastic_gradient_descent.h>
Public Member Functions | |
StochasticGradientDescent () | |
StochasticGradientDescent (LossIndex *) | |
virtual | ~StochasticGradientDescent () |
Destructor. More... | |
const type & | get_initial_learning_rate () const |
Returns the initial learning rate. More... | |
const type & | get_initial_decay () const |
Returns the initial decay. More... | |
const type & | get_momentum () const |
Returns the momentum. More... | |
const bool & | get_nesterov () const |
Returns true if nesterov is active, and false otherwise. More... | |
const type & | get_loss_goal () const |
const type & | get_maximum_time () const |
Returns the maximum training time. More... | |
void | set_loss_index_pointer (LossIndex *) |
void | set_default () |
Sets the members of the optimization algorithm object to their default values. More... | |
void | set_batch_samples_number (const Index &new_batch_samples_number) |
Index | get_batch_samples_number () const |
void | set_initial_learning_rate (const type &) |
void | set_initial_decay (const type &) |
void | set_momentum (const type &) |
void | set_nesterov (const bool &) |
void | set_maximum_epochs_number (const Index &) |
void | set_loss_goal (const type &) |
void | set_maximum_time (const type &) |
void | update_parameters (LossIndexBackPropagation &back_propagation, StochasticGradientDescentData &optimization_data) |
Set hardware to use. Default: Multi-core. More... | |
TrainingResults | perform_training () |
string | write_optimization_algorithm_type () const |
Tensor< string, 2 > | to_string_matrix () const |
Writes as matrix of strings the most representative atributes. More... | |
void | from_XML (const tinyxml2::XMLDocument &) |
void | write_XML (tinyxml2::XMLPrinter &) const |
![]() | |
OptimizationAlgorithm () | |
OptimizationAlgorithm (LossIndex *) | |
virtual | ~OptimizationAlgorithm () |
Destructor. More... | |
LossIndex * | get_loss_index_pointer () const |
string | get_hardware_use () const |
Hardware use. More... | |
void | set_hardware_use (const string &) |
Set hardware to use. Default: Multi-core. More... | |
bool | has_loss_index () const |
const bool & | get_display () const |
const Index & | get_display_period () const |
Returns the number of iterations between the training showing progress. More... | |
const Index & | get_save_period () const |
Returns the number of iterations between the training saving progress. More... | |
const string & | get_neural_network_file_name () const |
Returns the file name where the neural network will be saved. More... | |
const string | write_time (const type &) const |
Writes the time from seconds in format HH:mm:ss. More... | |
void | set () |
virtual void | set_threads_number (const int &) |
virtual void | set_display (const bool &) |
void | set_display_period (const Index &) |
void | set_save_period (const Index &) |
void | set_neural_network_file_name (const string &) |
virtual void | check () const |
virtual void | print () const |
Prints to the screen the XML-type representation of the optimization algorithm object. More... | |
void | save (const string &) const |
void | load (const string &) |
Private Attributes | |
type | initial_learning_rate |
Initial learning rate. More... | |
type | initial_decay |
Learning rate decay over each update. More... | |
type | momentum |
Parameter that accelerates SGD in the relevant direction and dampens oscillations. More... | |
bool | nesterov |
Boolean. Whether to apply Nesterov momentum. More... | |
Index | batch_samples_number = 1000 |
Number of samples per training batch. More... | |
type | training_loss_goal = type(0) |
Goal value for the loss. It is used as a stopping criterion. More... | |
Index | maximum_selection_failures = numeric_limits<Index>::max() |
Maximum selection error allowed. More... | |
Index | maximum_epochs_number = 10000 |
Maximum epochs number. More... | |
type | maximum_time = type(3600) |
Maximum training time. It is used as a stopping criterion. More... | |
Additional Inherited Members | |
![]() | |
enum class | StoppingCondition { MinimumLossDecrease , LossGoal , MaximumSelectionErrorIncreases , MaximumEpochsNumber , MaximumTime } |
Enumeration of all possibles condition of stop for the algorithms. More... | |
![]() | |
NonBlockingThreadPool * | non_blocking_thread_pool = nullptr |
ThreadPoolDevice * | thread_pool_device |
LossIndex * | loss_index_pointer = nullptr |
Pointer to a loss index for a neural network object. More... | |
Index | epochs_number = 10000 |
Number of training epochs in the neural network. More... | |
string | hardware_use = "Multi-core" |
Hardware use. More... | |
Index | display_period = 10 |
Number of iterations between the training showing progress. More... | |
Index | save_period = numeric_limits<Index>::max() |
Number of iterations between the training saving progress. More... | |
string | neural_network_file_name = "neural_network.xml" |
Path where the neural network is saved. More... | |
bool | display = true |
Display messages to screen. More... | |
const Eigen::array< IndexPair< Index >, 1 > | AT_B = {IndexPair<Index>(0, 0)} |
const Eigen::array< IndexPair< Index >, 1 > | product_vector_matrix = {IndexPair<Index>(0, 1)} |
const Eigen::array< IndexPair< Index >, 1 > | A_B = {IndexPair<Index>(1, 0)} |
This concrete class represents the stochastic gradient descent optimization algorithm[1] for a loss index of a neural network.
It supports momentum, learning rate decay, and Nesterov momentum.
[1] Neural Designer "5 Algorithms to Train a Neural Network." https://www.neuraldesigner.com/blog/5_algorithms_to_train_a_neural_network
Definition at line 43 of file stochastic_gradient_descent.h.
|
explicit |
Default constructor. It creates a stochastic gradient descent optimization algorithm not associated to any loss index object. It also initializes the class members to their default values.
Definition at line 18 of file stochastic_gradient_descent.cpp.
|
explicit |
Loss index constructor. It creates a stochastic gradient descent optimization algorithm associated to a loss index. It also initializes the class members to their default values.
new_loss_index_pointer | Pointer to a loss index object. |
Definition at line 30 of file stochastic_gradient_descent.cpp.
|
virtual |
Destructor.
Definition at line 39 of file stochastic_gradient_descent.cpp.
|
virtual |
Loads a default optimization algorithm from a XML document.
document | TinyXML document containing the error term members. |
Reimplemented from OptimizationAlgorithm.
Definition at line 723 of file stochastic_gradient_descent.cpp.
Index get_batch_samples_number | ( | ) | const |
Definition at line 124 of file stochastic_gradient_descent.cpp.
const type & get_initial_decay | ( | ) | const |
Returns the initial decay.
Definition at line 54 of file stochastic_gradient_descent.cpp.
const type & get_initial_learning_rate | ( | ) | const |
Returns the initial learning rate.
Definition at line 46 of file stochastic_gradient_descent.cpp.
const type & get_loss_goal | ( | ) | const |
Returns the goal value for the loss. This is used as a stopping criterion when training a neural network
Definition at line 79 of file stochastic_gradient_descent.cpp.
const type & get_maximum_time | ( | ) | const |
Returns the maximum training time.
Definition at line 87 of file stochastic_gradient_descent.cpp.
const type & get_momentum | ( | ) | const |
Returns the momentum.
Definition at line 62 of file stochastic_gradient_descent.cpp.
const bool & get_nesterov | ( | ) | const |
Returns true if nesterov is active, and false otherwise.
Definition at line 70 of file stochastic_gradient_descent.cpp.
|
virtual |
Trains a neural network with an associated loss index, according to the stochastic gradient descent method. Training occurs according to the training parameters and stopping criteria. It returns a results structure with the history and the final values of the reserved variables.
Implements OptimizationAlgorithm.
Definition at line 328 of file stochastic_gradient_descent.cpp.
|
inline |
Definition at line 76 of file stochastic_gradient_descent.h.
|
virtual |
Sets the members of the optimization algorithm object to their default values.
Reimplemented from OptimizationAlgorithm.
Definition at line 103 of file stochastic_gradient_descent.cpp.
void set_initial_decay | ( | const type & | new_dacay | ) |
Set the initial value for the decay.
new_initial_learning_rate | initial value for the decay. |
Definition at line 160 of file stochastic_gradient_descent.cpp.
void set_initial_learning_rate | ( | const type & | new_learning_rate | ) |
Set the initial value for the learning rate. If dacay is not active learning rate will be constant otherwise learning rate will decay over each update.
new_initial_learning_rate | initial learning rate value. |
Definition at line 134 of file stochastic_gradient_descent.cpp.
void set_loss_goal | ( | const type & | new_loss_goal | ) |
Sets a new goal value for the loss. This is used as a stopping criterion when training a neural network
new_loss_goal | Goal value for the loss. |
Definition at line 249 of file stochastic_gradient_descent.cpp.
|
virtual |
Sets a pointer to a loss index object to be associated to the gradient descent object. It also sets that loss index to the learning rate algorithm.
new_loss_index_pointer | Pointer to a loss index object. |
Reimplemented from OptimizationAlgorithm.
Definition at line 97 of file stochastic_gradient_descent.cpp.
void set_maximum_epochs_number | ( | const Index & | new_maximum_epochs_number | ) |
Set the a new maximum for the epochs number.
new_maximum_epochs | number New maximum epochs number. |
Definition at line 222 of file stochastic_gradient_descent.cpp.
void set_maximum_time | ( | const type & | new_maximum_time | ) |
Sets a new maximum training time.
new_maximum_time | Maximum training time. |
Definition at line 258 of file stochastic_gradient_descent.cpp.
void set_momentum | ( | const type & | new_momentum | ) |
Set a new value for momentum, this parameter accelerates SGD in the relevant direction and dampens oscillations.
new_momentum | initial value for the mometum. |
Definition at line 187 of file stochastic_gradient_descent.cpp.
void set_nesterov | ( | const bool & | new_nesterov_momentum | ) |
Set nesterov, boolean. Whether to apply Nesterov momentum.
new_momentum | initial value for the mometum. |
Definition at line 213 of file stochastic_gradient_descent.cpp.
|
virtual |
Writes as matrix of strings the most representative atributes.
Reimplemented from OptimizationAlgorithm.
Definition at line 599 of file stochastic_gradient_descent.cpp.
void update_parameters | ( | LossIndexBackPropagation & | back_propagation, |
StochasticGradientDescentData & | optimization_data | ||
) |
Set hardware to use. Default: Multi-core.
Definition at line 283 of file stochastic_gradient_descent.cpp.
|
virtual |
Reimplemented from OptimizationAlgorithm.
Definition at line 591 of file stochastic_gradient_descent.cpp.
|
virtual |
Serializes the gradient descent object into a XML document of the TinyXML library without keep the DOM tree in memory. See the OpenNN manual for more information about the format of this document.
Reimplemented from OptimizationAlgorithm.
Definition at line 645 of file stochastic_gradient_descent.cpp.
|
private |
Number of samples per training batch.
Definition at line 138 of file stochastic_gradient_descent.h.
|
private |
Learning rate decay over each update.
Definition at line 126 of file stochastic_gradient_descent.h.
|
private |
Initial learning rate.
Definition at line 122 of file stochastic_gradient_descent.h.
|
private |
Maximum epochs number.
Definition at line 152 of file stochastic_gradient_descent.h.
|
private |
Maximum selection error allowed.
Definition at line 148 of file stochastic_gradient_descent.h.
|
private |
Maximum training time. It is used as a stopping criterion.
Definition at line 156 of file stochastic_gradient_descent.h.
|
private |
Parameter that accelerates SGD in the relevant direction and dampens oscillations.
Definition at line 130 of file stochastic_gradient_descent.h.
|
private |
Boolean. Whether to apply Nesterov momentum.
Definition at line 134 of file stochastic_gradient_descent.h.
|
private |
Goal value for the loss. It is used as a stopping criterion.
Definition at line 144 of file stochastic_gradient_descent.h.