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

Cosine Embedding Loss function is used for measuring whether two inputs are similar or dissimilar, using the cosine distance, and is typically used for learning nonlinear embeddings or semi-supervised learning. More...

#include <cosine_embedding_loss.hpp>

Public Member Functions

 CosineEmbeddingLoss (const double margin=0.0, const bool similarity=true, const bool takeMean=false)
 Create the CosineEmbeddingLoss object. More...
 
template<typename PredictionType , typename TargetType >
PredictionType::elem_type Forward (const PredictionType &prediction, const TargetType &target)
 Ordinary feed forward pass of a neural network. 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...
 
InputDataType & InputParameter () const
 Get the input parameter.
 
InputDataType & InputParameter ()
 Modify the input parameter.
 
OutputDataType & OutputParameter () const
 Get the output parameter.
 
OutputDataType & OutputParameter ()
 Modify the output parameter.
 
OutputDataType & Delta () const
 Get the delta.
 
OutputDataType & Delta ()
 Modify the delta.
 
bool TakeMean () const
 Get the value of takeMean.
 
bool & TakeMean ()
 Modify the value of takeMean.
 
double Margin () const
 Get the value of margin.
 
double & Margin ()
 Modify the value of takeMean.
 
bool Similarity () const
 Get the value of similarity hyperparameter.
 
bool & Similarity ()
 Modify the value of takeMean.
 
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::CosineEmbeddingLoss< InputDataType, OutputDataType >

Cosine Embedding Loss function is used for measuring whether two inputs are similar or dissimilar, using the cosine distance, and is typically used for learning nonlinear embeddings or semi-supervised learning.

\begin{eqnarray*} f(x) = 1 - cos(x1, x2) , for y = 1 f(x) = max(0, cos(x1, x2) - margin) , for y = -1 \end{eqnarray*}

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

◆ CosineEmbeddingLoss()

template<typename InputDataType , typename OutputDataType >
mlpack::ann::CosineEmbeddingLoss< InputDataType, OutputDataType >::CosineEmbeddingLoss ( const double  margin = 0.0,
const bool  similarity = true,
const bool  takeMean = false 
)

Create the CosineEmbeddingLoss object.

Parameters
marginIncreases cosine distance in case of dissimilarity. Refer definition of cosine-embedding-loss above.
similarityDetermines whether to use similarity or dissimilarity for comparision.
takeMeanBoolean variable to specify whether to take mean or not. Specifies reduction method i.e. sum or mean corresponding to 0 and 1 respectively. Default value = 0.

Member Function Documentation

◆ Backward()

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

Ordinary feed backward pass of a neural network.

Parameters
predictionPredictions 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::CosineEmbeddingLoss< InputDataType, OutputDataType >::Forward ( const PredictionType &  prediction,
const TargetType &  target 
)

Ordinary feed forward pass of a neural network.

Parameters
predictionPredictions used for evaluating the specified loss function.
targetThe target vector.

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