mlpack
Public Member Functions | List of all members
mlpack::ann::HingeLoss< InputDataType, OutputDataType > Class Template Reference

Computes the hinge loss between \(y_true\) and \(y_pred\). More...

#include <hinge_loss.hpp>

Public Member Functions

 HingeLoss (const bool reduction=true)
 Create HingeLoss object. More...
 
template<typename PredictionType , typename TargetType >
PredictionType::elem_type Forward (const PredictionType &prediction, const TargetType &target)
 Computes the Hinge loss function. More...
 
template<typename PredictionType , typename TargetType , typename LossType >
void Backward (const PredictionType &prediction, const TargetType &target, LossType &loss)
 Ordinary feed backward pass of a neural network. More...
 
OutputDataType & OutputParameter () const
 Get the output parameter.
 
OutputDataType & OutputParameter ()
 Modify the output parameter.
 
bool Reduction () const
 Get the type of reduction used.
 
bool & Reduction ()
 Modify the type of reduction used.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the layer.
 

Detailed Description

template<typename InputDataType = arma::mat, typename OutputDataType = arma::mat>
class mlpack::ann::HingeLoss< InputDataType, OutputDataType >

Computes the hinge loss between \(y_true\) and \(y_pred\).

Expects \(y_true\) to be either -1 or 1. If \(y_true\) is either 0 or 1, a temporary conversion is made to calculate the loss. The hinge loss \(l(y_true, y_pred)\) is defined as \(l(y_true, y_pred) = max(0, 1 - y_true*y_pred)\).

Template Parameters
InputDataTypeType of the input data (arma::colvec, arma::mat, arma::sp_mat or arma::cube).
OutputDataTypeType of the output data (arma::colvec, arma::mat, arma::sp_mat or arma::cube).

Constructor & Destructor Documentation

◆ HingeLoss()

template<typename InputDataType , typename OutputDataType >
mlpack::ann::HingeLoss< InputDataType, OutputDataType >::HingeLoss ( const bool  reduction = true)

Create HingeLoss object.

Parameters
reductionSpecifies the reduction to apply to the output. If false, 'mean' reduction is used, where sum of the output will be divided by the number of elements in the output. If true, 'sum' reduction is used and the output will be summed. It is set to true by default.

Member Function Documentation

◆ Backward()

template<typename InputDataType , typename OutputDataType >
template<typename PredictionType , typename TargetType , typename LossType >
void mlpack::ann::HingeLoss< InputDataType, OutputDataType >::Backward ( const PredictionType &  prediction,
const TargetType &  target,
LossType &  loss 
)

Ordinary feed backward pass of a neural network.

Parameters
predictionPrediction used for evaluating the specified loss function.
targetThe target vector.
lossThe calculated error.

◆ Forward()

template<typename InputDataType , typename OutputDataType >
template<typename PredictionType , typename TargetType >
PredictionType::elem_type mlpack::ann::HingeLoss< InputDataType, OutputDataType >::Forward ( const PredictionType &  prediction,
const TargetType &  target 
)

Computes the Hinge loss function.

Parameters
predictionPrediction used for evaluating the specified loss function.
targetTarget data to compare with.

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