gaussian_init.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_ANN_INIT_RULES_GAUSSIAN_INIT_HPP
15 #define MLPACK_METHODS_ANN_INIT_RULES_GAUSSIAN_INIT_HPP
16 
17 #include <mlpack/prereqs.hpp>
19 
20 using namespace mlpack::math;
21 
22 namespace mlpack {
23 namespace ann {
24 
29 {
30  public:
37  GaussianInitialization(const double mean = 0, const double variance = 1) :
38  mean(mean), variance(variance)
39  {
40  // Nothing to do here.
41  }
42 
50  template<typename eT>
51  void Initialize(arma::Mat<eT>& W,
52  const size_t rows,
53  const size_t cols)
54  {
55  if (W.is_empty())
56  {
57  W = arma::Mat<eT>(rows, cols);
58  }
59  W.imbue( [&]() { return arma::as_scalar(RandNormal(mean, variance)); } );
60  }
61 
70  template<typename eT>
71  void Initialize(arma::Cube<eT> & W,
72  const size_t rows,
73  const size_t cols,
74  const size_t slices)
75  {
76  W = arma::Cube<eT>(rows, cols, slices);
77 
78  for (size_t i = 0; i < slices; i++)
79  Initialize(W.slice(i), rows, cols);
80  }
81 
82  private:
84  double mean;
85 
87  double variance;
88 }; // class GaussianInitialization
89 
90 } // namespace ann
91 } // namespace mlpack
92 
93 #endif
.hpp
Definition: add_to_po.hpp:21
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize the elements weight matrix using a Gaussian Distribution.
The core includes that mlpack expects; standard C++ includes and Armadillo.
GaussianInitialization(const double mean=0, const double variance=1)
Initialize the gaussian with the given mean and variance.
double RandNormal()
Generates a normally distributed random number with mean 0 and variance 1.
Definition: random.hpp:122
Miscellaneous math routines.
Definition: ccov.hpp:20
Miscellaneous math random-related routines.
void Initialize(arma::Cube< eT > &W, const size_t rows, const size_t cols, const size_t slices)
Initialize randomly the elements of the specified weight 3rd order tensor.
This class is used to initialize weigth matrix with a gaussian.