[mlpack-git] master: * minor changes (9657fd5)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:57:02 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 9657fd537117ef4f6f9b3bc36e9fff52b01de3c2
Author: sumedhghaisas <sumedhghaisas at gmail.com>
Date:   Wed Aug 6 21:38:07 2014 +0000

    * minor changes


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

9657fd537117ef4f6f9b3bc36e9fff52b01de3c2
 src/mlpack/methods/cf/cf.hpp        |  1 +
 src/mlpack/methods/cf/cf_impl.hpp   |  1 +
 src/mlpack/methods/cf/plain_svd.cpp | 18 ++++++++++++++++
 src/mlpack/methods/cf/plain_svd.hpp | 41 +++++++++++++++++++++++++++++++++----
 src/mlpack/tests/plain_svd_test.cpp |  1 +
 5 files changed, 58 insertions(+), 4 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;



More information about the mlpack-git mailing list