lecun_normal_init.hpp
Go to the documentation of this file.
1 
15 #ifndef MLPACK_METHODS_ANN_INIT_RULES_LECUN_NORMAL_INIT_HPP
16 #define MLPACK_METHODS_ANN_INIT_RULES_LECUN_NORMAL_INIT_HPP
17 
18 #include <mlpack/prereqs.hpp>
20 
21 namespace mlpack {
22 namespace ann {
23 
50 {
51  public:
56  {
57  // Nothing to do here.
58  }
59 
68  void Initialize(arma::mat& W,
69  const size_t rows,
70  const size_t cols)
71  {
72  // He initialization rule says to initialize weights with random
73  // values taken from a gaussian distribution with mean = 0 and
74  // standard deviation = sqrt(1 / rows), i.e. variance = (1 / rows).
75  const double variance = 1.0 / ((double) rows);
76 
77  if (W.is_empty())
78  {
79  W.set_size(rows, cols);
80  }
81 
82  // Multipling a random variable X with variance V(X) by some factor c,
83  // then the variance V(cX) = (c ^ 2) * V(X).
84  W.imbue( [&]() { return sqrt(variance) * arma::randn(); } );
85  }
86 
96  void Initialize(arma::cube & W,
97  const size_t rows,
98  const size_t cols,
99  const size_t slices)
100  {
101  if (W.is_empty())
102  W.set_size(rows, cols, slices);
103 
104  for (size_t i = 0; i < slices; i++)
105  Initialize(W.slice(i), rows, cols);
106  }
107 }; // class LecunNormalInitialization
108 
109 } // namespace ann
110 } // namespace mlpack
111 
112 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
This class is used to initialize weight matrix with the Lecun Normalization initialization rule...
void Initialize(arma::mat &W, const size_t rows, const size_t cols)
Initialize the elements of the weight matrix with the Lecun Normal initialization rule...
void Initialize(arma::cube &W, const size_t rows, const size_t cols, const size_t slices)
Initialize the elements of the specified weight 3rd order tensor with Lecun Normal initialization rul...
LecunNormalInitialization()
Initialize the LecunNormalInitialization object.
Miscellaneous math random-related routines.