mlpack
mean_squared_logarithmic_error_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_MEAN_SQUARED_LOGARITHMIC_ERROR_IMPL_HPP
13 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_MEAN_SQUARED_LOGARITHMIC_ERROR_IMPL_HPP
14 
15 // In case it hasn't yet been included.
17 
18 namespace mlpack {
19 namespace ann {
20 
21 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  return arma::accu(arma::square(arma::log(1. + target) -
36  arma::log(1. + prediction))) / target.n_cols;
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 = 2 * (arma::log(1. + prediction) - arma::log(1. + target)) /
47  ((1. + prediction) * target.n_cols);
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
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the mean squared logarithmic error function.
Definition: mean_squared_logarithmic_error_impl.hpp:31
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: mean_squared_logarithmic_error_impl.hpp:52
MeanSquaredLogarithmicError()
Create the MeanSquaredLogarithmicError object.
Definition: mean_squared_logarithmic_error_impl.hpp:23
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: mean_squared_logarithmic_error_impl.hpp:41