mlpack
softmin_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP
13 #define MLPACK_METHODS_ANN_LAYER_SOFTMIN_IMPL_HPP
14 
15 // In case it hasn't yet been included.
16 #include "softmin.hpp"
17 
18 namespace mlpack {
19 namespace ann {
20 
21 template<typename InputDataType, typename OutputDataType>
23 {
24  // Nothing to do here.
25 }
26 
27 template<typename InputDataType, typename OutputDataType>
28 template<typename InputType, typename OutputType>
30  const InputType& input,
31  OutputType& output)
32 {
33  InputType softminInput = arma::exp(-(input.each_row() -
34  arma::min(input, 0)));
35  output = softminInput.each_row() / sum(softminInput, 0);
36 }
37 
38 template<typename InputDataType, typename OutputDataType>
39 template<typename eT>
41  const arma::Mat<eT>& input,
42  const arma::Mat<eT>& gy,
43  arma::Mat<eT>& g)
44 {
45  g = input % (gy - arma::repmat(arma::sum(gy % input), input.n_rows, 1));
46 }
47 
48 template<typename InputDataType, typename OutputDataType>
49 template<typename Archive>
51  Archive& /* ar */,
52  const uint32_t /* version */)
53 {
54  // Nothing to do here.
55 }
56 
57 } // namespace ann
58 } // namespace mlpack
59 
60 #endif
void serialize(Archive &, const uint32_t)
Serialize the layer.
Definition: softmin_impl.hpp:50
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
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: softmin_impl.hpp:29
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: softmin_impl.hpp:40
Softmin()
Create the Softmin object.
Definition: softmin_impl.hpp:22