[mlpack] 294/324: * minor changes

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:20 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit d7ded32c6e3fb6b0d9610eeaf1c4f48d3a9c7eb4
Author: sumedhghaisas <sumedhghaisas at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Wed Aug 6 21:38:07 2014 +0000

    * minor changes
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16978 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/cf/cf.hpp        |  1 +
 src/mlpack/methods/cf/cf_impl.hpp   |  1 +
 src/mlpack/methods/cf/plain_svd.cpp | 20 +++++++++++++++++-
 src/mlpack/methods/cf/plain_svd.hpp | 41 +++++++++++++++++++++++++++++++++----
 src/mlpack/tests/plain_svd_test.cpp |  1 +
 5 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/methods/cf/cf.hpp b/src/mlpack/methods/cf/cf.hpp
index 500ed10..8a7b503 100644
--- a/src/mlpack/methods/cf/cf.hpp
+++ b/src/mlpack/methods/cf/cf.hpp
@@ -1,6 +1,7 @@
 /**
  * @file cf.hpp
  * @author Mudit Raj Gupta
+ * @author Sumedh Ghaisas
  *
  * Collaborative filtering.
  *
diff --git a/src/mlpack/methods/cf/cf_impl.hpp b/src/mlpack/methods/cf/cf_impl.hpp
index 80389bf..65cb78d 100644
--- a/src/mlpack/methods/cf/cf_impl.hpp
+++ b/src/mlpack/methods/cf/cf_impl.hpp
@@ -1,6 +1,7 @@
 /**
  * @file cf.cpp
  * @author Mudit Raj Gupta
+ * @author Sumedh Ghaisas
  *
  * Collaborative Filtering.
  *
diff --git a/src/mlpack/methods/cf/plain_svd.cpp b/src/mlpack/methods/cf/plain_svd.cpp
index 1ea65c2..cdedb69 100644
--- a/src/mlpack/methods/cf/plain_svd.cpp
+++ b/src/mlpack/methods/cf/plain_svd.cpp
@@ -1,3 +1,9 @@
+/**
+ * @file plain_svd.cpp
+ * @author Sumedh Ghaisas
+ *
+ * Implementation of the wrapper class for Armadillo's SVD.
+ */
 #include "plain_svd.hpp"
 
 using namespace mlpack;
@@ -8,9 +14,11 @@ double PlainSVD::Apply(const arma::mat& V,
                        arma::mat& sigma,
                        arma::mat& H) const
 {
+  // get svd factorization
   arma::vec E;
   arma::svd(W, E, H, V);
 
+  // construct sigma matrix 
   sigma.zeros(V.n_rows, V.n_cols);
 
   for(size_t i = 0;i < sigma.n_rows && i < sigma.n_cols;i++)
@@ -18,6 +26,7 @@ double PlainSVD::Apply(const arma::mat& V,
 
   arma::mat V_rec = W * sigma * arma::trans(H);
 
+  // return normalized frobenius error
   return arma::norm(V - V_rec, "fro") / arma::norm(V, "fro");
 }
 
@@ -26,6 +35,7 @@ double PlainSVD::Apply(const arma::mat& V,
                        arma::mat& W,
                        arma::mat& H) const
 {
+  // check if the given rank is valid
   if(r > V.n_rows || r > V.n_cols)
   {
     Log::Info << "Rank " << r << ", given for decomposition is invalid." << std::endl;
@@ -33,19 +43,27 @@ double PlainSVD::Apply(const arma::mat& V,
     Log::Info << "Setting decomposition rank to " << r << std::endl;
   }
 
+  // get svd factorization
   arma::vec sigma;
   arma::svd(W, sigma, H, V);
 
+  // remove the part of W and H depending upon the value of rank
   W = W.submat(0, 0, W.n_rows - 1, r - 1);
   H = H.submat(0, 0, H.n_cols - 1, r - 1);
 
+  // take only required eigenvalues
   sigma = sigma.subvec(0, r - 1);
-
+  
+  // eigenvalue matrix is multiplied to W
+  // it can either be multiplied to H matrix
   W = W * arma::diagmat(sigma);
   
+  // take transpose of the matrix H as required by CF module
   H = arma::trans(H);
 
+  // reconstruct the matrix
   arma::mat V_rec = W * H;
 
+  // return the normalized frobenius norm
   return arma::norm(V - V_rec, "fro") / arma::norm(V, "fro");
 }
diff --git a/src/mlpack/methods/cf/plain_svd.hpp b/src/mlpack/methods/cf/plain_svd.hpp
index facd5ca..f1191d4 100644
--- a/src/mlpack/methods/cf/plain_svd.hpp
+++ b/src/mlpack/methods/cf/plain_svd.hpp
@@ -1,3 +1,9 @@
+/**
+ * @file plain_svd.hpp
+ * @author Sumedh Ghaisas
+ *
+ * Wrapper class for Armadillo's SVD.
+ */
 #ifndef __MLPACK_METHODS_PLAIN_SVD_HPP
 #define __MLPACK_METHODS_PLAIN_SVD_HPP
 
@@ -8,23 +14,50 @@ namespace mlpack
 namespace svd
 {
 
+/**
+ * This class acts as a wrapper class for Armadillo's SVD implementation to be 
+ * used by Collaborative Filteraing module.
+ *
+ * @see CF
+ */
 class PlainSVD
 {
  public:
+  // empty constructor
   PlainSVD() {};
 
+  /**
+   * Factorizer function which takes SVD of the given matrix and returns the 
+   * frobenius norm of error.
+   *
+   * @param V input matrix
+   * @param W first unitary matrix
+   * @param sigma eigenvalue matrix
+   * @param H second unitary matrix
+   *
+   * @note V = W * sigma * arma::trans(H)
+   */
   double Apply(const arma::mat& V,
                arma::mat& W,
                arma::mat& sigma,
                arma::mat& H) const;
-
+  /**
+   * Factorizer function which computes SVD and returns matrices as required by 
+   * CF module.
+   * 
+   * @param V input matrix
+   * @param W first unitary matrix
+   * @param H second unitary matrix
+   *
+   * @note V = W * H
+   */
   double Apply(const arma::mat& V,
                size_t r,
                arma::mat& W,
                arma::mat& H) const;
-};
+}; // class PlainSVD
 
-};
-};
+}; // namespace svd
+}; // namespace mlpack
 
 #endif
diff --git a/src/mlpack/tests/plain_svd_test.cpp b/src/mlpack/tests/plain_svd_test.cpp
index bb73221..0aed9a4 100644
--- a/src/mlpack/tests/plain_svd_test.cpp
+++ b/src/mlpack/tests/plain_svd_test.cpp
@@ -38,6 +38,7 @@ BOOST_AUTO_TEST_CASE(PlainSVDLowRankFactorizationTest)
   mat W_t = randu<mat>(30, 3);
   mat H_t = randu<mat>(3, 40);
   
+  // create a row-rank matrix
   mat test = W_t * H_t;
 
   PlainSVD svd;

-- 
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