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... | |
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.
InputDataType | Type of the input data (arma::colvec, arma::mat, arma::sp_mat or arma::cube). |
OutputDataType | Type of the output data (arma::colvec, arma::mat, arma::sp_mat or arma::cube). |
Definition at line 39 of file cosine_embedding_loss.hpp.
CosineEmbeddingLoss | ( | const double | margin = 0.0 , |
const bool | similarity = true , |
||
const bool | takeMean = false |
||
) |
Create the CosineEmbeddingLoss object.
margin | Increases cosine distance in case of dissimilarity. Refer definition of cosine-embedding-loss above. |
similarity | Determines whether to use similarity or dissimilarity for comparision. |
takeMean | Boolean 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. |
void Backward | ( | const PredictionType & | prediction, |
const TargetType & | target, | ||
LossType & | loss | ||
) |
Ordinary feed backward pass of a neural network.
prediction | Predictions used for evaluating the specified loss function. |
target | The target vector. |
loss | The calculated error. |
|
inline |
Get the delta.
Definition at line 92 of file cosine_embedding_loss.hpp.
|
inline |
Modify the delta.
Definition at line 94 of file cosine_embedding_loss.hpp.
PredictionType::elem_type Forward | ( | const PredictionType & | prediction, |
const TargetType & | target | ||
) |
Ordinary feed forward pass of a neural network.
prediction | Predictions used for evaluating the specified loss function. |
target | The target vector. |
|
inline |
Get the input parameter.
Definition at line 82 of file cosine_embedding_loss.hpp.
|
inline |
Modify the input parameter.
Definition at line 84 of file cosine_embedding_loss.hpp.
|
inline |
Get the value of margin.
Definition at line 102 of file cosine_embedding_loss.hpp.
|
inline |
Modify the value of takeMean.
Definition at line 104 of file cosine_embedding_loss.hpp.
|
inline |
Get the output parameter.
Definition at line 87 of file cosine_embedding_loss.hpp.
|
inline |
Modify the output parameter.
Definition at line 89 of file cosine_embedding_loss.hpp.
void serialize | ( | Archive & | ar, |
const uint32_t | |||
) |
Serialize the layer.
Referenced by CosineEmbeddingLoss< InputDataType, OutputDataType >::Similarity().
|
inline |
Get the value of similarity hyperparameter.
Definition at line 107 of file cosine_embedding_loss.hpp.
|
inline |
Modify the value of takeMean.
Definition at line 109 of file cosine_embedding_loss.hpp.
References CosineEmbeddingLoss< InputDataType, OutputDataType >::serialize().
|
inline |
Get the value of takeMean.
Definition at line 97 of file cosine_embedding_loss.hpp.
|
inline |
Modify the value of takeMean.
Definition at line 99 of file cosine_embedding_loss.hpp.