[mlpack] 79/149: Refactor code for better comments and better adherence to coding conventions. No functionality change.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Sat May 2 09:11:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit 6f0d7b62bb2d3a030f66670f74650d2dafe38c83
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Thu Nov 6 05:41:27 2014 +0000
Refactor code for better comments and better adherence to coding conventions.
No functionality change.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17307 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../complete_incremental_termination.hpp | 92 +++++++++++-----------
1 file changed, 48 insertions(+), 44 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
+ * 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
+ //! 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 the wrapped class object
- const TerminationPolicy& TPolicy() const { return t_policy; }
- TerminationPolicy& TPolicy() { return t_policy; }
+
+ //! 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 termination policy.
+ const TerminationPolicy& TPolicy() const { return tPolicy; }
+ //! Modify the wrapped termination policy.
+ TerminationPolicy& TPolicy() { return tPolicy; }
private:
- //! wrapped class object
- TerminationPolicy t_policy;
-
- //! number of iterations after which wrapped class object will be called
+ //! Wrapped termination policy.
+ TerminationPolicy tPolicy;
+
+ //! 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
--
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