random_acol_init.hpp

Go to the documentation of this file.
00001 
00026 #ifndef __MLPACK_METHODS_NMF_RANDOM_ACOL_INIT_HPP
00027 #define __MLPACK_METHODS_NMF_RANDOM_ACOL_INIT_HPP
00028 
00029 #include <mlpack/core.hpp>
00030 
00031 namespace mlpack {
00032 namespace nmf {
00033 
00041 template<int p = 5>
00042 class RandomAcolInitialization
00043 {
00044  public:
00045   // Empty constructor required for the InitializeRule template
00046   RandomAcolInitialization()
00047   { }
00048 
00049   template<typename MatType>
00050   inline static void Initialize(const MatType& V,
00051                                 const size_t r,
00052                                 arma::mat& W,
00053                                 arma::mat& H)
00054   {
00055     const size_t n = V.n_rows;
00056     const size_t m = V.n_cols;
00057 
00058     if (p > m)
00059     {
00060       Log::Warn << "Number of random columns is more than the number of columns"
00061           << "available in the V matrix; weird results may ensue!" << std::endl;
00062     }
00063 
00064     W.zeros(n, r);
00065 
00066     // Initialize W matrix with random columns.
00067     for (size_t col = 0; col < r; col++)
00068     {
00069       for (size_t randCol = 0; randCol < p; randCol++)
00070       {
00071         // .col() does not work in this case, as of Armadillo 3.920.
00072         W.unsafe_col(col) += V.col(math::RandInt(0, m));
00073       }
00074     }
00075 
00076     // Now divide by p.
00077     W /= p;
00078 
00079     // Initialize H to random values.
00080     H.randu(r, m);
00081   }
00082 }; // Class RandomAcolInitialization
00083 
00084 }; // namespace nmf
00085 }; // namespace mlpack
00086 
00087 #endif

Generated on 29 Sep 2016 for MLPACK by  doxygen 1.6.1