[mlpack-git] master: Add as-of-yet untested termination policy. Tests will come soon, but I want to work from a different system... (9e80681)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Tue Jul 7 11:29:16 EDT 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/267bf1f0ace881bea4a38bf1156cc9f503930f09...9e806819495ee24c60d7b63b1fee1ab74c52f6cc

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

commit 9e806819495ee24c60d7b63b1fee1ab74c52f6cc
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Jul 7 11:28:42 2015 -0400

    Add as-of-yet untested termination policy.
    Tests will come soon, but I want to work from a different system...


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

9e806819495ee24c60d7b63b1fee1ab74c52f6cc
 .../max_iteration_termination.hpp                  | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/src/mlpack/methods/amf/termination_policies/max_iteration_termination.hpp b/src/mlpack/methods/amf/termination_policies/max_iteration_termination.hpp
new file mode 100644
index 0000000..ac1cc7b
--- /dev/null
+++ b/src/mlpack/methods/amf/termination_policies/max_iteration_termination.hpp
@@ -0,0 +1,73 @@
+/**
+ * @file max_iteration_termination.hpp
+ * @author Ryan Curtin
+ *
+ * A termination policy which only terminates when the maximum number of
+ * iterations is reached.
+ */
+#ifndef __MLPACK_METHODS_AMF_TERMINATION_POLICIES_MAX_ITERATION_TERMINATION_HPP
+#define __MLPACK_METHODS_AMF_TERMINATION_POLICIES_MAX_ITERATION_TERMINATION_HPP
+
+namespace mlpack {
+namespace amf {
+
+/**
+ * This termination policy only terminates when the maximum number of iterations
+ * has been reached.
+ */
+class MaxIterationTermination
+{
+ public:
+  /**
+   * Construct the termination policy with the given number of iterations
+   * allowed (default 1000).  If maxIterations is 0, then termination will never
+   * occur.
+   *
+   * @param maxIterations Maximum number of allowed iterations.
+   */
+  MaxIterationTermination(const size_t maxIterations) :
+      maxIterations(maxIterations),
+      iteration(0)
+  {
+    if (maxIterations == 0)
+      Log::Warn << "MaxIterationTermination::MaxIterationTermination(): given "
+          << "number of iterations is 0, so algorithm will never terminate!"
+          << std::endl;
+  }
+
+  /**
+   * Initialize for the given matrix V (there is nothing to do).
+   */
+  template<typename MatType>
+  void Initialize(const MatType& /* V */) { }
+
+  /**
+   * Check if convergence has occurred.
+   */
+  bool IsConverged(const arma::mat& /* H */, const arma::mat& /* W */)
+  {
+    // Return true if we have performed the correct number of iterations.
+    return (++iteration == maxIterations);
+  }
+
+  //! Get the current iteration.
+  size_t Iteration() const { return iteration; }
+  //! Modify the current iteration.
+  size_t& Iteration() { return iteration; }
+
+  //! Get the maximum number of iterations.
+  size_t MaxIterations() const { return maxIterations; }
+  //! Modify the maximum number of iterations.
+  size_t& MaxIterations() { return maxIterations; }
+
+ private:
+  //! The maximum number of allowed iterations.
+  size_t maxIterations;
+  //! The number of the current iteration.
+  size_t iteration;
+};
+
+} // namespace amf
+} // namespace mlpack
+
+#endif



More information about the mlpack-git mailing list