MLPACK  1.0.11
random_acol_init.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
23 #define __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
24 
25 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace amf {
29 
39 template<int p = 5>
41 {
42  public:
43  // Empty constructor required for the InitializeRule template
45  { }
46 
47  template<typename MatType>
48  inline static void Initialize(const MatType& V,
49  const size_t r,
50  arma::mat& W,
51  arma::mat& H)
52  {
53  const size_t n = V.n_rows;
54  const size_t m = V.n_cols;
55 
56  if (p > m)
57  {
58  Log::Warn << "Number of random columns is more than the number of columns"
59  << "available in the V matrix; weird results may ensue!" << std::endl;
60  }
61 
62  W.zeros(n, r);
63 
64  // Initialize W matrix with random columns.
65  for (size_t col = 0; col < r; col++)
66  {
67  for (size_t randCol = 0; randCol < p; randCol++)
68  {
69  // .col() does not work in this case, as of Armadillo 3.920.
70  W.unsafe_col(col) += V.col(math::RandInt(0, m));
71  }
72  }
73 
74  // Now divide by p.
75  W /= p;
76 
77  // Initialize H to random values.
78  H.randu(r, m);
79  }
80 }; // Class RandomAcolInitialization
81 
82 }; // namespace amf
83 }; // namespace mlpack
84 
85 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
static void Initialize(const MatType &V, const size_t r, arma::mat &W, arma::mat &H)
static util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:92
This class initializes the W matrix of the AMF algorithm by averaging p randomly chosen columns of V...
int RandInt(const int hiExclusive)
Generates a uniform random integer.
Definition: random.hpp:106