12 #ifndef MLPACK_METHODS_ANN_LAYER_NEGATIVE_LOG_LIKELIHOOD_IMPL_HPP 13 #define MLPACK_METHODS_ANN_LAYER_NEGATIVE_LOG_LIKELIHOOD_IMPL_HPP 21 template<
typename InputDataType,
typename OutputDataType>
27 template<
typename InputDataType,
typename OutputDataType>
28 template<
typename PredictionType,
typename TargetType>
29 typename PredictionType::elem_type
31 const PredictionType& prediction,
32 const TargetType& target)
34 typedef typename PredictionType::elem_type ElemType;
36 for (
size_t i = 0; i < prediction.n_cols; ++i)
38 Log::Assert(target(i) >= 0 && target(i) < prediction.n_rows,
39 "Target class out of range.");
41 output -= prediction(target(i), i);
47 template<
typename InputDataType,
typename OutputDataType>
48 template<
typename PredictionType,
typename TargetType,
typename LossType>
50 const PredictionType& prediction,
51 const TargetType& target,
54 loss = arma::zeros<LossType>(prediction.n_rows, prediction.n_cols);
55 for (
size_t i = 0; i < prediction.n_cols; ++i)
57 Log::Assert(target(i) >= 0 && target(i) < prediction.n_rows,
58 "Target class out of range.");
60 loss(target(i), i) = -1;
64 template<
typename InputDataType,
typename OutputDataType>
65 template<
typename Archive>
67 Archive& ,
const uint32_t )
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: negative_log_likelihood_impl.hpp:49
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
NegativeLogLikelihood()
Create the NegativeLogLikelihoodLayer object.
Definition: negative_log_likelihood_impl.hpp:22
void serialize(Archive &, const uint32_t)
Serialize the layer.
Definition: negative_log_likelihood_impl.hpp:66
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Negative log likelihood.
Definition: negative_log_likelihood_impl.hpp:30
static void Assert(bool condition, const std::string &message="Assert Failed.")
Checks if the specified condition is true.
Definition: log.cpp:38