mlpack
3.1.1
src
mlpack
methods
amf
init_rules
average_init.hpp
Go to the documentation of this file.
1
12
#ifndef MLPACK_METHODS_AMF_AVERAGE_INIT_HPP
13
#define MLPACK_METHODS_AMF_AVERAGE_INIT_HPP
14
15
#include <
mlpack/prereqs.hpp
>
16
17
namespace
mlpack
{
18
namespace
amf {
19
27
class
AverageInitialization
28
{
29
public
:
30
// Empty constructor required for the InitializeRule template
31
AverageInitialization
() { }
32
42
template
<
typename
MatType>
43
inline
static
void
Initialize
(
const
MatType& V,
44
const
size_t
r,
45
arma::mat& W,
46
arma::mat& H)
47
{
48
const
size_t
n = V.n_rows;
49
const
size_t
m = V.n_cols;
50
51
double
avgV = 0;
52
size_t
count = 0;
53
double
min = DBL_MAX;
54
55
// Iterate over all elements in the matrix (for sparse matrices, this only
56
// iterates over nonzeros).
57
for
(
typename
MatType::const_row_col_iterator it = V.begin();
58
it != V.end(); ++it)
59
{
60
++count;
61
avgV += *it;
62
// Track the minimum value.
63
if
(*it < min)
64
min = *it;
65
}
66
67
avgV = sqrt(((avgV / (n * m)) - min) / r);
68
69
// Initialize to random values.
70
W.randu(n, r);
71
H.randu(r, m);
72
73
W = W + avgV;
74
H = H + avgV;
75
}
76
78
template
<
typename
Archive>
79
void
serialize
(Archive&
/* ar */
,
const
unsigned
int
/* version */
) { }
80
};
81
82
}
// namespace amf
83
}
// namespace mlpack
84
85
#endif
prereqs.hpp
mlpack::amf::AverageInitialization::AverageInitialization
AverageInitialization()
Definition:
average_init.hpp:31
mlpack
@serialization.hpp
Definition:
add_to_po.hpp:21
mlpack::amf::AverageInitialization::serialize
void serialize(Archive &, const unsigned int)
Serialize the object (in this case, there is nothing to do).
Definition:
average_init.hpp:79
mlpack::amf::AverageInitialization
This initialization rule initializes matrix W and H to root of the average of V, perturbed with unifo...
Definition:
average_init.hpp:27
mlpack::amf::AverageInitialization::Initialize
static void Initialize(const MatType &V, const size_t r, arma::mat &W, arma::mat &H)
Initialize the matrices W and H to the average value of V with uniform random noise added.
Definition:
average_init.hpp:43
Generated by
1.8.17