MLPACK
1.0.11
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
mlpack
methods
amf
termination_policies
simple_residue_termination.hpp
Go to the documentation of this file.
1
22
#ifndef _MLPACK_METHODS_AMF_SIMPLERESIDUETERMINATION_HPP_INCLUDED
23
#define _MLPACK_METHODS_AMF_SIMPLERESIDUETERMINATION_HPP_INCLUDED
24
25
#include <
mlpack/core.hpp
>
26
27
namespace
mlpack {
28
namespace
amf {
29
41
class
SimpleResidueTermination
42
{
43
public
:
52
SimpleResidueTermination
(
const
double
minResidue
= 1e-10,
53
const
size_t
maxIterations
= 10000)
54
:
minResidue
(
minResidue
),
maxIterations
(
maxIterations
) { }
55
61
template
<
typename
MatType>
62
void
Initialize
(
const
MatType& V)
63
{
64
// Initialize the things we keep track of.
65
residue
= DBL_MAX;
66
iteration
= 1;
67
nm
= V.n_rows * V.n_cols;
68
// Remove history.
69
normOld
= 0;
70
}
71
78
bool
IsConverged
(arma::mat& W, arma::mat& H)
79
{
80
// Calculate the norm and compute the residue
81
const
double
norm = arma::norm(W * H,
"fro"
);
82
residue
= fabs(
normOld
- norm) /
normOld
;
83
84
// Store the norm.
85
normOld
= norm;
86
87
// Increment iteration count
88
iteration
++;
89
90
// Check if termination criterion is met.
91
return
(residue < minResidue || iteration >
maxIterations
);
92
}
93
95
const
double
&
Index
()
const
{
return
residue
; }
96
98
const
size_t
&
Iteration
()
const
{
return
iteration
; }
99
101
const
size_t
&
MaxIterations
()
const
{
return
maxIterations
; }
102
size_t
&
MaxIterations
() {
return
maxIterations
; }
103
105
const
double
&
MinResidue
()
const
{
return
minResidue
; }
106
double
&
MinResidue
() {
return
minResidue
; }
107
108
public
:
110
double
minResidue
;
112
size_t
maxIterations
;
113
115
double
residue
;
117
size_t
iteration
;
119
double
normOld
;
120
121
size_t
nm
;
122
};
// class SimpleResidueTermination
123
124
};
// namespace amf
125
};
// namespace mlpack
126
127
128
#endif // _MLPACK_METHODS_AMF_SIMPLERESIDUETERMINATION_HPP_INCLUDED
Generated by
1.8.3.1