12 #ifndef MLPACK_METHODS_ANN_LAYER_LOG_SOFTMAX_IMPL_HPP 13 #define MLPACK_METHODS_ANN_LAYER_LOG_SOFTMAX_IMPL_HPP 21 template<
typename InputDataType,
typename OutputDataType>
27 template<
typename InputDataType,
typename OutputDataType>
28 template<
typename InputType,
typename OutputType>
30 const InputType& input, OutputType& output)
32 arma::mat maxInput = arma::repmat(arma::max(input), input.n_rows, 1);
33 output = (maxInput - input);
37 output.transform([](
double x)
40 static constexpr
double A0 = 1.0;
41 static constexpr
double A1 = 0.125;
42 static constexpr
double A2 = 0.0078125;
43 static constexpr
double A3 = 0.00032552083;
44 static constexpr
double A4 = 1.0172526e-5;
48 double y = A0 + x * (A1 + x * (A2 + x * (A3 + x * A4)));
60 maxInput.each_row() += arma::log(arma::sum(output));
61 output = input - maxInput;
64 template<
typename InputDataType,
typename OutputDataType>
67 const arma::Mat<eT>& input,
68 const arma::Mat<eT>& gy,
71 g = arma::exp(input) + gy;
74 template<
typename InputDataType,
typename OutputDataType>
75 template<
typename Archive>
void Forward(const InputType &input, OutputType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
Definition: log_softmax_impl.hpp:29
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void serialize(Archive &, const uint32_t)
Serialize the layer.
Definition: log_softmax_impl.hpp:76
void Backward(const arma::Mat< eT > &input, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
Definition: log_softmax_impl.hpp:66
LogSoftMax()
Create the LogSoftmax object.
Definition: log_softmax_impl.hpp:22