HingeLoss< InputDataType, OutputDataType > Class Template Reference

Computes the hinge loss between $y_true$ and $y_pred$. More...

Public Member Functions

 HingeLoss (const bool reduction=true)
 Create HingeLoss object. 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...

 
template
<
typename
PredictionType
,
typename
TargetType
>
PredictionType::elem_type Forward (const PredictionType &prediction, const TargetType &target)
 Computes the Hinge loss function. More...

 
OutputDataType & OutputParameter () const
 Get the output parameter. More...

 
OutputDataType & OutputParameter ()
 Modify the output parameter. More...

 
bool Reduction () const
 Get the type of reduction used. More...

 
bool & Reduction ()
 Modify the type of reduction used. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the layer. More...

 

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).

Definition at line 37 of file hinge_loss.hpp.

Constructor & Destructor Documentation

◆ HingeLoss()

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()

void 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()

PredictionType::elem_type 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.

◆ OutputParameter() [1/2]

OutputDataType& OutputParameter ( ) const
inline

Get the output parameter.

Definition at line 76 of file hinge_loss.hpp.

◆ OutputParameter() [2/2]

OutputDataType& OutputParameter ( )
inline

Modify the output parameter.

Definition at line 78 of file hinge_loss.hpp.

◆ Reduction() [1/2]

bool Reduction ( ) const
inline

Get the type of reduction used.

Definition at line 81 of file hinge_loss.hpp.

◆ Reduction() [2/2]

bool& Reduction ( )
inline

Modify the type of reduction used.

Definition at line 83 of file hinge_loss.hpp.

References HingeLoss< InputDataType, OutputDataType >::serialize().

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

Serialize the layer.

Referenced by HingeLoss< InputDataType, OutputDataType >::Reduction().


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/methods/ann/loss_functions/hinge_loss.hpp