mlpack
l1_loss_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_L1_LOSS_IMPL_HPP
13 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_L1_LOSS_IMPL_HPP
14 
15 // In case it hasn't yet been included.
16 #include "l1_loss.hpp"
17 
18 namespace mlpack {
19 namespace ann {
20 
21 template<typename InputDataType, typename OutputDataType>
23  mean(mean)
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  if (mean)
36  return arma::accu(arma::mean(prediction - target));
37 
38  return arma::accu(prediction - target);
39 }
40 
41 template<typename InputDataType, typename OutputDataType>
42 template<typename PredictionType, typename TargetType, typename LossType>
44  const PredictionType& prediction,
45  const TargetType& target,
46  LossType& loss)
47 {
48  loss = arma::sign(prediction - target);
49 }
50 
51 template<typename InputDataType, typename OutputDataType>
52 template<typename Archive>
54  Archive& ar,
55  const uint32_t /* version */)
56 {
57  ar(CEREAL_NVP(mean));
58 }
59 
60 } // namespace ann
61 } // namespace mlpack
62 
63 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: l1_loss_impl.hpp:53
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: l1_loss_impl.hpp:43
L1Loss(const bool mean=true)
Create the L1Loss object.
Definition: l1_loss_impl.hpp:22
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the L1 Loss function.
Definition: l1_loss_impl.hpp:31