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