max_iteration_termination.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_AMF_TERMINATION_POLICIES_MAX_ITERATION_TERMINATION_HPP
14 #define MLPACK_METHODS_AMF_TERMINATION_POLICIES_MAX_ITERATION_TERMINATION_HPP
15 
16 namespace mlpack {
17 namespace amf {
18 
24 {
25  public:
33  MaxIterationTermination(const size_t maxIterations) :
34  maxIterations(maxIterations),
35  iteration(0)
36  {
37  if (maxIterations == 0)
38  Log::Warn << "MaxIterationTermination::MaxIterationTermination(): given "
39  << "number of iterations is 0, so algorithm will never terminate!"
40  << std::endl;
41  }
42 
46  template<typename MatType>
47  void Initialize(const MatType& /* V */) { }
48 
52  bool IsConverged(const arma::mat& /* H */, const arma::mat& /* W */)
53  {
54  // Return true if we have performed the correct number of iterations.
55  return (++iteration >= maxIterations);
56  }
57 
60  size_t Index()
61  {
62  return (iteration > maxIterations) ? 0 : maxIterations - iteration;
63  }
64 
66  size_t Iteration() const { return iteration; }
68  size_t& Iteration() { return iteration; }
69 
71  size_t MaxIterations() const { return maxIterations; }
73  size_t& MaxIterations() { return maxIterations; }
74 
75  private:
77  size_t maxIterations;
79  size_t iteration;
80 };
81 
82 } // namespace amf
83 } // namespace mlpack
84 
85 #endif
size_t Iteration() const
Get the current iteration.
MaxIterationTermination(const size_t maxIterations)
Construct the termination policy with the given number of iterations allowed (default 1000)...
Linear algebra utility functions, generally performed on matrices or vectors.
size_t & Iteration()
Modify the current iteration.
size_t MaxIterations() const
Get the maximum number of iterations.
void Initialize(const MatType &)
Initialize for the given matrix V (there is nothing to do).
size_t Index()
Return something similar to the residue, which in this case is just the number of iterations left...
This termination policy only terminates when the maximum number of iterations has been reached...
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:87
size_t & MaxIterations()
Modify the maximum number of iterations.
bool IsConverged(const arma::mat &, const arma::mat &)
Check if convergence has occurred.