mlpack 3.4.2
cosine_embedding_loss.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_COSINE_EMBEDDING_HPP
13#define MLPACK_METHODS_ANN_LOSS_FUNCTION_COSINE_EMBEDDING_HPP
14
15#include <mlpack/prereqs.hpp>
16
17namespace mlpack {
18namespace ann {
19
35template <
36 typename InputDataType = arma::mat,
37 typename OutputDataType = arma::mat
38>
40{
41 public:
53 CosineEmbeddingLoss(const double margin = 0.0,
54 const bool similarity = true,
55 const bool takeMean = false);
56
63 template <typename InputType, typename TargetType>
64 typename InputType::elem_type Forward(const InputType& input,
65 const TargetType& target);
66
74 template<typename InputType, typename TargetType, typename OutputType>
75 void Backward(const InputType& input,
76 const TargetType& target,
77 OutputType& output);
78
80 InputDataType& InputParameter() const { return inputParameter; }
82 InputDataType& InputParameter() { return inputParameter; }
83
85 OutputDataType& OutputParameter() const { return outputParameter; }
87 OutputDataType& OutputParameter() { return outputParameter; }
88
90 OutputDataType& Delta() const { return delta; }
92 OutputDataType& Delta() { return delta; }
93
95 bool TakeMean() const { return takeMean; }
97 bool& TakeMean() { return takeMean; }
98
100 double Margin() const { return margin; }
102 double& Margin() { return margin; }
103
105 bool Similarity() const { return similarity; }
107 bool& Similarity() { return similarity; }
108
112 template<typename Archive>
113 void serialize(Archive& ar, const unsigned int /* version */);
114
115 private:
117 OutputDataType delta;
118
120 InputDataType inputParameter;
121
123 OutputDataType outputParameter;
124
126 double margin;
127
129 bool similarity;
130
132 bool takeMean;
133}; // class CosineEmbeddingLoss
134
135} // namespace ann
136} // namespace mlpack
137
138// Include implementation.
139#include "cosine_embedding_loss_impl.hpp"
140
141#endif
Cosine Embedding Loss function is used for measuring whether two inputs are similar or dissimilar,...
InputDataType & InputParameter() const
Get the input parameter.
CosineEmbeddingLoss(const double margin=0.0, const bool similarity=true, const bool takeMean=false)
Create the CosineEmbeddingLoss object.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType & OutputParameter() const
Get the output parameter.
OutputDataType & Delta() const
Get the delta.
bool & Similarity()
Modify the value of takeMean.
void Backward(const InputType &input, const TargetType &target, OutputType &output)
Ordinary feed backward pass of a neural network.
bool Similarity() const
Get the value of similarity hyperparameter.
double & Margin()
Modify the value of takeMean.
InputType::elem_type Forward(const InputType &input, const TargetType &target)
Ordinary feed forward pass of a neural network.
bool TakeMean() const
Get the value of takeMean.
double Margin() const
Get the value of margin.
OutputDataType & OutputParameter()
Modify the output parameter.
bool & TakeMean()
Modify the value of takeMean.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Delta()
Modify the delta.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.