MLPACK
1.0.8
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
mlpack
methods
nmf
random_acol_init.hpp
Go to the documentation of this file.
1
26
#ifndef __MLPACK_METHODS_NMF_RANDOM_ACOL_INIT_HPP
27
#define __MLPACK_METHODS_NMF_RANDOM_ACOL_INIT_HPP
28
29
#include <
mlpack/core.hpp
>
30
31
namespace
mlpack {
32
namespace
nmf {
33
41
template
<
int
p = 5>
42
class
RandomAcolInitialization
43
{
44
public
:
45
// Empty constructor required for the InitializeRule template
46
RandomAcolInitialization
()
47
{ }
48
49
template
<
typename
MatType>
50
inline
static
void
Initialize
(
const
MatType& V,
51
const
size_t
r,
52
arma::mat& W,
53
arma::mat& H)
54
{
55
const
size_t
n = V.n_rows;
56
const
size_t
m = V.n_cols;
57
58
if
(p > m)
59
{
60
Log::Warn
<<
"Number of random columns is more than the number of columns"
61
<<
"available in the V matrix; weird results may ensue!"
<< std::endl;
62
}
63
64
W.zeros(n, r);
65
66
// Initialize W matrix with random columns.
67
for
(
size_t
col = 0; col < r; col++)
68
{
69
for
(
size_t
randCol = 0; randCol < p; randCol++)
70
{
71
// .col() does not work in this case, as of Armadillo 3.920.
72
W.unsafe_col(col) += V.col(
math::RandInt
(0, m));
73
}
74
}
75
76
// Now divide by p.
77
W /= p;
78
79
// Initialize H to random values.
80
H.randu(r, m);
81
}
82
};
// Class RandomAcolInitialization
83
84
};
// namespace nmf
85
};
// namespace mlpack
86
87
#endif
Generated by
1.8.3.1