mlpack  master
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 "random_init.hpp"
32 
33 namespace mlpack {
34 namespace ann {
35 
53 {
54  public:
63  const double upperBound = 0.5) :
65 
74  template<typename eT>
75  void Initialize(arma::Mat<eT>& W, const size_t rows, const size_t cols)
76  {
78  randomInit.Initialize(W, rows, cols);
79 
80  double beta = 0.7 * std::pow(cols, 1 / rows);
81  W *= (beta / arma::norm(W));
82  }
83 
93  template<typename eT>
94  void Initialize(arma::Cube<eT>& W,
95  const size_t rows,
96  const size_t cols,
97  const size_t slices)
98  {
99  W = arma::Cube<eT>(rows, cols, slices);
100 
101  for (size_t i = 0; i < slices; i++)
102  Initialize(W.slice(i), rows, cols);
103  }
104 
105  private:
107  const double lowerBound;
108 
110  const double upperBound;
111 }; // class NguyenWidrowInitialization
112 
113 
114 } // namespace ann
115 } // namespace mlpack
116 
117 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
const double lowerBound
The number used as lower bound.
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 randomly the weight matrix.
Definition: random_init.hpp:24
The core includes that mlpack expects; standard C++ includes and Armadillo.
const double upperBound
The number used as upper bound.
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 class is used to initialize the weight matrix with the Nguyen-Widrow method. ...
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