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