[mlpack-git] master: Refactoring. (d27eb05)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:15:56 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit d27eb0560c7a36bc02b72eb95f48f5ad7de62153
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Feb 9 11:59:29 2015 -0500
Refactoring.
>---------------------------------------------------------------
d27eb0560c7a36bc02b72eb95f48f5ad7de62153
.../methods/amf/init_rules/random_acol_init.hpp | 40 +++++++++++++++-------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/mlpack/methods/amf/init_rules/random_acol_init.hpp b/src/mlpack/methods/amf/init_rules/random_acol_init.hpp
index 6d2066d..3bf9ad3 100644
--- a/src/mlpack/methods/amf/init_rules/random_acol_init.hpp
+++ b/src/mlpack/methods/amf/init_rules/random_acol_init.hpp
@@ -15,13 +15,26 @@ namespace amf {
/**
* This class initializes the W matrix of the AMF algorithm by averaging p
* randomly chosen columns of V. In this case, p is a template parameter. H is
- * then set randomly This simple initialization is performed by the random
- * Acol initialization introduced in the paper 'Algorithms, Initializations and
- * Convergence' by Langville et al.
+ * then filled using a uniform distribution in the range [0, 1].
*
- * @tparam The number of random columns to average for each column of W.
+ * This simple initialization is the "random Acol initialization" found in the
+ * following paper:
+ *
+ * @code
+ * @techreport{langville2014algorithms,
+ * title = {Algorithms, Initializations, and Convergence for the Nonnegative
+ * Matrix Factorization},
+ * author = {Langville, A.N. and Meyer, C.D. and Albright, R. and Cox, J. and
+ * Duling, D.},
+ * year = {2014},
+ * institution = {NCSU Technical Report Math 81706}
+ * }
+ * @endcode
+ *
+ * @tparam columnsToAverage The number of random columns to average for each
+ * column of W.
*/
-template<int p = 5>
+template<size_t columnsToAverage = 5>
class RandomAcolInitialization
{
public:
@@ -38,10 +51,11 @@ class RandomAcolInitialization
const size_t n = V.n_rows;
const size_t m = V.n_cols;
- if (p > m)
+ if (columnsToAverage > m)
{
- Log::Warn << "Number of random columns is more than the number of columns"
- << "available in the V matrix; weird results may ensue!" << std::endl;
+ Log::Warn << "Number of random columns (columnsToAverage) is more than "
+ << "the number of columns available in the V matrix; weird results "
+ << "may ensue!" << std::endl;
}
W.zeros(n, r);
@@ -49,7 +63,7 @@ class RandomAcolInitialization
// Initialize W matrix with random columns.
for (size_t col = 0; col < r; col++)
{
- for (size_t randCol = 0; randCol < p; randCol++)
+ for (size_t randCol = 0; randCol < columnsToAverage; randCol++)
{
// .col() does not work in this case, as of Armadillo 3.920.
W.unsafe_col(col) += V.col(math::RandInt(0, m));
@@ -57,14 +71,14 @@ class RandomAcolInitialization
}
// Now divide by p.
- W /= p;
+ W /= columnsToAverage;
// Initialize H to random values.
H.randu(r, m);
}
-}; // Class RandomAcolInitialization
+};
-}; // namespace amf
-}; // namespace mlpack
+} // namespace amf
+} // namespace mlpack
#endif
More information about the mlpack-git
mailing list