nguyen_widrow_init.hpp
Go to the documentation of this file.
1 
26 #ifndef MLPACK_METHODS_ANN_INIT_RULES_NGUYEN_WIDROW_INIT_HPP
27 #define MLPACK_METHODS_ANN_INIT_RULES_NGUYEN_WIDROW_INIT_HPP
28 
29 #include <mlpack/prereqs.hpp>
30 
31 #include "init_rules_traits.hpp"
32 #include "random_init.hpp"
33 
34 namespace mlpack {
35 namespace ann {
36 
54 {
55  public:
63  NguyenWidrowInitialization(const double lowerBound = -0.5,
64  const double upperBound = 0.5) :
65  lowerBound(lowerBound), upperBound(upperBound) { }
66 
75  template<typename eT>
76  void Initialize(arma::Mat<eT>& W, const size_t rows, const size_t cols)
77  {
78  RandomInitialization randomInit(lowerBound, upperBound);
79  randomInit.Initialize(W, rows, cols);
80 
81  double beta = 0.7 * std::pow(cols, 1 / rows);
82  W *= (beta / arma::norm(W));
83  }
84 
94  template<typename eT>
95  void Initialize(arma::Cube<eT>& W,
96  const size_t rows,
97  const size_t cols,
98  const size_t slices)
99  {
100  W = arma::Cube<eT>(rows, cols, slices);
101 
102  for (size_t i = 0; i < slices; i++)
103  Initialize(W.slice(i), rows, cols);
104  }
105 
106  private:
108  double lowerBound;
109 
111  double upperBound;
112 }; // class NguyenWidrowInitialization
113 
115 template<>
117 {
118  public:
120  static const bool UseLayer = false;
121 };
122 
123 
124 } // namespace ann
125 } // namespace mlpack
126 
127 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
This class is used to initialize randomly the weight matrix.
Definition: random_init.hpp:24
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Initialize(arma::Cube< eT > &W, const size_t rows, const size_t cols, const size_t slices)
Initialize the elements of the specified weight 3rd order tensor with the Nguyen-Widrow method...
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize randomly the elements of the specified weight matrix.
Definition: random_init.hpp:56
NguyenWidrowInitialization(const double lowerBound=-0.5, const double upperBound=0.5)
Initialize the random initialization rule with the given lower bound and upper bound.
This is a template class that can provide information about various initialization methods...
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize the elements of the specified weight matrix with the Nguyen-Widrow method.
This class is used to initialize the weight matrix with the Nguyen-Widrow method. ...