kl_divergence.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_KL_DIVERGENCE_HPP
14 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_KL_DIVERGENCE_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace ann {
20 
41 template <
42  typename InputDataType = arma::mat,
43  typename OutputDataType = arma::mat
44 >
46 {
47  public:
54  KLDivergence(const bool takeMean = false);
55 
63  template<typename PredictionType, typename TargetType>
64  typename PredictionType::elem_type Forward(const PredictionType& prediction,
65  const TargetType& target);
66 
75  template<typename PredictionType, typename TargetType, typename LossType>
76  void Backward(const PredictionType& prediction,
77  const TargetType& target,
78  LossType& loss);
79 
81  OutputDataType& OutputParameter() const { return outputParameter; }
83  OutputDataType& OutputParameter() { return outputParameter; }
84 
86  bool TakeMean() const { return takeMean; }
88  bool& TakeMean() { return takeMean; }
89 
93  template<typename Archive>
94  void serialize(Archive& ar, const uint32_t /* version */);
95 
96  private:
98  OutputDataType outputParameter;
99 
101  bool takeMean;
102 }; // class KLDivergence
103 
104 } // namespace ann
105 } // namespace mlpack
106 
107 // include implementation
108 #include "kl_divergence_impl.hpp"
109 
110 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool TakeMean() const
Get the value of takeMean.
OutputDataType & OutputParameter()
Modify the output parameter.
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
bool & TakeMean()
Modify the value of takeMean.
KLDivergence(const bool takeMean=false)
Create the Kullback–Leibler Divergence object with the specified parameters.
void serialize(Archive &ar, const uint32_t)
Serialize the loss function.
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Kullback–Leibler divergence error function.
The Kullback–Leibler divergence is often used for continuous distributions (direct regression)...
OutputDataType & OutputParameter() const
Get the output parameter.