mlpack
hinge_embedding_loss_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_HINGE_EMBEDDING_LOSS_IMPL_HPP
14 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_HINGE_EMBEDDING_LOSS_IMPL_HPP
15 
16 // In case it hasn't yet been included.
17 #include "hinge_embedding_loss.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
22 template<typename InputDataType, typename OutputDataType>
24 {
25  // Nothing to do here.
26 }
27 
28 template<typename InputDataType, typename OutputDataType>
29 template<typename PredictionType, typename TargetType>
30 typename PredictionType::elem_type
32  const PredictionType& prediction,
33  const TargetType& target)
34 {
35  TargetType temp = target - (target == 0);
36  return (arma::accu(arma::max(1 - prediction % temp, 0.))) / target.n_elem;
37 }
38 
39 template<typename InputDataType, typename OutputDataType>
40 template<typename PredictionType, typename TargetType, typename LossType>
42  const PredictionType& prediction,
43  const TargetType& target,
44  LossType& loss)
45 {
46  TargetType temp = target - (target == 0);
47  loss = (prediction < 1 / temp) % -temp;
48 }
49 
50 template<typename InputDataType, typename OutputDataType>
51 template<typename Archive>
53  Archive& /* ar */,
54  const uint32_t /* version */)
55 {
56  // Nothing to do here.
57 }
58 
59 } // namespace ann
60 } // namespace mlpack
61 
62 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
HingeEmbeddingLoss()
Create the Hinge Embedding object.
Definition: hinge_embedding_loss_impl.hpp:23
void serialize(Archive &ar, const uint32_t)
Serialize the loss function.
Definition: hinge_embedding_loss_impl.hpp:52
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Hinge Embedding loss function.
Definition: hinge_embedding_loss_impl.hpp:31
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: hinge_embedding_loss_impl.hpp:41