mlpack 3.4.2
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
18namespace mlpack {
19namespace 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
62 template<typename MatType>
63 inline void InitializeOne(const MatType& V,
64 const size_t r,
65 arma::mat& M,
66 const bool whichMatrix = true)
67 {
68 // Simple implementation (left in the header file due to its simplicity).
69 const size_t n = V.n_rows;
70 const size_t m = V.n_cols;
71
72 // Initialize W or H to random values
73 if (whichMatrix)
74 {
75 M.randu(n, r);
76 }
77 else
78 {
79 M.randu(r, m);
80 }
81 }
82
84 template<typename Archive>
85 void serialize(Archive& /* ar */, const unsigned int /* version */) { }
86};
87
88} // namespace amf
89} // namespace mlpack
90
91#endif
This initialization rule for AMF simply fills the W and H matrices with uniform random noise in [0,...
Definition: random_init.hpp:26
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
void serialize(Archive &, const unsigned int)
Serialize the object (in this case, there is nothing to serialize).
Definition: random_init.hpp:85
void InitializeOne(const MatType &V, const size_t r, arma::mat &M, const bool whichMatrix=true)
Fill W or H with random uniform noise.
Definition: random_init.hpp:63
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.