MLPACK  1.0.11
complete_incremental_termination.hpp
Go to the documentation of this file.
1 
22 #ifndef COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
23 #define COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
24 
25 namespace mlpack
26 {
27 namespace amf
28 {
29 
30 template <class TerminationPolicy>
32 {
33  public:
39  CompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy())
40  : t_policy(t_policy) {}
41 
42  template <class MatType>
43  void Initialize(const MatType& V)
44  {
45  t_policy.Initialize(V);
46 
47  incrementalIndex = accu(V != 0);
48  iteration = 0;
49  }
50 
51  void Initialize(const arma::sp_mat& V)
52  {
53  t_policy.Initialize(V);
54 
55  incrementalIndex = V.n_nonzero;
56  iteration = 0;
57  }
58 
59  bool IsConverged(arma::mat& W, arma::mat& H)
60  {
61  iteration++;
62  if(iteration % incrementalIndex == 0)
63  return t_policy.IsConverged(W, H);
64  else return false;
65  }
66 
67  const double& Index()
68  {
69  return t_policy.Index();
70  }
71  const size_t& Iteration()
72  {
73  return iteration;
74  }
75 
76  const size_t& MaxIterations()
77  {
78  return t_policy.MaxIterations();
79  }
80 
81  private:
82  TerminationPolicy t_policy;
83 
85  size_t iteration;
86 };
87 
88 } // namespace amf
89 } // namespace mlpack
90 
91 
92 #endif // COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
93 
CompleteIncrementalTermination(TerminationPolicy t_policy=TerminationPolicy())
Empty constructor.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31