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 
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 
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
mlpack::ann::CosineEmbeddingLoss::Forward
InputType::elem_type Forward(const InputType &input, const TargetType &target)
Ordinary feed forward pass of a neural network.
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
mlpack::ann::CosineEmbeddingLoss::InputParameter
InputDataType & InputParameter()
Modify the input parameter.
Definition: cosine_embedding_loss.hpp:82
mlpack::ann::CosineEmbeddingLoss::OutputParameter
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: cosine_embedding_loss.hpp:87
mlpack::ann::CosineEmbeddingLoss::Margin
double & Margin()
Modify the value of takeMean.
Definition: cosine_embedding_loss.hpp:102
mlpack::ann::CosineEmbeddingLoss::Backward
void Backward(const InputType &input, const TargetType &target, OutputType &output)
Ordinary feed backward pass of a neural network.
mlpack::ann::CosineEmbeddingLoss::OutputParameter
OutputDataType & OutputParameter() const
Get the output parameter.
Definition: cosine_embedding_loss.hpp:85
mlpack::ann::CosineEmbeddingLoss::Delta
OutputDataType & Delta() const
Get the delta.
Definition: cosine_embedding_loss.hpp:90
mlpack::ann::CosineEmbeddingLoss::CosineEmbeddingLoss
CosineEmbeddingLoss(const double margin=0.0, const bool similarity=true, const bool takeMean=false)
Create the CosineEmbeddingLoss object.
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::ann::CosineEmbeddingLoss::InputParameter
InputDataType & InputParameter() const
Get the input parameter.
Definition: cosine_embedding_loss.hpp:80
mlpack::ann::CosineEmbeddingLoss::Similarity
bool Similarity() const
Get the value of similarity hyperparameter.
Definition: cosine_embedding_loss.hpp:105
mlpack::ann::CosineEmbeddingLoss::serialize
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
mlpack::ann::CosineEmbeddingLoss::Delta
OutputDataType & Delta()
Modify the delta.
Definition: cosine_embedding_loss.hpp:92
mlpack::ann::CosineEmbeddingLoss::TakeMean
bool & TakeMean()
Modify the value of takeMean.
Definition: cosine_embedding_loss.hpp:97
mlpack::ann::CosineEmbeddingLoss::Similarity
bool & Similarity()
Modify the value of takeMean.
Definition: cosine_embedding_loss.hpp:107
mlpack::ann::CosineEmbeddingLoss
Cosine Embedding Loss function is used for measuring whether two inputs are similar or dissimilar,...
Definition: cosine_embedding_loss.hpp:40
mlpack::ann::CosineEmbeddingLoss::TakeMean
bool TakeMean() const
Get the value of takeMean.
Definition: cosine_embedding_loss.hpp:95
mlpack::ann::CosineEmbeddingLoss::Margin
double Margin() const
Get the value of margin.
Definition: cosine_embedding_loss.hpp:100