[mlpack] 29/44: Add AverageInitialization.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Mon Feb 15 19:35:54 UTC 2016
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to tag mlpack-1.0.11
in repository mlpack.
commit df0e5aff82f483d593c79d2d9f0d2e8a6a814f2b
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Dec 8 00:58:07 2014 +0000
Add AverageInitialization.
---
src/mlpack/methods/amf/init_rules/average_init.hpp | 63 ++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/src/mlpack/methods/amf/init_rules/average_init.hpp b/src/mlpack/methods/amf/init_rules/average_init.hpp
new file mode 100644
index 0000000..cf01ce4
--- /dev/null
+++ b/src/mlpack/methods/amf/init_rules/average_init.hpp
@@ -0,0 +1,63 @@
+/**
+ * @file averge_init.hpp
+ * @author Sumedh Ghaisas
+ *
+ * Intialization rule for Alternating Matrix Factorization.
+ */
+#ifndef __MLPACK_METHODS_AMF_AVERAGE_INIT_HPP
+#define __MLPACK_METHODS_AMF_AVERAGE_INIT_HPP
+
+#include <mlpack/core.hpp>
+
+namespace mlpack {
+namespace amf {
+
+/**
+ * This initialization rule initializes matrix W and H to root of average of V
+ * with uniform noise. Uniform noise is generated by Armadillo's 'randu' function.
+ * To have a better effect lower bound of the matrix is subtracted from average
+ * before dividing it by the factorization rank. This computed value is added
+ * with the random noise.
+ */
+class AverageInitialization
+{
+ public:
+ // Empty constructor required for the InitializeRule template
+ AverageInitialization() { }
+
+ template<typename MatType>
+ inline static void Initialize(const MatType& V,
+ const size_t r,
+ arma::mat& W,
+ arma::mat& H)
+ {
+ size_t n = V.n_rows;
+ size_t m = V.n_cols;
+
+ double V_avg = 0;
+ size_t count = 0;
+ double min = DBL_MAX;
+ for(typename MatType::const_row_col_iterator it = V.begin();it != V.end();it++)
+ {
+ if(*it != 0)
+ {
+ count++;
+ V_avg += *it;
+ if(*it < min) min = *it;
+ }
+ }
+ V_avg = sqrt(((V_avg / (n * m)) - min) / r);
+
+ // Intialize to random values.
+ W.randu(n, r);
+ H.randu(r, m);
+
+ W = W + V_avg;
+ H = H + V_avg;
+ }
+};
+
+}; // namespace amf
+}; // namespace mlpack
+
+#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list