poisson_nll_loss.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTIONS_POISSON_NLL_LOSS_HPP
14 #define MLPACK_METHODS_ANN_LOSS_FUNCTIONS_POISSON_NLL_LOSS_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace ann {
20 
32 template <
33  typename InputDataType = arma::mat,
34  typename OutputDataType = arma::mat
35 >
37 {
38  public:
50  PoissonNLLLoss(const bool logInput = true,
51  const bool full = false,
52  const typename InputDataType::elem_type eps = 1e-08,
53  const bool mean = true);
54 
63  template<typename PredictionType, typename TargetType>
64  typename InputDataType::elem_type Forward(const PredictionType& prediction,
65  const TargetType& target);
66 
79  template<typename PredictionType, typename TargetType, typename LossType>
80  void Backward(const PredictionType& prediction,
81  const TargetType& target,
82  LossType& loss);
83 
85  InputDataType& InputParameter() const { return inputParameter; }
87  InputDataType& InputParameter() { return inputParameter; }
88 
90  OutputDataType& OutputParameter() const { return outputParameter; }
92  OutputDataType& OutputParameter() { return outputParameter; }
93 
96  bool LogInput() const { return logInput; }
99  bool& LogInput() { return logInput; }
100 
103  bool Full() const { return full; }
106  bool& Full() { return full; }
107 
110  typename InputDataType::elem_type Eps() const { return eps; }
113  typename InputDataType::elem_type& Eps() { return eps; }
114 
117  bool Mean() const { return mean; }
120  bool& Mean() { return mean; }
121 
125  template<typename Archive>
126  void serialize(Archive& ar, const uint32_t /* version */);
127 
128  private:
130  template<typename eT>
131  void CheckProbs(const arma::Mat<eT>& probs)
132  {
133  for (size_t i = 0; i < probs.size(); ++i)
134  {
135  if (probs[i] > 1.0 || probs[i] < 0.0)
136  Log::Fatal << "Probabilities cannot be greater than 1 "
137  << "or smaller than 0." << std::endl;
138  }
139  }
140 
142  InputDataType inputParameter;
143 
145  OutputDataType outputParameter;
146 
148  bool logInput;
149 
151  // approximation term.
152  bool full;
153 
155  typename InputDataType::elem_type eps;
156 
158  bool mean;
159 }; // class PoissonNLLLoss
160 
161 } // namespace ann
162 } // namespace mlpack
163 
164 // Include implementation.
165 #include "poisson_nll_loss_impl.hpp"
166 
167 #endif
OutputDataType & OutputParameter()
Modify the output parameter.
bool & Full()
Modify the value of full.
Implementation of the Poisson negative log likelihood loss.
InputDataType::elem_type Eps() const
Get the value of eps.
Linear algebra utility functions, generally performed on matrices or vectors.
bool & Mean()
Modify the value of mean.
InputDataType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Poisson negative log likelihood Loss.
InputDataType & InputParameter() const
Get the input parameter.
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool Full() const
Get the value of full.
OutputDataType & OutputParameter() const
Get the output parameter.
bool Mean() const
Get the value of mean.
bool LogInput() const
Get the value of logInput.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
InputDataType::elem_type & Eps()
Modify the value of eps.
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
PoissonNLLLoss(const bool logInput=true, const bool full=false, const typename InputDataType::elem_type eps=1e-08, const bool mean=true)
Create the PoissonNLLLoss object.
bool & LogInput()
Modify the value of logInput.
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
InputDataType & InputParameter()
Modify the input parameter.