mlpack  master
oivs_init.hpp
Go to the documentation of this file.
1 
27 #ifndef MLPACK_METHODS_ANN_INIT_RULES_OIVS_INIT_HPP
28 #define MLPACK_METHODS_ANN_INIT_RULES_OIVS_INIT_HPP
29 
30 #include <mlpack/prereqs.hpp>
32 
33 #include "random_init.hpp"
34 
35 namespace mlpack {
36 namespace ann {
37 
56 template<
57  class ActivationFunction = LogisticFunction
58 >
60 {
61  public:
69  OivsInitialization(const double epsilon = 0.1,
70  const int k = 5,
71  const double gamma = 0.9) :
72  k(k), gamma(gamma),
73  b(std::abs(ActivationFunction::inv(1 - epsilon) -
74  ActivationFunction::inv(epsilon)))
75  {
76  }
77 
85  template<typename eT>
86  void Initialize(arma::Mat<eT>& W, const size_t rows, const size_t cols)
87  {
88  RandomInitialization randomInit(-gamma, gamma);
89  randomInit.Initialize(W, rows, cols);
90 
91  W = (b / (k * rows)) * arma::sqrt(W + 1);
92  }
93 
103  template<typename eT>
104  void Initialize(arma::Cube<eT>& W,
105  const size_t rows,
106  const size_t cols,
107  const size_t slices)
108  {
109  W = arma::Cube<eT>(rows, cols, slices);
110 
111  for (size_t i = 0; i < slices; i++)
112  Initialize(W.slice(i), rows, cols);
113  }
114 
115  private:
117  const int k;
118 
120  const double gamma;
121 
123  const double b;
124 }; // class OivsInitialization
125 
126 
127 } // namespace ann
128 } // namespace mlpack
129 
130 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
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.
Definition: prereqs.hpp:56
This class is used to initialize the weight matrix with the oivs method.
Definition: oivs_init.hpp:59
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize the elements of the specified weight matrix with the oivs method.
Definition: oivs_init.hpp:86
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 oivs method.
Definition: oivs_init.hpp:104
const double gamma
Parameter to define the uniform random range.
Definition: oivs_init.hpp:120
const double b
Parameter to control the activation region.
Definition: oivs_init.hpp:123
const int k
Parameter to control the activation region width.
Definition: oivs_init.hpp:117
OivsInitialization(const double epsilon=0.1, const int k=5, const double gamma=0.9)
Initialize the random initialization rule with the given values.
Definition: oivs_init.hpp:69
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