This abstract class represents the concept of loss index composed of an error term and a regularization term. More...
#include <loss_index.h>
Public Types | |
enum class | RegularizationMethod { L1 , L2 , NoRegularization } |
Enumeration of available regularization methods. More... | |
Protected Attributes | |
NonBlockingThreadPool * | non_blocking_thread_pool = nullptr |
ThreadPoolDevice * | thread_pool_device = nullptr |
NeuralNetwork * | neural_network_pointer = nullptr |
Pointer to a neural network object. More... | |
DataSet * | data_set_pointer = nullptr |
Pointer to a data set object. More... | |
RegularizationMethod | regularization_method = RegularizationMethod::L2 |
Pointer to a regularization method object. More... | |
type | regularization_weight = static_cast<type>(0.01) |
Regularization weight value. 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 > | A_B = {IndexPair<Index>(1, 0)} |
const Eigen::array< IndexPair< Index >, 2 > | SSE = {IndexPair<Index>(0, 0), IndexPair<Index>(1, 1)} |
const Eigen::array< int, 1 > | rows_sum = {Eigen::array<int, 1>({1})} |
This abstract class represents the concept of loss index composed of an error term and a regularization term.
The error term could be:
Definition at line 47 of file loss_index.h.
|
strong |
Enumeration of available regularization methods.
Definition at line 66 of file loss_index.h.
|
explicit |
Default constructor. It creates a default error term object, with all pointers initialized to nullptr. It also initializes all the rest of class members to their default values.
Definition at line 18 of file loss_index.cpp.
|
explicit |
Neural network and data set constructor. It creates a error term object associated to a neural network and to be measured on a data set. The rest of pointers are initialized to nullptr. It also initializes all the rest of class members to their default values.
new_neural_network_pointer | Pointer to a neural network object. |
new_data_set_pointer | Pointer to a data set object. |
Definition at line 33 of file loss_index.cpp.
|
virtual |
Destructor.
Definition at line 43 of file loss_index.cpp.
void back_propagate | ( | const DataSetBatch & | batch, |
NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagation & | back_propagation | ||
) | const |
Definition at line 419 of file loss_index.cpp.
void back_propagate_lm | ( | const DataSetBatch & | batch, |
NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagationLM & | loss_index_back_propagation_lm | ||
) | const |
This method calculates the second order loss. It is used for optimization of parameters during training. Returns a second order terms loss structure, which contains the values and the Hessian of the error terms function.
Definition at line 457 of file loss_index.cpp.
|
pure virtual |
Implemented in MeanSquaredError, NormalizedSquaredError, and MinkowskiError.
void calculate_error_gradient | ( | const DataSetBatch & | batch, |
const NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagation & | back_propagation | ||
) | const |
Definition at line 757 of file loss_index.cpp.
|
virtual |
Reimplemented in WeightedSquaredError.
Definition at line 598 of file loss_index.cpp.
|
inlinevirtual |
Definition at line 215 of file loss_index.h.
|
inlinevirtual |
Definition at line 196 of file loss_index.h.
void calculate_errors | ( | const DataSetBatch & | batch, |
const NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagation & | back_propagation | ||
) | const |
Definition at line 321 of file loss_index.cpp.
void calculate_errors_lm | ( | const DataSetBatch & | batch, |
const NeuralNetworkForwardPropagation & | neural_network_forward_propagation, | ||
LossIndexBackPropagationLM & | loss_index_back_propagation | ||
) | const |
Definition at line 366 of file loss_index.cpp.
type calculate_eta | ( | ) | const |
Definition at line 1143 of file loss_index.cpp.
Tensor< type, 1 > calculate_gradient_numerical_differentiation | ( | ) |
Definition at line 1016 of file loss_index.cpp.
type calculate_h | ( | const type & | x | ) | const |
Calculates a proper step size for computing the derivatives, as a function of the inputs point value.
x | Input value. |
Definition at line 1154 of file loss_index.cpp.
Tensor< type, 2 > calculate_jacobian_numerical_differentiation | ( | ) |
Definition at line 1076 of file loss_index.cpp.
void calculate_layers_delta | ( | const DataSetBatch & | batch, |
NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagation & | back_propagation | ||
) | const |
Definition at line 701 of file loss_index.cpp.
void calculate_layers_delta_lm | ( | const DataSetBatch & | batch, |
NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagationLM & | back_propagation | ||
) | const |
Definition at line 729 of file loss_index.cpp.
|
inlinevirtual |
Definition at line 200 of file loss_index.h.
type calculate_regularization | ( | const Tensor< type, 1 > & | parameters | ) | const |
It calculates the regularization term using through the use of parameters. Returns the regularization evaluation, according to the respective regularization type used in the loss index expression.
parameters | vector with the parameters to get the regularization term. |
Definition at line 648 of file loss_index.cpp.
void calculate_regularization_gradient | ( | const Tensor< type, 1 > & | parameters, |
Tensor< type, 1 > & | regularization_gradient | ||
) | const |
It calculate the regularization term using the gradient method. Returns the gradient of the regularization, according to the regularization type. That gradient is the vector of partial derivatives of the regularization with respect to the parameters. The size is thus the number of parameters
parameters | vector with the parameters to get the regularization term. |
Definition at line 669 of file loss_index.cpp.
void calculate_regularization_hessian | ( | const Tensor< type, 1 > & | parameters, |
Tensor< type, 2 > & | regularization_hessian | ||
) | const |
It calculate the regularization term using the Hessian. Returns the Hessian of the regularization, according to the regularization type. That Hessian is the matrix of second partial derivatives of the regularization with respect to the parameters. That matrix is symmetric, with size the number of parameters.
parameters | vector with the parameters to get the regularization term. |
Definition at line 688 of file loss_index.cpp.
void calculate_squared_errors_jacobian_lm | ( | const DataSetBatch & | batch, |
NeuralNetworkForwardPropagation & | forward_propagation, | ||
LossIndexBackPropagationLM & | loss_index_back_propagation_lm | ||
) | const |
Calculates the Jacobian matrix of the error terms from layers. Returns the Jacobian of the error terms function, according to the objective type used in the loss index expression. Note that this function is only defined when the objective can be expressed as a sum of squared terms. The Jacobian elements are the partial derivatives of a single term with respect to a single parameter. The number of rows in the Jacobian matrix are the number of parameters, and the number of columns the number of terms composing the objective.
inputs | Tensor with inputs. |
layers_activations | vector of tensors with layers activations. |
layers_delta | vector of tensors with layers delta. |
Definition at line 508 of file loss_index.cpp.
|
virtual |
Definition at line 411 of file loss_index.cpp.
void check | ( | ) | const |
Checks that there is a neural network associated to the error term. If some of the above conditions is not hold, the method throws an exception.
Definition at line 295 of file loss_index.cpp.
void from_XML | ( | const tinyxml2::XMLDocument & | document | ) |
Loads a default error term from a XML document.
document | TinyXML document containing the error term members. |
Definition at line 979 of file loss_index.cpp.
|
inline |
Returns a pointer to the data set object associated to the error term.
Definition at line 92 of file loss_index.h.
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 61 of file loss_index.cpp.
|
virtual |
Returns a string with the default type of error term, "USER_PERFORMANCE_TERM".
Reimplemented in CrossEntropyError, MeanSquaredError, MinkowskiError, NormalizedSquaredError, SumSquaredError, and WeightedSquaredError.
Definition at line 608 of file loss_index.cpp.
|
virtual |
Returns a string with the default type of error term in text format, "USER_PERFORMANCE_TERM".
Reimplemented in CrossEntropyError, MeanSquaredError, MinkowskiError, NormalizedSquaredError, SumSquaredError, and WeightedSquaredError.
Definition at line 616 of file loss_index.cpp.
|
inline |
Returns a pointer to the neural network object associated to the error term.
Definition at line 70 of file loss_index.h.
LossIndex::RegularizationMethod get_regularization_method | ( | ) | const |
Returns the regularization method.
Definition at line 101 of file loss_index.cpp.
const type & get_regularization_weight | ( | ) | const |
Returns regularization weight.
Definition at line 52 of file loss_index.cpp.
bool has_data_set | ( | ) | const |
Returns true if this error term object has a data set pointer associated, and false otherwise.
Definition at line 86 of file loss_index.cpp.
bool has_neural_network | ( | ) | const |
Returns true if this error term object has a neural nework class pointer associated, and false otherwise
Definition at line 70 of file loss_index.cpp.
bool has_selection | ( | ) | const |
Returns true if there are selection samples and false otherwise.
Definition at line 279 of file loss_index.cpp.
void regularization_from_XML | ( | const tinyxml2::XMLDocument & | document | ) |
Definition at line 891 of file loss_index.cpp.
void set | ( | ) |
Sets all the member pointers to nullptr(neural network, data set). It also initializes all the rest of class members to their default values.
Definition at line 110 of file loss_index.cpp.
void set | ( | const LossIndex & | other_error_term | ) |
Sets to this error term object the members of another error term object.
other_error_term | Error term to be copied. |
Definition at line 163 of file loss_index.cpp.
void set | ( | DataSet * | new_data_set_pointer | ) |
Sets all the member pointers to nullptr, but the data set, which set to a given pointer. It also initializes all the rest of class members to their default values.
new_data_set_pointer | Pointer to a data set object. |
Definition at line 136 of file loss_index.cpp.
void set | ( | NeuralNetwork * | new_neural_network_pointer | ) |
Sets all the member pointers to nullptr, but the neural network, which set to a given pointer. It also initializes all the rest of class members to their default values.
new_neural_network_pointer | Pointer to a neural network object. |
Definition at line 123 of file loss_index.cpp.
void set | ( | NeuralNetwork * | new_neural_network_pointer, |
DataSet * | new_data_set_pointer | ||
) |
Sets new neural network and data set pointers. Finally, it initializes all the rest of class members to their default values.
new_neural_network_pointer | Pointer to a neural network object. |
new_data_set_pointer | Pointer to a data set object. |
Definition at line 150 of file loss_index.cpp.
|
virtual |
Sets a new data set on which the error term is to be measured.
Reimplemented in WeightedSquaredError, and NormalizedSquaredError.
Definition at line 196 of file loss_index.cpp.
void set_default | ( | ) |
Sets the members of the error term to their default values:
Definition at line 204 of file loss_index.cpp.
void set_display | ( | const bool & | new_display | ) |
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. |
Definition at line 271 of file loss_index.cpp.
void set_neural_network_pointer | ( | NeuralNetwork * | new_neural_network_pointer | ) |
Sets a pointer to a neural network object which is to be associated to the error term.
new_neural_network_pointer | Pointer to a neural network object to be associated to the error term. |
Definition at line 188 of file loss_index.cpp.
|
inlinevirtual |
Reimplemented in NormalizedSquaredError, and WeightedSquaredError.
Definition at line 147 of file loss_index.h.
void set_regularization_method | ( | const RegularizationMethod & | new_regularization_method | ) |
Sets the object with the regularization method.
new_regularization_method | String with method. |
Definition at line 251 of file loss_index.cpp.
void set_regularization_method | ( | const string & | new_regularization_method | ) |
Sets the object with the regularization method.
new_regularization_method | String with method. |
Definition at line 221 of file loss_index.cpp.
void set_regularization_weight | ( | const type & | new_regularization_weight | ) |
Sets the object with the regularization weights.
new_regularization_method | New regularization weight. |
Definition at line 260 of file loss_index.cpp.
void set_threads_number | ( | const int & | new_threads_number | ) |
Definition at line 175 of file loss_index.cpp.
string write_regularization_method | ( | ) | const |
Returns a string with the regularization information of the error term. It will be used by the training strategy to monitor the training process.
Definition at line 625 of file loss_index.cpp.
void write_regularization_XML | ( | tinyxml2::XMLPrinter & | file_stream | ) | const |
Definition at line 928 of file loss_index.cpp.
|
virtual |
Serializes a default error term 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 CrossEntropyError, MeanSquaredError, MinkowskiError, NormalizedSquaredError, SumSquaredError, and WeightedSquaredError.
Definition at line 881 of file loss_index.cpp.
|
protected |
Definition at line 273 of file loss_index.h.
|
protected |
Definition at line 272 of file loss_index.h.
|
protected |
Pointer to a data set object.
Definition at line 258 of file loss_index.h.
|
protected |
Display messages to screen.
Definition at line 270 of file loss_index.h.
|
protected |
Pointer to a neural network object.
Definition at line 254 of file loss_index.h.
|
protected |
Definition at line 249 of file loss_index.h.
|
protected |
Pointer to a regularization method object.
Definition at line 262 of file loss_index.h.
|
protected |
Regularization weight value.
Definition at line 266 of file loss_index.h.
|
protected |
Definition at line 277 of file loss_index.h.
|
protected |
Definition at line 275 of file loss_index.h.
|
protected |
Definition at line 250 of file loss_index.h.