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