12 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTIONS_CROSS_ENTROPY_ERROR_IMPL_HPP 13 #define MLPACK_METHODS_ANN_LOSS_FUNCTIONS_CROSS_ENTROPY_ERROR_IMPL_HPP 16 #include "binary_cross_entropy_loss.hpp" 21 template<
typename InputDataType,
typename OutputDataType>
23 const double eps,
const bool reduction) : eps(eps), reduction(reduction)
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)
35 typedef typename PredictionType::elem_type ElemType;
37 ElemType loss = -arma::accu(target % arma::log(prediction + eps) +
38 (1. - target) % arma::log(1. - prediction + eps));
40 loss /= prediction.n_elem;
44 template<
typename InputDataType,
typename OutputDataType>
45 template<
typename PredictionType,
typename TargetType,
typename LossType>
47 const PredictionType& prediction,
48 const TargetType& target,
51 loss = (1. - target) / (1. - prediction + eps) - target / (prediction + eps);
53 loss /= prediction.n_elem;
56 template<
typename InputDataType,
typename OutputDataType>
57 template<
typename Archive>
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the cross-entropy function.
Definition: binary_cross_entropy_loss_impl.hpp:31
BCELoss(const double eps=1e-10, const bool reduction=true)
Create the BinaryCrossEntropyLoss object.
Definition: binary_cross_entropy_loss_impl.hpp:22
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: binary_cross_entropy_loss_impl.hpp:58
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: binary_cross_entropy_loss_impl.hpp:46