const_init.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_ANN_INIT_RULES_CONST_INIT_HPP
15 #define MLPACK_METHODS_ANN_INIT_RULES_CONST_INIT_HPP
16 
17 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace ann {
21 
26 {
27  public:
31  ConstInitialization(const double initVal = 0) : initVal(initVal)
32  { /* Nothing to do here */ }
33 
41  template<typename eT>
42  void Initialize(arma::Mat<eT>& W, const size_t rows, const size_t cols)
43  {
44  if (W.is_empty())
45  W.set_size(rows, cols);
46 
47  W.fill(initVal);
48  }
49 
55  template<typename eT>
56  void Initialize(arma::Mat<eT>& W)
57  {
58  if (W.is_empty())
59  Log::Fatal << "Cannot initialize an empty matrix." << std::endl;
60 
61  W.fill(initVal);
62  }
63 
72  template<typename eT>
73  void Initialize(arma::Cube<eT>& W,
74  const size_t rows,
75  const size_t cols,
76  const size_t slices)
77  {
78  if (W.is_empty())
79  W.set_size(rows, cols, slices);
80 
81  W.fill(initVal);
82  }
83 
89  template<typename eT>
90  void Initialize(arma::Cube<eT>& W)
91  {
92  if (W.is_empty())
93  Log::Fatal << "Cannot initialize an empty cube." << std::endl;
94 
95  W.fill(initVal);
96  }
97 
99  double const& InitValue() const { return initVal; }
101  double& InitValue() { return initVal; }
102 
103  template<typename Archive>
104  void serialize(Archive& ar, const uint32_t /* version */)
105  {
106  ar(CEREAL_NVP(initVal));
107  }
108 
109  private:
111  double initVal;
112 }; // class ConstInitialization
113 
114 } // namespace ann
115 } // namespace mlpack
116 
117 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
double & InitValue()
Modify the initialization value.
Definition: const_init.hpp:101
The core includes that mlpack expects; standard C++ includes, Armadillo, cereal, and a few basic mlpa...
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize the elements of the specified weight matrix.
Definition: const_init.hpp:42
ConstInitialization(const double initVal=0)
Create the ConstantInitialization object.
Definition: const_init.hpp:31
void Initialize(arma::Cube< eT > &W)
Initialize the elements of the specified weight (3rd order tensor).
Definition: const_init.hpp:90
void serialize(Archive &ar, const uint32_t)
Definition: const_init.hpp:104
double const & InitValue() const
Get the initialization value.
Definition: const_init.hpp:99
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).
Definition: const_init.hpp:73
This class is used to initialize weight matrix with constant values.
Definition: const_init.hpp:25
void Initialize(arma::Mat< eT > &W)
Initialize the elements of the specified weight matrix.
Definition: const_init.hpp:56
static util::PrefixedOutStream Fatal
Definition: log.hpp:105