incomplete_incremental_termination.hpp
Go to the documentation of this file.
1 
12 #ifndef _MLPACK_METHODS_AMF_INCOMPLETE_INCREMENTAL_TERMINATION_HPP
13 #define _MLPACK_METHODS_AMF_INCOMPLETE_INCREMENTAL_TERMINATION_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace amf {
19 
27 template <class TerminationPolicy>
29 {
30  public:
37  TerminationPolicy tPolicy = TerminationPolicy()) :
38  tPolicy(tPolicy), incrementalIndex(0), iteration(0)
39  { /* Nothing to do here. */ }
40 
46  template<class MatType>
47  void Initialize(const MatType& V)
48  {
49  tPolicy.Initialize(V);
50 
51  // Initialize incremental index to number of rows.
52  incrementalIndex = V.n_rows;
53  iteration = 0;
54  }
55 
62  bool IsConverged(arma::mat& W, arma::mat& H)
63  {
64  // increment iteration count
65  iteration++;
66 
67  // If the iteration count is a multiple of incremental index, return the
68  // wrapped termination policy result.
69  if (iteration % incrementalIndex == 0)
70  return tPolicy.IsConverged(W, H);
71  else
72  return false;
73  }
74 
76  const double& Index() const { return tPolicy.Index(); }
77 
79  const size_t& Iteration() const { return iteration; }
80 
82  size_t MaxIterations() const { return tPolicy.MaxIterations(); }
84  size_t& MaxIterations() { return tPolicy.MaxIterations(); }
85 
87  const TerminationPolicy& TPolicy() const { return tPolicy; }
89  TerminationPolicy& TPolicy() { return tPolicy; }
90 
91  private:
93  TerminationPolicy tPolicy;
94 
96  size_t incrementalIndex;
98  size_t iteration;
99 }; // class IncompleteIncrementalTermination
100 
101 } // namespace amf
102 } // namespace mlpack
103 
104 #endif
size_t & MaxIterations()
Modify maximum number of iterations.
bool IsConverged(arma::mat &W, arma::mat &H)
Check if termination criterio is met.
TerminationPolicy & TPolicy()
Modify the wrapped termination policy.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const TerminationPolicy & TPolicy() const
Access the wrapped termination policy.
const size_t & Iteration() const
Get current iteration count.
IncompleteIncrementalTermination(TerminationPolicy tPolicy=TerminationPolicy())
Empty constructor.
size_t MaxIterations() const
Access maximum number of iterations.
const double & Index() const
Get current value of residue.
This class acts as a wrapper for basic termination policies to be used by SVDIncompleteIncrementalLea...
void Initialize(const MatType &V)
Initializes the termination policy before stating the factorization.