mlpack  2.0.1
random_acol_init.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
15 #define __MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP
16 
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace amf {
21 
44 template<size_t columnsToAverage = 5>
46 {
47  public:
48  // Empty constructor required for the InitializeRule template
50  { }
51 
52  template<typename MatType>
53  inline static void Initialize(const MatType& V,
54  const size_t r,
55  arma::mat& W,
56  arma::mat& H)
57  {
58  const size_t n = V.n_rows;
59  const size_t m = V.n_cols;
60 
61  if (columnsToAverage > m)
62  {
63  Log::Warn << "Number of random columns (columnsToAverage) is more than "
64  << "the number of columns available in the V matrix; weird results "
65  << "may ensue!" << std::endl;
66  }
67 
68  W.zeros(n, r);
69 
70  // Initialize W matrix with random columns.
71  for (size_t col = 0; col < r; col++)
72  {
73  for (size_t randCol = 0; randCol < columnsToAverage; randCol++)
74  {
75  // .col() does not work in this case, as of Armadillo 3.920.
76  W.unsafe_col(col) += V.col(math::RandInt(0, m));
77  }
78  }
79 
80  // Now divide by p.
81  W /= columnsToAverage;
82 
83  // Initialize H to random values.
84  H.randu(r, m);
85  }
86 
88  template<typename Archive>
89  void Serialize(Archive& /* ar */, const unsigned int /* version */) { }
90 };
91 
92 } // namespace amf
93 } // namespace mlpack
94 
95 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
static void Initialize(const MatType &V, const size_t r, arma::mat &W, arma::mat &H)
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
void Serialize(Archive &, const unsigned int)
Serialize the object (in this case, there is nothing to serialize).
static util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:84
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:67