[mlpack-git] mlpack-1.0.x: Add AverageInitialization. (df0e5af)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:07:23 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit df0e5aff82f483d593c79d2d9f0d2e8a6a814f2b
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Dec 8 00:58:07 2014 +0000

    Add AverageInitialization.


>---------------------------------------------------------------

df0e5aff82f483d593c79d2d9f0d2e8a6a814f2b
 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



More information about the mlpack-git mailing list