mlpack  master
random_init.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_LMF_RANDOM_INIT_HPP
14 #define MLPACK_METHODS_LMF_RANDOM_INIT_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace amf {
20 
26 {
27  public:
28  // Empty constructor required for the InitializeRule template
30 
39  template<typename MatType>
40  inline static void Initialize(const MatType& V,
41  const size_t r,
42  arma::mat& W,
43  arma::mat& H)
44  {
45  // Simple implementation (left in the header file due to its simplicity).
46  const size_t n = V.n_rows;
47  const size_t m = V.n_cols;
48 
49  // Initialize to random values.
50  W.randu(n, r);
51  H.randu(r, m);
52  }
53 
55  template<typename Archive>
56  void Serialize(Archive& /* ar */, const unsigned int /* version */) { }
57 };
58 
59 } // namespace amf
60 } // namespace mlpack
61 
62 #endif
This initialization rule for AMF simply fills the W and H matrices with uniform random noise in [0...
Definition: random_init.hpp:25
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
void Serialize(Archive &, const unsigned int)
Serialize the object (in this case, there is nothing to serialize).
Definition: random_init.hpp:56
The core includes that mlpack expects; standard C++ includes and Armadillo.
static void Initialize(const MatType &V, const size_t r, arma::mat &W, arma::mat &H)
Fill W and H with random uniform noise.
Definition: random_init.hpp:40