mlpack
isrlu_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_ISRLU_IMPL_HPP
13 #define MLPACK_METHODS_ANN_LAYER_ISRLU_IMPL_HPP
14 
15 // In case it hasn't yet been included.
16 #include "isrlu.hpp"
17 
18 namespace mlpack {
19 namespace ann {
20 
21 template<typename InputDataType, typename OutputDataType>
23  alpha(alpha)
24 {}
25 
26 template<typename InputDataType, typename OutputDataType>
27 template<typename InputType, typename OutputType>
29  const InputType& input, OutputType& output)
30 {
31  output = arma::ones<OutputDataType>(arma::size(input));
32  for (size_t i = 0; i < input.n_elem; ++i)
33  {
34  output(i) = (input(i) >= 0) ? input(i) : input(i) *
35  (1 / std::sqrt(1 + alpha * (input(i) * input(i))));
36  }
37 }
38 
39 template<typename InputDataType, typename OutputDataType>
40 template<typename DataType>
42  const DataType& input, const DataType& gy, DataType& g)
43 {
44  derivative.set_size(arma::size(input));
45  for (size_t i = 0; i < input.n_elem; ++i)
46  {
47  derivative(i) = (input(i) >= 0) ? 1 :
48  std::pow(1 / std::sqrt(1 + alpha * input(i) * input(i)), 3);
49  }
50  g = gy % derivative;
51 }
52 
53 template<typename InputDataType, typename OutputDataType>
54 template<typename Archive>
56  Archive& ar,
57  const uint32_t /* version */)
58 {
59  ar(CEREAL_NVP(alpha));
60 }
61 
62 } // namespace ann
63 } // namespace mlpack
64 
65 #endif
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: isrlu_impl.hpp:55
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void Backward(const DataType &input, const DataType &gy, DataType &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
Definition: isrlu_impl.hpp:41
ISRLU(const double alpha=1.0)
Create the ISRLU object using the specified parameter.
Definition: isrlu_impl.hpp:22
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: isrlu_impl.hpp:28