mlpack
sigmoid_cross_entropy_error_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_SIGMOID_CROSS_ENTROPY_ERROR_IMPL_HPP
14 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_SIGMOID_CROSS_ENTROPY_ERROR_IMPL_HPP
15 
16 // In case it hasn't yet been included.
19 
20 namespace mlpack {
21 namespace ann {
22 
23 template<typename InputDataType, typename OutputDataType>
26 {
27  // Nothing to do here.
28 }
29 
30 template<typename InputDataType, typename OutputDataType>
31 template<typename PredictionType, typename TargetType>
32 inline typename PredictionType::elem_type
34  const PredictionType& prediction,
35  const TargetType& target)
36 {
37  typedef typename PredictionType::elem_type ElemType;
38  ElemType maximum = 0;
39  for (size_t i = 0; i < prediction.n_elem; ++i)
40  {
41  maximum += std::max(prediction[i], 0.0) +
42  std::log(1 + std::exp(-std::abs(prediction[i])));
43  }
44 
45  return maximum - arma::accu(prediction % target);
46 }
47 
48 template<typename InputDataType, typename OutputDataType>
49 template<typename PredictionType, typename TargetType, typename LossType>
51  const PredictionType& prediction,
52  const TargetType& target,
53  LossType& loss)
54 {
55  loss = 1.0 / (1.0 + arma::exp(-prediction)) - target;
56 }
57 
58 template<typename InputDataType, typename OutputDataType>
59 template<typename Archive>
61  Archive& /* ar */,
62  const uint32_t /* version */)
63 {
64  // Nothing to do here
65 }
66 
67 } // namespace ann
68 } // namespace mlpack
69 
70 #endif
SigmoidCrossEntropyError()
Create the SigmoidCrossEntropyError object.
Definition: sigmoid_cross_entropy_error_impl.hpp:25
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: sigmoid_cross_entropy_error_impl.hpp:50
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Sigmoid CrossEntropy Error functions.
Definition: sigmoid_cross_entropy_error_impl.hpp:33
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: sigmoid_cross_entropy_error_impl.hpp:60