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

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
,
typename
LossType
>
void Backward (const PredictionType &prediction, const TargetType &target, LossType &loss)
 Ordinary feed backward pass of a neural network. More...

 
OutputDataType & Delta () const
 Get the delta. More...

 
OutputDataType & Delta ()
 Modify the delta. 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...

 
InputDataType & InputParameter () const
 Get the input parameter. More...

 
InputDataType & InputParameter ()
 Modify the input parameter. More...

 
double Margin () const
 Get the value of margin. More...

 
double & Margin ()
 Modify the value of takeMean. More...

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

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

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

 
bool Similarity () const
 Get the value of similarity hyperparameter. More...

 
bool & Similarity ()
 Modify the value of takeMean. More...

 
bool TakeMean () const
 Get the value of takeMean. More...

 
bool & TakeMean ()
 Modify the value of takeMean. More...

 

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

Definition at line 39 of file cosine_embedding_loss.hpp.

Constructor & Destructor Documentation

◆ CosineEmbeddingLoss()

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

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

◆ Delta() [1/2]

OutputDataType& Delta ( ) const
inline

Get the delta.

Definition at line 92 of file cosine_embedding_loss.hpp.

◆ Delta() [2/2]

OutputDataType& Delta ( )
inline

Modify the delta.

Definition at line 94 of file cosine_embedding_loss.hpp.

◆ Forward()

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

◆ InputParameter() [1/2]

InputDataType& InputParameter ( ) const
inline

Get the input parameter.

Definition at line 82 of file cosine_embedding_loss.hpp.

◆ InputParameter() [2/2]

InputDataType& InputParameter ( )
inline

Modify the input parameter.

Definition at line 84 of file cosine_embedding_loss.hpp.

◆ Margin() [1/2]

double Margin ( ) const
inline

Get the value of margin.

Definition at line 102 of file cosine_embedding_loss.hpp.

◆ Margin() [2/2]

double& Margin ( )
inline

Modify the value of takeMean.

Definition at line 104 of file cosine_embedding_loss.hpp.

◆ OutputParameter() [1/2]

OutputDataType& OutputParameter ( ) const
inline

Get the output parameter.

Definition at line 87 of file cosine_embedding_loss.hpp.

◆ OutputParameter() [2/2]

OutputDataType& OutputParameter ( )
inline

Modify the output parameter.

Definition at line 89 of file cosine_embedding_loss.hpp.

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

◆ Similarity() [1/2]

bool Similarity ( ) const
inline

Get the value of similarity hyperparameter.

Definition at line 107 of file cosine_embedding_loss.hpp.

◆ Similarity() [2/2]

bool& Similarity ( )
inline

Modify the value of takeMean.

Definition at line 109 of file cosine_embedding_loss.hpp.

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

◆ TakeMean() [1/2]

bool TakeMean ( ) const
inline

Get the value of takeMean.

Definition at line 97 of file cosine_embedding_loss.hpp.

◆ TakeMean() [2/2]

bool& TakeMean ( )
inline

Modify the value of takeMean.

Definition at line 99 of file cosine_embedding_loss.hpp.


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