MLPACK  1.0.10
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:
34  CompleteIncrementalTermination(TerminationPolicy t_policy = TerminationPolicy())
35  : t_policy(t_policy) {}
36 
37  template <class MatType>
38  void Initialize(const MatType& V)
39  {
40  t_policy.Initialize(V);
41 
42  incrementalIndex = accu(V != 0);
43  iteration = 0;
44  }
45 
46  void Initialize(const arma::sp_mat& V)
47  {
48  t_policy.Initialize(V);
49 
50  incrementalIndex = V.n_nonzero;
51  iteration = 0;
52  }
53 
54  bool IsConverged(arma::mat& W, arma::mat& H)
55  {
56  iteration++;
57  if(iteration % incrementalIndex == 0)
58  return t_policy.IsConverged(W, H);
59  else return false;
60  }
61 
62  const double& Index()
63  {
64  return t_policy.Index();
65  }
66  const size_t& Iteration()
67  {
68  return iteration;
69  }
70 
71  const size_t& MaxIterations()
72  {
73  return t_policy.MaxIterations();
74  }
75 
76  private:
77  TerminationPolicy t_policy;
78 
80  size_t iteration;
81 };
82 
83 } // namespace amf
84 } // namespace mlpack
85 
86 
87 #endif // COMPLETE_INCREMENTAL_TERMINATION_HPP_INCLUDED
88