WeightedSquaredError Class Reference

This class represents the weighted squared error term. More...

#include <weighted_squared_error.h>

Inheritance diagram for WeightedSquaredError:
LossIndex

Public Member Functions

 WeightedSquaredError ()
 
 WeightedSquaredError (NeuralNetwork *, DataSet *)
 
virtual ~WeightedSquaredError ()
 Destructor. More...
 
type get_positives_weight () const
 Returns the weight of the positives. More...
 
type get_negatives_weight () const
 Returns the weight of the negatives. More...
 
type get_normalizaton_coefficient () const
 
void set_default ()
 Set the default values for the object. More...
 
void set_positives_weight (const type &)
 
void set_negatives_weight (const type &)
 
void set_weights (const type &, const type &)
 
void set_weights ()
 Calculates of the weights for the positives and negatives values with the data of the data set. More...
 
void set_normalization_coefficient ()
 Calculates of the normalization coefficient with the data of the data set. More...
 
void set_data_set_pointer (DataSet *)
 set_data_set_pointer More...
 
type weighted_sum_squared_error (const Tensor< type, 2 > &x, const Tensor< type, 2 > &y) const
 
string get_error_type () const
 Returns a string with the name of the weighted squared error loss type, "WEIGHTED_SQUARED_ERROR". More...
 
string get_error_type_text () const
 Returns a string with the name of the weighted squared error loss type in text format. More...
 
void calculate_error (const DataSetBatch &, const NeuralNetworkForwardPropagation &, LossIndexBackPropagation &) const
 
void calculate_output_delta (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagation &) const
 
void calculate_squared_errors_lm (const DataSetBatch &, const NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
void calculate_error_lm (const DataSetBatch &, const NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
void calculate_error_gradient_lm (const DataSetBatch &, LossIndexBackPropagationLM &) const
 
void calculate_error_hessian_lm (const DataSetBatch &, LossIndexBackPropagationLM &) const
 
void from_XML (const tinyxml2::XMLDocument &)
 
void write_XML (tinyxml2::XMLPrinter &) const
 
- Public Member Functions inherited from LossIndex
 LossIndex ()
 
 LossIndex (NeuralNetwork *, DataSet *)
 
virtual ~LossIndex ()
 Destructor. More...
 
NeuralNetworkget_neural_network_pointer () const
 Returns a pointer to the neural network object associated to the error term. More...
 
DataSetget_data_set_pointer () const
 Returns a pointer to the data set object associated to the error term. More...
 
const type & get_regularization_weight () const
 Returns regularization weight. More...
 
const bool & get_display () const
 
bool has_neural_network () const
 
bool has_data_set () const
 
RegularizationMethod get_regularization_method () const
 Returns the regularization method. More...
 
void set ()
 
void set (NeuralNetwork *)
 
void set (DataSet *)
 
void set (NeuralNetwork *, DataSet *)
 
void set (const LossIndex &)
 
void set_threads_number (const int &)
 
void set_neural_network_pointer (NeuralNetwork *)
 
void set_default ()
 Sets the members of the error term to their default values: More...
 
void set_regularization_method (const RegularizationMethod &)
 
void set_regularization_method (const string &)
 
void set_regularization_weight (const type &)
 
void set_display (const bool &)
 
bool has_selection () const
 Returns true if there are selection samples and false otherwise. More...
 
type calculate_eta () const
 
type calculate_h (const type &) const
 
Tensor< type, 1 > calculate_gradient_numerical_differentiation ()
 
Tensor< type, 2 > calculate_jacobian_numerical_differentiation ()
 
void calculate_errors (const DataSetBatch &, const NeuralNetworkForwardPropagation &, LossIndexBackPropagation &) const
 
void calculate_layers_delta (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagation &) const
 
void calculate_error_gradient (const DataSetBatch &, const NeuralNetworkForwardPropagation &, LossIndexBackPropagation &) const
 
void back_propagate (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagation &) const
 
void calculate_errors_lm (const DataSetBatch &, const NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
virtual void calculate_output_delta_lm (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
void calculate_layers_delta_lm (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
void calculate_squared_errors_jacobian_lm (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
void back_propagate_lm (const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &) const
 
type calculate_regularization (const Tensor< type, 1 > &) const
 
void calculate_regularization_gradient (const Tensor< type, 1 > &, Tensor< type, 1 > &) const
 
void calculate_regularization_hessian (const Tensor< type, 1 > &, Tensor< type, 2 > &) const
 
void from_XML (const tinyxml2::XMLDocument &)
 
void regularization_from_XML (const tinyxml2::XMLDocument &)
 
void write_regularization_XML (tinyxml2::XMLPrinter &) const
 
string write_regularization_method () const
 
void check () const
 

Private Attributes

type positives_weight = type(NAN)
 Weight for the positives for the calculation of the error. More...
 
type negatives_weight = type(NAN)
 Weight for the negatives for the calculation of the error. More...
 
type normalization_coefficient
 Coefficient of normalization. More...
 

Additional Inherited Members

- Public Types inherited from LossIndex
enum class  RegularizationMethod { L1 , L2 , NoRegularization }
 Enumeration of available regularization methods. More...
 
- Protected Attributes inherited from LossIndex
ThreadPool * thread_pool = nullptr
 
ThreadPoolDevice * thread_pool_device = nullptr
 
NeuralNetworkneural_network_pointer = nullptr
 Pointer to a neural network object. More...
 
DataSetdata_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})}
 

Detailed Description

This class represents the weighted squared error term.

The weighted squared error measures the difference between the outputs from a neural network and the targets in a data set. This functional is used in data modeling problems, such as function regression, classification and time series prediction.

Definition at line 37 of file weighted_squared_error.h.

Constructor & Destructor Documentation

◆ WeightedSquaredError() [1/2]

WeightedSquaredError ( )
explicit

Default constructor. It creates a weighted squared error term not associated to any neural network and not measured on any data set. It also initializes all the rest of class members to their default values.

Definition at line 19 of file weighted_squared_error.cpp.

◆ WeightedSquaredError() [2/2]

WeightedSquaredError ( NeuralNetwork new_neural_network_pointer,
DataSet new_data_set_pointer 
)
explicit

Neural network and data set constructor. It creates a weighted squared error term object associated to a neural network and measured on a data set. It also initializes all the rest of class members to their default values.

Parameters
new_neural_network_pointerPointer to a neural network object.
new_data_set_pointerPointer to a data set object.

Definition at line 32 of file weighted_squared_error.cpp.

◆ ~WeightedSquaredError()

~WeightedSquaredError ( )
virtual

Destructor.

Definition at line 41 of file weighted_squared_error.cpp.

Member Function Documentation

◆ calculate_error()

void calculate_error ( const DataSetBatch batch,
const NeuralNetworkForwardPropagation forward_propagation,
LossIndexBackPropagation back_propagation 
) const
virtual

Implements LossIndex.

Definition at line 205 of file weighted_squared_error.cpp.

◆ calculate_error_gradient_lm()

void calculate_error_gradient_lm ( const DataSetBatch batch,
LossIndexBackPropagationLM loss_index_back_propagation_lm 
) const
virtual

Reimplemented from LossIndex.

Definition at line 298 of file weighted_squared_error.cpp.

◆ calculate_error_hessian_lm()

void calculate_error_hessian_lm ( const DataSetBatch batch,
LossIndexBackPropagationLM loss_index_back_propagation_lm 
) const
virtual

Reimplemented from LossIndex.

Definition at line 319 of file weighted_squared_error.cpp.

◆ calculate_error_lm()

void calculate_error_lm ( const DataSetBatch batch,
const NeuralNetworkForwardPropagation ,
LossIndexBackPropagationLM back_propagation 
) const
virtual

Reimplemented from LossIndex.

Definition at line 242 of file weighted_squared_error.cpp.

◆ calculate_output_delta()

void calculate_output_delta ( const DataSetBatch batch,
NeuralNetworkForwardPropagation ,
LossIndexBackPropagation back_propagation 
) const
virtual

Implements LossIndex.

Definition at line 258 of file weighted_squared_error.cpp.

◆ calculate_squared_errors_lm()

void calculate_squared_errors_lm ( const DataSetBatch batch,
const NeuralNetworkForwardPropagation forward_propagation,
LossIndexBackPropagationLM loss_index_back_propagation_lm 
) const
virtual

Reimplemented from LossIndex.

Definition at line 508 of file weighted_squared_error.cpp.

◆ from_XML()

void from_XML ( const tinyxml2::XMLDocument document)

Loads a weighted squared error object from a XML document.

Parameters
documentPointer to a TinyXML document with the object data.

Definition at line 399 of file weighted_squared_error.cpp.

◆ get_error_type()

string get_error_type ( ) const
virtual

Returns a string with the name of the weighted squared error loss type, "WEIGHTED_SQUARED_ERROR".

Reimplemented from LossIndex.

Definition at line 342 of file weighted_squared_error.cpp.

◆ get_error_type_text()

string get_error_type_text ( ) const
virtual

Returns a string with the name of the weighted squared error loss type in text format.

Reimplemented from LossIndex.

Definition at line 350 of file weighted_squared_error.cpp.

◆ get_negatives_weight()

type get_negatives_weight ( ) const

Returns the weight of the negatives.

Definition at line 56 of file weighted_squared_error.cpp.

◆ get_normalizaton_coefficient()

type get_normalizaton_coefficient ( ) const

Definition at line 62 of file weighted_squared_error.cpp.

◆ get_positives_weight()

type get_positives_weight ( ) const

Returns the weight of the positives.

Definition at line 48 of file weighted_squared_error.cpp.

◆ set_data_set_pointer()

void set_data_set_pointer ( DataSet new_data_set_pointer)
virtual

set_data_set_pointer

Parameters
new_data_set_pointer

Reimplemented from LossIndex.

Definition at line 195 of file weighted_squared_error.cpp.

◆ set_default()

void set_default ( )

Set the default values for the object.

Definition at line 70 of file weighted_squared_error.cpp.

◆ set_negatives_weight()

void set_negatives_weight ( const type &  new_negatives_weight)

Set a new weight for the negatives values.

Parameters
new_negatives_weightNew weight for the negatives.

Definition at line 100 of file weighted_squared_error.cpp.

◆ set_normalization_coefficient()

void set_normalization_coefficient ( )
virtual

Calculates of the normalization coefficient with the data of the data set.

Reimplemented from LossIndex.

Definition at line 162 of file weighted_squared_error.cpp.

◆ set_positives_weight()

void set_positives_weight ( const type &  new_positives_weight)

Set a new weight for the positives values.

Parameters
new_positives_weightNew weight for the positives.

Definition at line 91 of file weighted_squared_error.cpp.

◆ set_weights() [1/2]

void set_weights ( )

Calculates of the weights for the positives and negatives values with the data of the data set.

Definition at line 119 of file weighted_squared_error.cpp.

◆ set_weights() [2/2]

void set_weights ( const type &  new_positives_weight,
const type &  new_negatives_weight 
)

Set new weights for the positives and negatives values.

Parameters
new_positives_weightNew weight for the positives.
new_negatives_weightNew weight for the negatives.

Definition at line 110 of file weighted_squared_error.cpp.

◆ weighted_sum_squared_error()

type weighted_sum_squared_error ( const Tensor< type, 2 > &  x,
const Tensor< type, 2 > &  y 
) const

Definition at line 452 of file weighted_squared_error.cpp.

◆ write_XML()

void write_XML ( tinyxml2::XMLPrinter file_stream) const
virtual

Serializes the cross entropy error 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.

Parameters
file_stream

Reimplemented from LossIndex.

Definition at line 360 of file weighted_squared_error.cpp.

Member Data Documentation

◆ negatives_weight

type negatives_weight = type(NAN)
private

Weight for the negatives for the calculation of the error.

Definition at line 120 of file weighted_squared_error.h.

◆ normalization_coefficient

type normalization_coefficient
private

Coefficient of normalization.

Definition at line 124 of file weighted_squared_error.h.

◆ positives_weight

type positives_weight = type(NAN)
private

Weight for the positives for the calculation of the error.

Definition at line 116 of file weighted_squared_error.h.


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