#include <conjugate_gradient.h>
Public Types | |
enum class | TrainingDirectionMethod { PR , FR } |
Enumeration of the available training operators for obtaining the training direction. More... | |
![]() | |
enum class | StoppingCondition { MinimumLossDecrease , LossGoal , MaximumSelectionErrorIncreases , MaximumEpochsNumber , MaximumTime } |
Enumeration of all possibles condition of stop for the algorithms. More... | |
Public Member Functions | |
ConjugateGradient () | |
ConjugateGradient (LossIndex *) | |
virtual | ~ConjugateGradient () |
Destructor. More... | |
const LearningRateAlgorithm & | get_learning_rate_algorithm () const |
Returns a constant reference to the learning rate algorithm object inside the conjugate gradient method object. More... | |
LearningRateAlgorithm * | get_learning_rate_algorithm_pointer () |
Returns a pointer to the learning rate algorithm object inside the conjugate gradient method object. More... | |
const TrainingDirectionMethod & | get_training_direction_method () const |
Returns the conjugate gradient training direction method used for training. More... | |
string | write_training_direction_method () const |
Returns a string with the name of the training direction. More... | |
const type & | get_minimum_loss_decrease () const |
Returns the minimum loss improvement during training. More... | |
const type & | get_loss_goal () const |
const Index & | get_maximum_selection_failures () const |
Returns the maximum number of selection error increases during the training process. More... | |
const Index & | get_maximum_epochs_number () const |
Returns the maximum number of epochs for training. More... | |
const type & | get_maximum_time () const |
Returns the maximum training time. More... | |
void | set_default () |
void | set_loss_index_pointer (LossIndex *) |
void | set_training_direction_method (const TrainingDirectionMethod &) |
void | set_training_direction_method (const string &) |
void | set_loss_goal (const type &) |
void | set_minimum_loss_decrease (const type &) |
void | set_maximum_selection_failures (const Index &) |
void | set_maximum_epochs_number (const Index &) |
void | set_maximum_time (const type &) |
void | set_save_period (const Index &) |
type | calculate_PR_parameter (const Tensor< type, 1 > &, const Tensor< type, 1 > &) const |
type | calculate_FR_parameter (const Tensor< type, 1 > &, const Tensor< type, 1 > &) const |
void | calculate_PR_training_direction (const Tensor< type, 1 > &, const Tensor< type, 1 > &, const Tensor< type, 1 > &, Tensor< type, 1 > &) const |
void | calculate_FR_training_direction (const Tensor< type, 1 > &, const Tensor< type, 1 > &, const Tensor< type, 1 > &, Tensor< type, 1 > &) const |
void | calculate_gradient_descent_training_direction (const Tensor< type, 1 > &, Tensor< type, 1 > &) const |
void | calculate_conjugate_gradient_training_direction (const Tensor< type, 1 > &, const Tensor< type, 1 > &, const Tensor< type, 1 > &, Tensor< type, 1 > &) const |
TrainingResults | perform_training () |
string | write_optimization_algorithm_type () const |
Write a string with best algorithm type for the model. More... | |
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 |
void | update_parameters (const DataSetBatch &batch, NeuralNetworkForwardPropagation &forward_propagation, LossIndexBackPropagation &back_propagation, ConjugateGradientData &optimization_data) |
ConjugateGradient::update_parameters. More... | |
![]() | |
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 | first_learning_rate = static_cast<type>(0.01) |
TrainingDirectionMethod | training_direction_method = ConjugateGradient::TrainingDirectionMethod::FR |
Applied method for calculating the conjugate gradient direction. More... | |
LearningRateAlgorithm | learning_rate_algorithm |
Learning rate algorithm object for one-dimensional minimization. More... | |
type | minimum_loss_decrease = type(0) |
Minimum loss improvement between two successive iterations. It is used as a stopping criterion. More... | |
type | training_loss_goal = type(0) |
Goal value for the loss. It is used as a stopping criterion. More... | |
Index | maximum_selection_failures |
Index | maximum_epochs_number |
Maximum number of epochs to perform_training. It is used as a stopping criterion. More... | |
type | maximum_time |
Maximum training time. It is used as a stopping criterion. More... | |
Additional Inherited Members | |
![]() | |
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)} |
In the conjugate gradient algorithms a search is performed along conjugate directions, which produces generally faster convergence than a search along the steepest descent directions. This concrete class represents a conjugate gradient training algorithm, based on solving sparse systems.
[1] https://www.neuraldesigner.com/blog/5_algorithms_to_train_a_neural_network
[2] D.P. O'Leary "The Block Conjugate Gradient Algorithm and Related Methods."
Definition at line 45 of file conjugate_gradient.h.
|
strong |
Enumeration of the available training operators for obtaining the training direction.
Definition at line 54 of file conjugate_gradient.h.
|
explicit |
Default constructor. It creates a conjugate gradient optimization algorithm object not associated to any loss index object. It also initializes the class members to their default values.
Definition at line 19 of file conjugate_gradient.cpp.
|
explicit |
Destructor. It creates a conjugate gradient optimization algorithm associated to a loss index object. It also initializes the rest of class members to their default values.
new_loss_index_pointer | Pointer to a loss index object. |
Definition at line 31 of file conjugate_gradient.cpp.
|
virtual |
Destructor.
Definition at line 42 of file conjugate_gradient.cpp.
void calculate_conjugate_gradient_training_direction | ( | const Tensor< type, 1 > & | old_gradient, |
const Tensor< type, 1 > & | gradient, | ||
const Tensor< type, 1 > & | old_training_direction, | ||
Tensor< type, 1 > & | training_direction | ||
) | const |
Returns the conjugate gradient training direction.
old_gradient | Gradient vector in the previous iteration. |
gradient | Current gradient vector. |
old_training_direction | Training direction in the previous iteration. |
Definition at line 641 of file conjugate_gradient.cpp.
type calculate_FR_parameter | ( | const Tensor< type, 1 > & | old_gradient, |
const Tensor< type, 1 > & | gradient | ||
) | const |
Returns the Fletcher-Reeves parameter used to calculate the training direction.
old_gradient | Previous error function gradient. |
gradient | Current error function gradient. |
Definition at line 327 of file conjugate_gradient.cpp.
void calculate_FR_training_direction | ( | const Tensor< type, 1 > & | old_gradient, |
const Tensor< type, 1 > & | gradient, | ||
const Tensor< type, 1 > & | old_training_direction, | ||
Tensor< type, 1 > & | training_direction | ||
) | const |
Returns the training direction using the Fletcher-Reeves update.
old_gradient | Previous error function gradient. |
gradient | Current error function gradient. |
old_training_direction | Previous training direction vector. |
Definition at line 561 of file conjugate_gradient.cpp.
void calculate_gradient_descent_training_direction | ( | const Tensor< type, 1 > & | gradient, |
Tensor< type, 1 > & | training_direction | ||
) | const |
Definition at line 630 of file conjugate_gradient.cpp.
type calculate_PR_parameter | ( | const Tensor< type, 1 > & | old_gradient, |
const Tensor< type, 1 > & | gradient | ||
) | const |
Returns the Polak-Ribiere parameter used to calculate the training direction.
old_gradient | Previous error function gradient. |
gradient | Current error function gradient. |
Definition at line 409 of file conjugate_gradient.cpp.
void calculate_PR_training_direction | ( | const Tensor< type, 1 > & | old_gradient, |
const Tensor< type, 1 > & | gradient, | ||
const Tensor< type, 1 > & | old_training_direction, | ||
Tensor< type, 1 > & | training_direction | ||
) | const |
Returns the training direction using the Polak-Ribiere update.
old_gradient | Previous error function gradient. |
gradient | Current error function gradient. |
old_training_direction | Previous training direction vector. |
Definition at line 492 of file conjugate_gradient.cpp.
|
virtual |
Deserializes the conjugate gradient object from a XML document of the TinyXML library.
document | TinyXML document containing the member data. |
Reimplemented from OptimizationAlgorithm.
Definition at line 1086 of file conjugate_gradient.cpp.
const LearningRateAlgorithm & get_learning_rate_algorithm | ( | ) | const |
Returns a constant reference to the learning rate algorithm object inside the conjugate gradient method object.
Definition at line 49 of file conjugate_gradient.cpp.
LearningRateAlgorithm * get_learning_rate_algorithm_pointer | ( | ) |
Returns a pointer to the learning rate algorithm object inside the conjugate gradient method object.
Definition at line 57 of file conjugate_gradient.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 99 of file conjugate_gradient.cpp.
const Index & get_maximum_epochs_number | ( | ) | const |
Returns the maximum number of epochs for training.
Definition at line 115 of file conjugate_gradient.cpp.
const Index & get_maximum_selection_failures | ( | ) | const |
Returns the maximum number of selection error increases during the training process.
Definition at line 107 of file conjugate_gradient.cpp.
const type & get_maximum_time | ( | ) | const |
Returns the maximum training time.
Definition at line 123 of file conjugate_gradient.cpp.
const type & get_minimum_loss_decrease | ( | ) | const |
Returns the minimum loss improvement during training.
Definition at line 90 of file conjugate_gradient.cpp.
const ConjugateGradient::TrainingDirectionMethod & get_training_direction_method | ( | ) | const |
Returns the conjugate gradient training direction method used for training.
Definition at line 65 of file conjugate_gradient.cpp.
|
virtual |
Trains a neural network with an associated loss index according to the conjugate gradient algorithm. Training occurs according to the training operators, training parameters and stopping criteria.
Implements OptimizationAlgorithm.
Definition at line 715 of file conjugate_gradient.cpp.
|
virtual |
Sets the default values into a conjugate gradient object. Training operators:
Training parameters:
Stopping criteria:
User stuff:
Reserve:
Reimplemented from OptimizationAlgorithm.
Definition at line 216 of file conjugate_gradient.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 248 of file conjugate_gradient.cpp.
|
virtual |
Sets a pointer to a loss index object to be associated to the conjugate gradient 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 133 of file conjugate_gradient.cpp.
void set_maximum_epochs_number | ( | const Index & | new_maximum_epochs_number | ) |
Sets a maximum number of epochs for training.
new_maximum_iterations_number | Maximum number of epochs for training. |
Definition at line 266 of file conjugate_gradient.cpp.
void set_maximum_selection_failures | ( | const Index & | new_maximum_selection_failures | ) |
Sets a new maximum number of selection error increases.
new_maximum_selection_failures | Maximum number of epochs in which the selection evalutation increases. |
Definition at line 257 of file conjugate_gradient.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 275 of file conjugate_gradient.cpp.
void set_minimum_loss_decrease | ( | const type & | new_minimum_loss_decrease | ) |
Sets a new minimum loss improvement during training.
new_minimum_loss_decrease | Minimum improvement in the loss between two iterations. |
Definition at line 238 of file conjugate_gradient.cpp.
void set_save_period | ( | const Index & | new_save_period | ) |
Sets a new number of iterations between the training saving progress.
new_save_period | Number of iterations between the training saving progress. |
Definition at line 302 of file conjugate_gradient.cpp.
void set_training_direction_method | ( | const string & | new_training_direction_method_name | ) |
Sets a new conjugate gradient training direction from a string representation. Possible values are:
new_training_direction_method_name | String with the name of the training direction method. |
Definition at line 159 of file conjugate_gradient.cpp.
void set_training_direction_method | ( | const TrainingDirectionMethod & | new_training_direction_method | ) |
Sets a new training direction method to be used for training.
new_training_direction_method | Conjugate gradient training direction method. |
Definition at line 144 of file conjugate_gradient.cpp.
|
virtual |
Writes as matrix of strings the most representative atributes.
Reimplemented from OptimizationAlgorithm.
Definition at line 933 of file conjugate_gradient.cpp.
void update_parameters | ( | const DataSetBatch & | batch, |
NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagation & | back_propagation, | ||
ConjugateGradientData & | optimization_data | ||
) |
ConjugateGradient::update_parameters.
batch | |
forward_propagation | |
back_propagation | |
optimization_data |
Definition at line 1335 of file conjugate_gradient.cpp.
|
virtual |
Write a string with best algorithm type for the model.
Reimplemented from OptimizationAlgorithm.
Definition at line 925 of file conjugate_gradient.cpp.
string write_training_direction_method | ( | ) | const |
Returns a string with the name of the training direction.
Definition at line 73 of file conjugate_gradient.cpp.
|
virtual |
Serializes the conjugate gradient 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 element.
Reimplemented from OptimizationAlgorithm.
Definition at line 984 of file conjugate_gradient.cpp.
|
private |
Definition at line 150 of file conjugate_gradient.h.
|
private |
Learning rate algorithm object for one-dimensional minimization.
Definition at line 158 of file conjugate_gradient.h.
|
private |
Maximum number of epochs to perform_training. It is used as a stopping criterion.
Definition at line 177 of file conjugate_gradient.h.
|
private |
Maximum number of epochs at which the selection error increases. This is an early stopping method for improving selection.
Definition at line 173 of file conjugate_gradient.h.
|
private |
Maximum training time. It is used as a stopping criterion.
Definition at line 181 of file conjugate_gradient.h.
|
private |
Minimum loss improvement between two successive iterations. It is used as a stopping criterion.
Definition at line 164 of file conjugate_gradient.h.
|
private |
Applied method for calculating the conjugate gradient direction.
Definition at line 154 of file conjugate_gradient.h.
|
private |
Goal value for the loss. It is used as a stopping criterion.
Definition at line 168 of file conjugate_gradient.h.