mlpack
log_cosh_loss_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_LOG_COSH_LOSS_IMPL_HPP
14 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_LOG_COSH_LOSS_IMPL_HPP
15 
16 // In case it hasn't yet been included.
17 #include "log_cosh_loss.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
22 template<typename InputDataType, typename OutputDataType>
24  a(a)
25 {
26  Log::Assert(a > 0, "Hyper-Parameter \'a\' must be positive");
27 }
28 
29 template<typename InputDataType, typename OutputDataType>
30 template<typename PredictionType, typename TargetType>
31 typename PredictionType::elem_type
33  const PredictionType& prediction,
34  const TargetType& target)
35 {
36  return arma::accu(arma::log(arma::cosh(a * (target - prediction)))) / a;
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  loss = arma::tanh(a * (target - prediction));
47 }
48 
49 template<typename InputDataType, typename OutputDataType>
50 template<typename Archive>
52  Archive& ar,
53  const uint32_t /* version */)
54 {
55  ar(CEREAL_NVP(a));
56 }
57 
58 } // namespace ann
59 } // namespace mlpack
60 
61 #endif
void serialize(Archive &ar, const uint32_t)
Serialize the loss function.
Definition: log_cosh_loss_impl.hpp:51
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Log-Hyperbolic-Cosine loss function.
Definition: log_cosh_loss_impl.hpp:32
LogCoshLoss(const double a=1.0)
Create the Log-Hyperbolic-Cosine object with the specified parameters.
Definition: log_cosh_loss_impl.hpp:23
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: log_cosh_loss_impl.hpp:41
static void Assert(bool condition, const std::string &message="Assert Failed.")
Checks if the specified condition is true.
Definition: log.cpp:38