#include <optimization_algorithm.h>
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... | |
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_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 |
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 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.
|
strong |
Enumeration of all possibles condition of stop for the algorithms.
Definition at line 54 of file optimization_algorithm.h.
|
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.
|
explicit |
It creates a optimization algorithm object associated to a loss index object.
new_loss_index_pointer | Pointer to a loss index object. |
Definition at line 31 of file optimization_algorithm.cpp.
|
virtual |
Destructor.
Definition at line 44 of file optimization_algorithm.cpp.
|
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.
|
virtual |
Loads a default optimization algorithm from a XML document.
document | TinyXML document containing the error term members. |
Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.
Definition at line 317 of file optimization_algorithm.cpp.
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.
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.
string get_hardware_use | ( | ) | const |
Hardware use.
Returns the hardware used. Default: Multi-core.
Definition at line 77 of file optimization_algorithm.cpp.
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.
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.
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.
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.
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.
file_name | Name of optimization algorithm XML-type file. |
Definition at line 388 of file optimization_algorithm.cpp.
|
pure virtual |
Trains a neural network which has a loss index associated.
Implemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, LevenbergMarquardtAlgorithm, QuasiNewtonMethod, and StochasticGradientDescent.
|
virtual |
Prints to the screen the XML-type representation of the optimization algorithm object.
Definition at line 364 of file optimization_algorithm.cpp.
void save | ( | const string & | file_name | ) | const |
Saves to a XML-type file the members of the optimization algorithm object.
file_name | Name of optimization algorithm XML-type file. |
Definition at line 372 of file optimization_algorithm.cpp.
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.
|
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.
|
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.
new_display | Display value. |
Reimplemented in QuasiNewtonMethod.
Definition at line 175 of file optimization_algorithm.cpp.
void set_display_period | ( | const Index & | new_display_period | ) |
Sets a new number of iterations between the training showing progress.
new_display_period | Number of iterations between the training showing progress. |
Definition at line 185 of file optimization_algorithm.cpp.
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.
|
virtual |
Sets a pointer to a loss index object to be associated to the optimization algorithm.
new_loss_index_pointer | Pointer to a loss index object. |
Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, GradientDescent, QuasiNewtonMethod, and StochasticGradientDescent.
Definition at line 164 of file optimization_algorithm.cpp.
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.
new_neural_network_file_name | File name for the neural network object. |
Definition at line 235 of file optimization_algorithm.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 210 of file optimization_algorithm.cpp.
|
virtual |
Definition at line 151 of file optimization_algorithm.cpp.
|
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.
|
inlinevirtual |
Reimplemented in AdaptiveMomentEstimation, ConjugateGradient, and LevenbergMarquardtAlgorithm.
Definition at line 106 of file optimization_algorithm.h.
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.
|
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.
|
protected |
Definition at line 158 of file optimization_algorithm.h.
|
protected |
Definition at line 156 of file optimization_algorithm.h.
|
protected |
Display messages to screen.
Definition at line 154 of file optimization_algorithm.h.
|
protected |
Number of iterations between the training showing progress.
Definition at line 142 of file optimization_algorithm.h.
|
protected |
Number of training epochs in the neural network.
Definition at line 132 of file optimization_algorithm.h.
|
protected |
Hardware use.
Definition at line 138 of file optimization_algorithm.h.
|
protected |
Pointer to a loss index for a neural network object.
Definition at line 128 of file optimization_algorithm.h.
|
protected |
Path where the neural network is saved.
Definition at line 150 of file optimization_algorithm.h.
|
protected |
Definition at line 123 of file optimization_algorithm.h.
|
protected |
Definition at line 157 of file optimization_algorithm.h.
|
protected |
Number of iterations between the training saving progress.
Definition at line 146 of file optimization_algorithm.h.
|
protected |
Definition at line 124 of file optimization_algorithm.h.