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 
17 namespace mlpack {
18 namespace ann {
19 
35 template <
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 
64  template <typename PredictionType, typename TargetType>
65  typename PredictionType::elem_type Forward(const PredictionType& prediction,
66  const TargetType& target);
67 
76  template<typename PredictionType, typename TargetType, typename LossType>
77  void Backward(const PredictionType& prediction,
78  const TargetType& target,
79  LossType& loss);
80 
82  InputDataType& InputParameter() const { return inputParameter; }
84  InputDataType& InputParameter() { return inputParameter; }
85 
87  OutputDataType& OutputParameter() const { return outputParameter; }
89  OutputDataType& OutputParameter() { return outputParameter; }
90 
92  OutputDataType& Delta() const { return delta; }
94  OutputDataType& Delta() { return delta; }
95 
97  bool TakeMean() const { return takeMean; }
99  bool& TakeMean() { return takeMean; }
100 
102  double Margin() const { return margin; }
104  double& Margin() { return margin; }
105 
107  bool Similarity() const { return similarity; }
109  bool& Similarity() { return similarity; }
110 
114  template<typename Archive>
115  void serialize(Archive& ar, const uint32_t /* version */);
116 
117  private:
119  OutputDataType delta;
120 
122  InputDataType inputParameter;
123 
125  OutputDataType outputParameter;
126 
128  double margin;
129 
131  bool similarity;
132 
134  bool takeMean;
135 }; // class CosineEmbeddingLoss
136 
137 } // namespace ann
138 } // namespace mlpack
139 
140 // Include implementation.
141 #include "cosine_embedding_loss_impl.hpp"
142 
143 #endif
bool & Similarity()
Modify the value of takeMean.
Linear algebra utility functions, generally performed on matrices or vectors.
OutputDataType & OutputParameter()
Modify the output parameter.
OutputDataType & OutputParameter() const
Get the output parameter.
CosineEmbeddingLoss(const double margin=0.0, const bool similarity=true, const bool takeMean=false)
Create the CosineEmbeddingLoss object.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
InputDataType & InputParameter() const
Get the input parameter.
The core includes that mlpack expects; standard C++ includes and Armadillo.
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Ordinary feed forward pass of a neural network.
OutputDataType & Delta()
Modify the delta.
bool & TakeMean()
Modify the value of takeMean.
double Margin() const
Get the value of margin.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType & Delta() const
Get the delta.
double & Margin()
Modify the value of takeMean.
bool TakeMean() const
Get the value of takeMean.
bool Similarity() const
Get the value of similarity hyperparameter.
Cosine Embedding Loss function is used for measuring whether two inputs are similar or dissimilar...
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.