OpenNN  2.2
Open Neural Networks Library
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
OpenNN::ConjugateGradient Class Reference

#include <conjugate_gradient.h>

Inheritance diagram for OpenNN::ConjugateGradient:
OpenNN::TrainingAlgorithm

Classes

struct  ConjugateGradientResults
 

Public Types

enum  TrainingDirectionMethod { PR, FR }
 

Public Member Functions

 ConjugateGradient (void)
 
 ConjugateGradient (PerformanceFunctional *)
 
 ConjugateGradient (const tinyxml2::XMLDocument &)
 
virtual ~ConjugateGradient (void)
 
const TrainingRateAlgorithmget_training_rate_algorithm (void) const
 
TrainingRateAlgorithmget_training_rate_algorithm_pointer (void)
 
const TrainingDirectionMethodget_training_direction_method (void) const
 
std::string write_training_direction_method (void) const
 
const double & get_warning_parameters_norm (void) const
 
const double & get_warning_gradient_norm (void) const
 
const double & get_warning_training_rate (void) const
 
const double & get_error_parameters_norm (void) const
 
const double & get_error_gradient_norm (void) const
 
const double & get_error_training_rate (void) const
 
const double & get_minimum_parameters_increment_norm (void) const
 
const double & get_minimum_performance_increase (void) const
 
const double & get_performance_goal (void) const
 
const size_t & get_maximum_generalization_performance_decreases (void) const
 
const double & get_gradient_norm_goal (void) const
 
const size_t & get_maximum_iterations_number (void) const
 
const double & get_maximum_time (void) const
 
const bool & get_reserve_parameters_history (void) const
 
const bool & get_reserve_parameters_norm_history (void) const
 
const bool & get_reserve_performance_history (void) const
 
const bool & get_reserve_generalization_performance_history (void) const
 
const bool & get_reserve_gradient_history (void) const
 
const bool & get_reserve_gradient_norm_history (void) const
 
const bool & get_reserve_training_direction_history (void) const
 
const bool & get_reserve_training_rate_history (void) const
 
const bool & get_reserve_elapsed_time_history (void) const
 
void set_default (void)
 
void set_performance_functional_pointer (PerformanceFunctional *)
 
void set_training_direction_method (const TrainingDirectionMethod &)
 
void set_training_direction_method (const std::string &)
 
void set_warning_parameters_norm (const double &)
 
void set_warning_gradient_norm (const double &)
 
void set_warning_training_rate (const double &)
 
void set_error_parameters_norm (const double &)
 
void set_error_gradient_norm (const double &)
 
void set_error_training_rate (const double &)
 
void set_minimum_parameters_increment_norm (const double &)
 
void set_performance_goal (const double &)
 
void set_minimum_performance_increase (const double &)
 
void set_maximum_generalization_performance_decreases (const size_t &)
 
void set_gradient_norm_goal (const double &)
 
void set_maximum_iterations_number (const size_t &)
 
void set_maximum_time (const double &)
 
void set_reserve_parameters_history (const bool &)
 
void set_reserve_parameters_norm_history (const bool &)
 
void set_reserve_performance_history (const bool &)
 
void set_reserve_generalization_performance_history (const bool &)
 
void set_reserve_gradient_history (const bool &)
 
void set_reserve_gradient_norm_history (const bool &)
 
void set_reserve_training_direction_history (const bool &)
 
void set_reserve_training_rate_history (const bool &)
 
void set_reserve_elapsed_time_history (const bool &)
 
void set_reserve_all_training_history (const bool &)
 
void set_display_period (const size_t &)
 
void set_save_period (const size_t &)
 
double calculate_PR_parameter (const Vector< double > &, const Vector< double > &) const
 
double calculate_FR_parameter (const Vector< double > &, const Vector< double > &) const
 
Vector< double > calculate_PR_training_direction (const Vector< double > &, const Vector< double > &, const Vector< double > &) const
 
Vector< double > calculate_FR_training_direction (const Vector< double > &, const Vector< double > &, const Vector< double > &) const
 
Vector< double > calculate_gradient_descent_training_direction (const Vector< double > &) const
 
Vector< double > calculate_training_direction (const Vector< double > &, const Vector< double > &, const Vector< double > &) const
 
ConjugateGradientResultsperform_training (void)
 
std::string write_training_algorithm_type (void) const
 
Matrix< std::string > to_string_matrix (void) const
 
tinyxml2::XMLDocument * to_XML (void) const
 
void from_XML (const tinyxml2::XMLDocument &)
 
- Public Member Functions inherited from OpenNN::TrainingAlgorithm
 TrainingAlgorithm (void)
 
 TrainingAlgorithm (PerformanceFunctional *)
 
 TrainingAlgorithm (const tinyxml2::XMLDocument &)
 
virtual ~TrainingAlgorithm (void)
 
virtual TrainingAlgorithmoperator= (const TrainingAlgorithm &)
 
virtual bool operator== (const TrainingAlgorithm &) const
 
PerformanceFunctionalget_performance_functional_pointer (void) const
 
bool has_performance_functional (void) const
 
const bool & get_display (void) const
 
const size_t & get_display_period (void) const
 
const size_t & get_save_period (void) const
 
const std::string & get_neural_network_file_name (void) const
 
void set (void)
 
void set (PerformanceFunctional *)
 
void set_display (const bool &)
 
void set_display_period (const size_t &)
 
void set_save_period (const size_t &)
 
void set_neural_network_file_name (const std::string &)
 
virtual void check (void) const
 
virtual std::string to_string (void) const
 
void print (void) const
 
void save (const std::string &) const
 
void load (const std::string &)
 
virtual void initialize_random (void)
 

Private Attributes

TrainingDirectionMethod training_direction_method
 
TrainingRateAlgorithm training_rate_algorithm
 
double warning_parameters_norm
 
double warning_gradient_norm
 
double warning_training_rate
 
double error_parameters_norm
 
double error_gradient_norm
 
double error_training_rate
 
double minimum_parameters_increment_norm
 
double minimum_performance_increase
 
double performance_goal
 
double gradient_norm_goal
 
size_t maximum_generalization_performance_decreases
 
size_t maximum_iterations_number
 
double maximum_time
 
bool reserve_parameters_history
 
bool reserve_parameters_norm_history
 
bool reserve_performance_history
 
bool reserve_gradient_history
 
bool reserve_gradient_norm_history
 
bool reserve_training_direction_history
 
bool reserve_training_rate_history
 
bool reserve_elapsed_time_history
 
bool reserve_generalization_performance_history
 

Additional Inherited Members

- Protected Attributes inherited from OpenNN::TrainingAlgorithm
PerformanceFunctionalperformance_functional_pointer
 
size_t display_period
 
size_t save_period
 
std::string neural_network_file_name
 
bool display
 

Detailed Description

This concrete class represents a conjugate gradient training algorithm for a performance functional of a neural network.

Definition at line 47 of file conjugate_gradient.h.

Constructor & Destructor Documentation

OpenNN::ConjugateGradient::ConjugateGradient ( void  )
explicit

Default constructor. It creates a conjugate gradient training algorithm object not associated to any performance functional object. It also initializes the class members to their default values.

Definition at line 27 of file conjugate_gradient.cpp.

OpenNN::ConjugateGradient::ConjugateGradient ( PerformanceFunctional new_performance_functional_pointer)
explicit

General constructor. It creates a conjugate gradient training algorithm associated to a performance functional object. It also initializes the rest of class members to their default values.

Parameters
new_performance_functional_pointerPointer to a performance functional object.

Definition at line 40 of file conjugate_gradient.cpp.

OpenNN::ConjugateGradient::ConjugateGradient ( const tinyxml2::XMLDocument &  conjugate_gradient_document)
explicit

XML constructor. It creates a conjugate gradient training algorithm not associated to any performance functional object. It also loads the class members from a XML document.

Parameters
conjugate_gradient_documentTinyXML document with the members of a conjugate gradient object.

Definition at line 56 of file conjugate_gradient.cpp.

Member Function Documentation

double OpenNN::ConjugateGradient::calculate_FR_parameter ( const Vector< double > &  old_gradient,
const Vector< double > &  gradient 
) const

Returns the Fletcher-Reeves parameter used to calculate the training direction.

Parameters
old_gradientPrevious objective function gradient.
gradientCurrent objective function gradient.

Definition at line 1059 of file conjugate_gradient.cpp.

Vector< double > OpenNN::ConjugateGradient::calculate_FR_training_direction ( const Vector< double > &  old_gradient,
const Vector< double > &  gradient,
const Vector< double > &  old_training_direction 
) const

Returns the training direction using the Fletcher-Reeves update.

Parameters
old_gradientPrevious objective function gradient.
gradientCurrent objective function gradient.
old_training_directionPrevious training direction vector.

Definition at line 1302 of file conjugate_gradient.cpp.

Vector< double > OpenNN::ConjugateGradient::calculate_gradient_descent_training_direction ( const Vector< double > &  gradient) const

Returns the gradient descent training direction, which is the negative of the normalized gradient.

Parameters
gradientGradient vector.

Definition at line 1476 of file conjugate_gradient.cpp.

double OpenNN::ConjugateGradient::calculate_PR_parameter ( const Vector< double > &  old_gradient,
const Vector< double > &  gradient 
) const

Returns the Polak-Ribiere parameter used to calculate the training direction.

Parameters
old_gradientPrevious objective function gradient.
gradientCurrent objective function gradient.

Definition at line 1139 of file conjugate_gradient.cpp.

Vector< double > OpenNN::ConjugateGradient::calculate_PR_training_direction ( const Vector< double > &  old_gradient,
const Vector< double > &  gradient,
const Vector< double > &  old_training_direction 
) const

Returns the training direction using the Polak-Ribiere update.

Parameters
old_gradientPrevious objective function gradient.
gradientCurrent objective function gradient.
old_training_directionPrevious training direction vector.

Definition at line 1225 of file conjugate_gradient.cpp.

Vector< double > OpenNN::ConjugateGradient::calculate_training_direction ( const Vector< double > &  old_gradient,
const Vector< double > &  gradient,
const Vector< double > &  old_training_direction 
) const

Returns the conjugate gradient training direction, which has been previously normalized.

Parameters
old_gradientGradient vector in the previous iteration.
gradientCurrent gradient vector.
old_training_directionTraining direction in the previous iteration.

Definition at line 1379 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::from_XML ( const tinyxml2::XMLDocument &  document)
virtual

Deserializes the conjugate gradient object from a XML document of the TinyXML library.

Parameters
documentTinyXML document containing the member data.

Reimplemented from OpenNN::TrainingAlgorithm.

Definition at line 2729 of file conjugate_gradient.cpp.

const double & OpenNN::ConjugateGradient::get_error_gradient_norm ( void  ) const

Returns the value for the norm of the gradient vector at wich an error message is written to the screen and the program exits.

Definition at line 186 of file conjugate_gradient.cpp.

const double & OpenNN::ConjugateGradient::get_error_training_rate ( void  ) const

Returns the training rate value at wich the line minimization algorithm is assumed to fail when bracketing a minimum.

Definition at line 197 of file conjugate_gradient.cpp.

const double & OpenNN::ConjugateGradient::get_gradient_norm_goal ( void  ) const

Returns the goal value for the norm of the objective function gradient. This is used as a stopping criterion when training a multilayer perceptron

Definition at line 239 of file conjugate_gradient.cpp.

const double & OpenNN::ConjugateGradient::get_performance_goal ( void  ) const

Returns the goal value for the performance. This is used as a stopping criterion when training a multilayer perceptron

Definition at line 228 of file conjugate_gradient.cpp.

ConjugateGradient::ConjugateGradientResults * OpenNN::ConjugateGradient::perform_training ( void  )
virtual

Trains a neural network with an associated performance functional according to the conjugate gradient algorithm. Training occurs according to the training operators, training parameters and stopping criteria.

Implements OpenNN::TrainingAlgorithm.

Definition at line 1770 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_default ( void  )
virtual

Sets the default values into a conjugate gradient object. Training operators:

  • Training direction method = Polak-Ribiere;
  • Training rate method = Brent;

Training parameters:

  • First training rate: 1.0.
  • Bracketing factor: 2.0.
  • Training rate tolerance: 1.0e-3.

Stopping criteria:

  • Performance goal: -1.0e99.
  • Gradient norm goal: 0.0.
  • Maximum training time: 1.0e6.
  • Maximum number of iterations: 100.

User stuff:

  • Warning training rate: 1.0e6.
  • Error training rate: 1.0e12.
  • Display: true.
  • Display period: 10.
  • Save period: 0.

Reserve:

  • Reserve training direction history: false.
  • Reserve training direction norm history: false.
  • Reserve training rate history: false.

Reimplemented from OpenNN::TrainingAlgorithm.

Definition at line 504 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_display_period ( const size_t &  new_display_period)

Sets a new number of iterations between the training showing progress.

Parameters
new_display_periodNumber of iterations between the training showing progress.

Definition at line 1000 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_error_gradient_norm ( const double &  new_error_gradient_norm)

Sets a new value for the gradient vector norm at which an error message is written to the screen and the program exits.

Parameters
new_error_gradient_normError norm of gradient vector value.

Definition at line 679 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_error_parameters_norm ( const double &  new_error_parameters_norm)

Sets a new value for the parameters vector norm at which an error message is written to the screen and the program exits.

Parameters
new_error_parameters_normError norm of parameters vector value.

Definition at line 648 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_error_training_rate ( const double &  new_error_training_rate)

Sets a new training rate value at wich a the line minimization algorithm is assumed to fail when bracketing a minimum.

Parameters
new_error_training_rateError training rate value.

Definition at line 710 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_gradient_norm_goal ( const double &  new_gradient_norm_goal)

Sets a new the goal value for the norm of the objective function gradient. This is used as a stopping criterion when training a multilayer perceptron

Parameters
new_gradient_norm_goalGoal value for the norm of the objective function gradient.

Definition at line 813 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_maximum_generalization_performance_decreases ( const size_t &  new_maximum_generalization_performance_decreases)

Sets a new maximum number of generalization failures.

Parameters
new_maximum_generalization_performance_decreasesMaximum number of iterations in which the generalization evalutation decreases.

Definition at line 843 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_maximum_iterations_number ( const size_t &  new_maximum_iterations_number)

Sets a maximum number of iterations for training.

Parameters
new_maximum_iterations_numberMaximum number of iterations for training.

Definition at line 854 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_maximum_time ( const double &  new_maximum_time)

Sets a new maximum training time.

Parameters
new_maximum_timeMaximum training time.

Definition at line 865 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_minimum_parameters_increment_norm ( const double &  new_minimum_parameters_increment_norm)

Sets a new value for the minimum parameters increment norm stopping criterion.

Parameters
new_minimum_parameters_increment_normValue of norm of parameters increment norm used to stop training.

Definition at line 740 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_minimum_performance_increase ( const double &  new_minimum_performance_increase)

Sets a new minimum performance improvement during training.

Parameters
new_minimum_performance_increaseMinimum improvement in the performance between two iterations.

Definition at line 770 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_performance_functional_pointer ( PerformanceFunctional new_performance_functional_pointer)
virtual

Sets a pointer to a performance functional object to be associated to the conjugate gradient object. It also sets that performance functional to the training rate algorithm.

Parameters
new_performance_functional_pointerPointer to a performance functional object.

Reimplemented from OpenNN::TrainingAlgorithm.

Definition at line 372 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_performance_goal ( const double &  new_performance_goal)

Sets a new goal value for the performance. This is used as a stopping criterion when training a multilayer perceptron

Parameters
new_performance_goalGoal value for the performance.

Definition at line 801 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_all_training_history ( const bool &  new_reserve_all_training_history)

Makes the training history of all variables to reseved or not in memory when training.

  • Parameters.
  • Parameters norm.
  • performance.
  • Gradient.
  • Gradient norm.
  • Generalization performance.
  • Training direction.
  • Training direction norm.
  • Training rate.
Parameters
new_reserve_all_training_historyTrue if all training history variables are to be reserved, false otherwise.

Definition at line 443 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_elapsed_time_history ( const bool &  new_reserve_elapsed_time_history)

Makes the elapsed time over the iterations to be reseved or not in memory. This is a vector.

Parameters
new_reserve_elapsed_time_historyTrue if the elapsed time history vector is to be reserved, false otherwise.

Definition at line 976 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_generalization_performance_history ( const bool &  new_reserve_generalization_performance_history)

Makes the Generalization performance history to be reserved or not in memory. This is a vector.

Parameters
new_reserve_generalization_performance_historyTrue if the Generalization performance history is to be reserved, false otherwise.

Definition at line 988 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_gradient_history ( const bool &  new_reserve_gradient_history)

Makes the gradient history vector of vectors to be reseved or not in memory.

Parameters
new_reserve_gradient_historyTrue if the gradient history matrix is to be reserved, false otherwise.

Definition at line 928 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_gradient_norm_history ( const bool &  new_reserve_gradient_norm_history)

Makes the gradient norm history vector to be reseved or not in memory.

Parameters
new_reserve_gradient_norm_historyTrue if the gradient norm history matrix is to be reserved, false otherwise.

Definition at line 940 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_parameters_history ( const bool &  new_reserve_parameters_history)

Makes the parameters history vector of vectors to be reseved or not in memory.

Parameters
new_reserve_parameters_historyTrue if the parameters history vector of vectors is to be reserved, false otherwise.

Definition at line 895 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_parameters_norm_history ( const bool &  new_reserve_parameters_norm_history)

Makes the parameters norm history vector to be reseved or not in memory.

Parameters
new_reserve_parameters_norm_historyTrue if the parameters norm history vector is to be reserved, false otherwise.

Definition at line 906 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_performance_history ( const bool &  new_reserve_performance_history)

Makes the performance history vector to be reseved or not in memory.

Parameters
new_reserve_performance_historyTrue if the performance history vector is to be reserved, false otherwise.

Definition at line 917 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_training_direction_history ( const bool &  new_reserve_training_direction_history)

Makes the training direction history vector of vectors to be reseved or not in memory.

Parameters
new_reserve_training_direction_historyTrue if the training direction history matrix is to be reserved, false otherwise.

Definition at line 952 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_reserve_training_rate_history ( const bool &  new_reserve_training_rate_history)

Makes the training rate history vector to be reseved or not in memory.

Parameters
new_reserve_training_rate_historyTrue if the training rate history vector is to be reserved, false otherwise.

Definition at line 964 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_save_period ( const size_t &  new_save_period)

Sets a new number of iterations between the training saving progress.

Parameters
new_save_periodNumber of iterations between the training saving progress.

Definition at line 1029 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_training_direction_method ( const TrainingDirectionMethod new_training_direction_method)

Sets a new training direction method to be used for training.

Parameters
new_training_direction_methodConjugate gradient training direction method.

Definition at line 386 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_training_direction_method ( const std::string &  new_training_direction_method_name)

Sets a new conjugate gradient training direction from a string representation. Possible values are:

  • "PR"
  • "FR"
Parameters
new_training_direction_method_nameString with the name of the training direction method.

Definition at line 402 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_warning_gradient_norm ( const double &  new_warning_gradient_norm)

Sets a new value for the gradient vector norm at which a warning message is written to the screen.

Parameters
new_warning_gradient_normWarning norm of gradient vector value.

Definition at line 588 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_warning_parameters_norm ( const double &  new_warning_parameters_norm)

Sets a new value for the parameters vector norm at which a warning message is written to the screen.

Parameters
new_warning_parameters_normWarning norm of parameters vector value.

Definition at line 557 of file conjugate_gradient.cpp.

void OpenNN::ConjugateGradient::set_warning_training_rate ( const double &  new_warning_training_rate)

Sets a new training rate value at wich a warning message is written to the screen during line minimization.

Parameters
new_warning_training_rateWarning training rate value.

Definition at line 619 of file conjugate_gradient.cpp.

Matrix< std::string > OpenNN::ConjugateGradient::to_string_matrix ( void  ) const
virtual

Returns a default (empty) string matrix containing the members of the training algorithm object.

Reimplemented from OpenNN::TrainingAlgorithm.

Definition at line 2187 of file conjugate_gradient.cpp.

tinyxml2::XMLDocument * OpenNN::ConjugateGradient::to_XML ( void  ) const
virtual

Serializes the conjugate gradient object into a XML document of the TinyXML library. See the OpenNN manual for more information about the format of this element.

Reimplemented from OpenNN::TrainingAlgorithm.

Definition at line 2360 of file conjugate_gradient.cpp.

Member Data Documentation

size_t OpenNN::ConjugateGradient::maximum_generalization_performance_decreases
private

Maximum number of iterations at which the generalization performance decreases. This is an early stopping method for improving generalization.

Definition at line 380 of file conjugate_gradient.h.


The documentation for this class was generated from the following files: