[mlpack-git] master: Refactor code for better comments and better adherence to coding conventions. No functionality change. (2470078)

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


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

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

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

commit 2470078bae2fe63618e3c218722b957cce0573d6
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Nov 6 05:41:27 2014 +0000

    Refactor code for better comments and better adherence to coding conventions.
    No functionality change.


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

2470078bae2fe63618e3c218722b957cce0573d6
 .../complete_incremental_termination.hpp           | 80 ++++++++++++----------
 1 file changed, 42 insertions(+), 38 deletions(-)

diff --git a/src/mlpack/methods/amf/termination_policies/complete_incremental_termination.hpp b/src/mlpack/methods/amf/termination_policies/complete_incremental_termination.hpp
index 44cf852..3700aeb 100644
--- a/src/mlpack/methods/amf/termination_policies/complete_incremental_termination.hpp
+++ b/src/mlpack/methods/amf/termination_policies/complete_incremental_termination.hpp
@@ -4,19 +4,19 @@
  *
  * Termination policy used in AMF (Alternating Matrix Factorization).
  */
-#ifndef _MLPACK_METHODS_AMF_COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
-#define _MLPACK_METHODS_AMF_COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
+#ifndef __MLPACK_METHODS_AMF_COMPLETE_INCREMENTAL_TERMINATION_HPP
+#define __MLPACK_METHODS_AMF_COMPLETE_INCREMENTAL_TERMINATION_HPP
 
-namespace mlpack
-{
-namespace amf
-{
+namespace mlpack {
+namespace amf {
 
 /**
  * This class acts as a wrapper for basic termination policies to be used by
  * SVDCompleteIncrementalLearning. This class calls the wrapped class functions
  * after every n calls to main class functions where n is the number of non-zero
- * entries in the matrix being factorized. 
+ * entries in the matrix being factorized. This is necessary for
+ * SVDCompleteIncrementalLearning, because otherwise IsConverged() is called
+ * after every point, which is very slow.
  *
  * @see AMF, SVDCompleteIncrementalLearning
  */
@@ -25,12 +25,12 @@ class CompleteIncrementalTermination
 {
  public:
   /**
-   * Empty constructor
+   * Empty constructor.
    *
-   * @param t_policy object of wrapped class.
+   * @param tPolicy object of wrapped class.
    */
-  CompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy())
-            : t_policy(t_policy) {}
+  CompleteIncrementalTermination(TerminationPolicy tPolicy = TerminationPolicy())
+      : tPolicy(tPolicy) { }
 
   /**
    * Initializes the termination policy before stating the factorization.
@@ -40,73 +40,77 @@ class CompleteIncrementalTermination
   template <class MatType>
   void Initialize(const MatType& V)
   {
-    t_policy.Initialize(V);
+    tPolicy.Initialize(V);
 
-    //! get number of non-zero entries
-    incrementalIndex = accu(V != 0);
+    // Get the number of non-zero entries.
+    incrementalIndex = arma::accu(V != 0);
     iteration = 0;
   }
 
   /**
-   * Initializes the termination policy before stating the factorization.
+   * Initializes the termination policy before stating the factorization.  This
+   * is a specialization for sparse matrices.
    *
    * @param V Input matrix to be factorized.
    */
   void Initialize(const arma::sp_mat& V)
   {
-    t_policy.Initialize(V);
+    tPolicy.Initialize(V);
 
-    // get number of non-zero entries
+    // Get number of non-zero entries
     incrementalIndex = V.n_nonzero;
     iteration = 0;
   }
 
   /**
-   * Check if termination criterio is met.
+   * Check if termination criterion is met, if the current iteration means that
+   * each point has been visited.
    *
    * @param W Basis matrix of output.
    * @param H Encoding matrix of output.
    */
   bool IsConverged(arma::mat& W, arma::mat& H)
   {
-    // increment iteration count
+    // Increment iteration count.
     iteration++;
 
-    // if iteration count is multiple of incremental index,
-    // return wrapped class function
-    if(iteration % incrementalIndex == 0)
-      return t_policy.IsConverged(W, H);
-    // else just return false
-    else return false;
+    // If iteration count is multiple of incremental index, return wrapped class
+    // function.
+    if (iteration % incrementalIndex == 0)
+      return tPolicy.IsConverged(W, H);
+    else
+      return false;
   }
 
   //! Get current value of residue
-  const double& Index() const { return t_policy.Index(); }
+  const double& Index() const { return tPolicy.Index(); }
 
   //! Get current iteration count
   const size_t& Iteration() const { return iteration; }
 
-  //! Access upper limit of iteration count
-  const size_t& MaxIterations() const { return t_policy.MaxIterations(); }
-  size_t& MaxIterations() { return t_policy.MaxIterations(); }
+  //! Access upper limit of iteration count.
+  const size_t& MaxIterations() const { return tPolicy.MaxIterations(); }
+  //! Modify maximum number of iterations.
+  size_t& MaxIterations() { return tPolicy.MaxIterations(); }
 
-  //! Access the wrapped class object
-  const TerminationPolicy& TPolicy() const { return t_policy; }
-  TerminationPolicy& TPolicy() { return t_policy; }
+  //! Access the wrapped termination policy.
+  const TerminationPolicy& TPolicy() const { return tPolicy; }
+  //! Modify the wrapped termination policy.
+  TerminationPolicy& TPolicy() { return tPolicy; }
 
  private:
-  //! wrapped class object
-  TerminationPolicy t_policy;
+  //! Wrapped termination policy.
+  TerminationPolicy tPolicy;
 
-  //! number of iterations after which wrapped class object will be called
+  //! Number of iterations after which wrapped termination policy will be
+  //! called.
   size_t incrementalIndex;
-  //! current iteration count
+  //! Current iteration number.
   size_t iteration;
 }; // class CompleteIncrementalTermination
 
 } // namespace amf
 } // namespace mlpack
 
-
-#endif // COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
+#endif // __MLPACK_METHODS_AMF_COMPLETE_INCREMENTAL_TERMINATION_HPP
 



More information about the mlpack-git mailing list