mlpack  master
given_init.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_AMF_INIT_RULES_GIVEN_INIT_HPP
14 #define MLPACK_METHODS_AMF_INIT_RULES_GIVEN_INIT_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace amf {
20 
28 {
29  public:
30  // Empty constructor required for the InitializeRule template.
32 
33  // Initialize the GivenInitialization object with the given matrices.
34  GivenInitialization(const arma::mat& w, const arma::mat& h) : w(w), h(h) { }
35 
36  // Initialize the GivenInitialization object, taking control of the given
37  // matrices.
38  GivenInitialization(const arma::mat&& w, const arma::mat&& h) :
39  w(std::move(w)),
40  h(std::move(h))
41  { }
42 
51  template<typename MatType>
52  inline void Initialize(const MatType& /* V */,
53  const size_t /* r */,
54  arma::mat& W,
55  arma::mat& H)
56  {
57  // Initialize to the given matrices.
58  W = w;
59  H = h;
60  }
61 
63  template<typename Archive>
64  void Serialize(Archive& ar, const unsigned int /* version */)
65  {
66  ar & data::CreateNVP(w, "w");
67  ar & data::CreateNVP(h, "h");
68  }
69 
70  private:
72  arma::mat w;
74  arma::mat h;
75 };
76 
77 } // namespace amf
78 } // namespace mlpack
79 
80 #endif
void Initialize(const MatType &, const size_t, arma::mat &W, arma::mat &H)
Fill W and H with random uniform noise.
Definition: given_init.hpp:52
arma::mat h
The H matrix for initialization.
Definition: given_init.hpp:74
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename std::enable_if_t< HasSerialize< T >::value > *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
Definition: prereqs.hpp:56
void Serialize(Archive &ar, const unsigned int)
Serialize the object (in this case, there is nothing to serialize).
Definition: given_init.hpp:64
This initialization rule for AMF simply fills the W and H matrices with the matrices given to the con...
Definition: given_init.hpp:27
GivenInitialization(const arma::mat &&w, const arma::mat &&h)
Definition: given_init.hpp:38
arma::mat w
The W matrix for initialization.
Definition: given_init.hpp:72
GivenInitialization(const arma::mat &w, const arma::mat &h)
Definition: given_init.hpp:34