9#ifndef STOCHASTICGRADIENTDESCENT_H
10#define STOCHASTICGRADIENTDESCENT_H
28#include "loss_index.h"
29#include "optimization_algorithm.h"
34struct StochasticGradientDescentData;
76 void set_batch_samples_number(
const Index& new_batch_samples_number)
83 Index get_batch_samples_number()
const;
106 string write_optimization_algorithm_type()
const;
159 #include "../../opennn-cuda/opennn-cuda/stochastic_gradient_descent_cuda.h"
175 set(new_stochastic_gradient_descent_pointer);
178 virtual ~StochasticGradientDescentData() {}
180 void set(StochasticGradientDescent* new_stochastic_gradient_descent_pointer)
182 stochastic_gradient_descent_pointer = new_stochastic_gradient_descent_pointer;
190 parameters_increment.resize(parameters_number);
191 nesterov_increment.resize(parameters_number);
192 last_parameters_increment.resize(parameters_number);
194 parameters_increment.setZero();
195 nesterov_increment.setZero();
196 last_parameters_increment.setZero();
199 StochasticGradientDescent* stochastic_gradient_descent_pointer =
nullptr;
203 Tensor<type, 1> parameters_increment;
204 Tensor<type, 1> nesterov_increment;
205 Tensor<type, 1> last_parameters_increment;
This abstract class represents the concept of loss index composed of an error term and a regularizati...
NeuralNetwork * get_neural_network_pointer() const
Returns a pointer to the neural network object associated to the error term.
Index get_parameters_number() const
LossIndex * get_loss_index_pointer() const
This concrete class represents the stochastic gradient descent optimization algorithm[1] for a loss i...
void set_momentum(const type &)
TrainingResults perform_training()
void set_loss_index_pointer(LossIndex *)
const type & get_maximum_time() const
Returns the maximum training time.
type momentum
Parameter that accelerates SGD in the relevant direction and dampens oscillations.
const type & get_loss_goal() const
void from_XML(const tinyxml2::XMLDocument &)
void set_default()
Sets the members of the optimization algorithm object to their default values.
type initial_learning_rate
Initial learning rate.
Tensor< string, 2 > to_string_matrix() const
Writes as matrix of strings the most representative atributes.
void set_initial_learning_rate(const type &)
const type & get_momentum() const
Returns the momentum.
void set_maximum_time(const type &)
const bool & get_nesterov() const
Returns true if nesterov is active, and false otherwise.
void set_loss_goal(const type &)
type maximum_time
Maximum training time. It is used as a stopping criterion.
void set_maximum_epochs_number(const Index &)
virtual ~StochasticGradientDescent()
Destructor.
type initial_decay
Learning rate decay over each update.
void set_nesterov(const bool &)
void update_parameters(LossIndexBackPropagation &back_propagation, StochasticGradientDescentData &optimization_data)
Set hardware to use. Default: Multi-core.
type training_loss_goal
Goal value for the loss. It is used as a stopping criterion.
void set_initial_decay(const type &)
Index maximum_epochs_number
Maximum epochs number.
void write_XML(tinyxml2::XMLPrinter &) const
bool nesterov
Boolean. Whether to apply Nesterov momentum.
StochasticGradientDescent()
Index batch_samples_number
Number of samples per training batch.
Index maximum_selection_failures
Maximum selection error allowed.
const type & get_initial_learning_rate() const
Returns the initial learning rate.
const type & get_initial_decay() const
Returns the initial decay.
StochasticGradientDescentData()
Default constructor.
This structure contains the optimization algorithm results.