OptimizationAlgorithm Class Referenceabstract

#include <optimization_algorithm.h>

Inheritance diagram for OptimizationAlgorithm:
AdaptiveMomentEstimation ConjugateGradient GradientDescent LevenbergMarquardtAlgorithm QuasiNewtonMethod StochasticGradientDescent

Public Types

enum class  StoppingCondition {
  MinimumLossDecrease , LossGoal , MaximumSelectionErrorIncreases , MaximumEpochsNumber ,
  MaximumTime
}
 Enumeration of all possibles condition of stop for the algorithms. More...
 

Public Member Functions

 OptimizationAlgorithm ()
 
 OptimizationAlgorithm (LossIndex *)
 
virtual ~OptimizationAlgorithm ()
 Destructor. More...
 
LossIndexget_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_default ()
 Sets the members of the optimization algorithm object to their default values. More...
 
virtual void set_threads_number (const int &)
 
virtual void set_loss_index_pointer (LossIndex *)
 
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 TrainingResults perform_training ()=0
 Trains a neural network which has a loss index associated. More...
 
virtual string write_optimization_algorithm_type () const
 
virtual void print () const
 Prints to the screen the XML-type representation of the optimization algorithm object. More...
 
virtual Tensor< string, 2 > to_string_matrix () const
 
virtual void from_XML (const tinyxml2::XMLDocument &)
 
virtual void write_XML (tinyxml2::XMLPrinter &) const
 
void save (const string &) const
 
void load (const string &)
 

Protected Attributes

NonBlockingThreadPool * non_blocking_thread_pool = nullptr
 
ThreadPoolDevice * thread_pool_device
 
LossIndexloss_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)}
 

Detailed Description

This abstract class represents the concept of optimization algorithm for a neural network in OpenNN library. Any derived class must implement the perform_training() method.

Definition at line 41 of file optimization_algorithm.h.

Member Enumeration Documentation

◆ StoppingCondition

enum class StoppingCondition
strong

Enumeration of all possibles condition of stop for the algorithms.

Definition at line 54 of file optimization_algorithm.h.

Constructor & Destructor Documentation

◆ OptimizationAlgorithm() [1/2]

OptimizationAlgorithm ( )
explicit

Default constructor. It creates a optimization algorithm object not associated to any loss index object.

Definition at line 17 of file optimization_algorithm.cpp.

◆ OptimizationAlgorithm() [2/2]

OptimizationAlgorithm ( LossIndex new_loss_index_pointer)
explicit

It creates a optimization algorithm object associated to a loss index object.

Parameters
new_loss_index_pointerPointer to a loss index object.

Definition at line 31 of file optimization_algorithm.cpp.

◆ ~OptimizationAlgorithm()

~OptimizationAlgorithm ( )
virtual

Destructor.

Definition at line 44 of file optimization_algorithm.cpp.

Member Function Documentation

◆ check()

void check ( ) const
virtual

Performs a default checking for optimization algorithms. In particular, it checks that the loss index pointer associated to the optimization algorithm is not nullptr, and that the neural network associated to that loss index is neither nullptr. If that checkings are not hold, an exception is thrown.

Reimplemented in LevenbergMarquardtAlgorithm.

Definition at line 260 of file optimization_algorithm.cpp.

◆ from_XML()

void from_XML ( const tinyxml2::XMLDocument document)
virtual

Loads a default optimization algorithm from a XML document.

Parameters
documentTinyXML document containing the error term members.

Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.

Definition at line 317 of file optimization_algorithm.cpp.

◆ get_display()

const bool & get_display ( ) const

Returns true if messages from this class can be displayed on the screen, or false if messages from this class can't be displayed on the screen.

Definition at line 110 of file optimization_algorithm.cpp.

◆ get_display_period()

const Index & get_display_period ( ) const

Returns the number of iterations between the training showing progress.

Definition at line 118 of file optimization_algorithm.cpp.

◆ get_hardware_use()

string get_hardware_use ( ) const

Hardware use.

Returns the hardware used. Default: Multi-core.

Definition at line 77 of file optimization_algorithm.cpp.

◆ get_loss_index_pointer()

LossIndex * get_loss_index_pointer ( ) const

Returns a pointer to the loss index object to which the optimization algorithm is associated.

Definition at line 54 of file optimization_algorithm.cpp.

◆ get_neural_network_file_name()

const string & get_neural_network_file_name ( ) const

Returns the file name where the neural network will be saved.

Definition at line 134 of file optimization_algorithm.cpp.

◆ get_save_period()

const Index & get_save_period ( ) const

Returns the number of iterations between the training saving progress.

Definition at line 126 of file optimization_algorithm.cpp.

◆ has_loss_index()

bool has_loss_index ( ) const

Returns true if this optimization algorithm object has an associated loss index object, and false otherwise.

Definition at line 94 of file optimization_algorithm.cpp.

◆ load()

void load ( const string &  file_name)

Loads a gradient descent object from a XML-type file. Please mind about the file format, wich is specified in the User's Guide.

Parameters
file_nameName of optimization algorithm XML-type file.

Definition at line 388 of file optimization_algorithm.cpp.

◆ perform_training()

virtual TrainingResults perform_training ( )
pure virtual

Trains a neural network which has a loss index associated.

Implemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.

◆ print()

void print ( ) const
virtual

Prints to the screen the XML-type representation of the optimization algorithm object.

Definition at line 364 of file optimization_algorithm.cpp.

◆ save()

void save ( const string &  file_name) const

Saves to a XML-type file the members of the optimization algorithm object.

Parameters
file_nameName of optimization algorithm XML-type file.

Definition at line 372 of file optimization_algorithm.cpp.

◆ set()

void set ( )

Sets the loss index pointer to nullptr. It also sets the rest of members to their default values.

Definition at line 143 of file optimization_algorithm.cpp.

◆ set_default()

void set_default ( )
virtual

Sets the members of the optimization algorithm object to their default values.

Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.

Definition at line 243 of file optimization_algorithm.cpp.

◆ set_display()

void set_display ( const bool &  new_display)
virtual

Sets a new display value. If it is set to true messages from this class are to be displayed on the screen; if it is set to false messages from this class are not to be displayed on the screen.

Parameters
new_displayDisplay value.

Reimplemented in QuasiNewtonMethod.

Definition at line 175 of file optimization_algorithm.cpp.

◆ set_display_period()

void set_display_period ( const Index &  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 185 of file optimization_algorithm.cpp.

◆ set_hardware_use()

void set_hardware_use ( const string &  new_hardware_use)

Set hardware to use. Default: Multi-core.

Definition at line 85 of file optimization_algorithm.cpp.

◆ set_loss_index_pointer()

void set_loss_index_pointer ( LossIndex new_loss_index_pointer)
virtual

Sets a pointer to a loss index object to be associated to the optimization algorithm.

Parameters
new_loss_index_pointerPointer to a loss index object.

Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, QuasiNewtonMethod, and StochasticGradientDescent.

Definition at line 164 of file optimization_algorithm.cpp.

◆ set_neural_network_file_name()

void set_neural_network_file_name ( const string &  new_neural_network_file_name)

Sets a new file name where the neural network will be saved.

Parameters
new_neural_network_file_nameFile name for the neural network object.

Definition at line 235 of file optimization_algorithm.cpp.

◆ set_save_period()

void set_save_period ( const Index &  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 210 of file optimization_algorithm.cpp.

◆ set_threads_number()

void set_threads_number ( const int &  new_threads_number)
virtual

Definition at line 151 of file optimization_algorithm.cpp.

◆ to_string_matrix()

Tensor< string, 2 > to_string_matrix ( ) const
virtual

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

Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.

Definition at line 356 of file optimization_algorithm.cpp.

◆ write_optimization_algorithm_type()

virtual string write_optimization_algorithm_type ( ) const
inlinevirtual

◆ write_time()

const string write_time ( const type &  time) const

Writes the time from seconds in format HH:mm:ss.

Definition at line 483 of file optimization_algorithm.cpp.

◆ write_XML()

void write_XML ( tinyxml2::XMLPrinter file_stream) const
virtual

Serializes the optimization algorithm 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 in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.

Definition at line 293 of file optimization_algorithm.cpp.

Member Data Documentation

◆ A_B

const Eigen::array<IndexPair<Index>, 1> A_B = {IndexPair<Index>(1, 0)}
protected

Definition at line 158 of file optimization_algorithm.h.

◆ AT_B

const Eigen::array<IndexPair<Index>, 1> AT_B = {IndexPair<Index>(0, 0)}
protected

Definition at line 156 of file optimization_algorithm.h.

◆ display

bool display = true
protected

Display messages to screen.

Definition at line 154 of file optimization_algorithm.h.

◆ display_period

Index display_period = 10
protected

Number of iterations between the training showing progress.

Definition at line 142 of file optimization_algorithm.h.

◆ epochs_number

Index epochs_number = 10000
protected

Number of training epochs in the neural network.

Definition at line 132 of file optimization_algorithm.h.

◆ hardware_use

string hardware_use = "Multi-core"
protected

Hardware use.

Definition at line 138 of file optimization_algorithm.h.

◆ loss_index_pointer

LossIndex* loss_index_pointer = nullptr
protected

Pointer to a loss index for a neural network object.

Definition at line 128 of file optimization_algorithm.h.

◆ neural_network_file_name

string neural_network_file_name = "neural_network.xml"
protected

Path where the neural network is saved.

Definition at line 150 of file optimization_algorithm.h.

◆ non_blocking_thread_pool

NonBlockingThreadPool* non_blocking_thread_pool = nullptr
protected

Definition at line 123 of file optimization_algorithm.h.

◆ product_vector_matrix

const Eigen::array<IndexPair<Index>, 1> product_vector_matrix = {IndexPair<Index>(0, 1)}
protected

Definition at line 157 of file optimization_algorithm.h.

◆ save_period

Index save_period = numeric_limits<Index>::max()
protected

Number of iterations between the training saving progress.

Definition at line 146 of file optimization_algorithm.h.

◆ thread_pool_device

ThreadPoolDevice* thread_pool_device
protected

Definition at line 124 of file optimization_algorithm.h.


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