MLPACK
1.0.7
|
This class implements the NMF on the given matrix V. More...
Public Member Functions | |
NMF (const size_t maxIterations=10000, const double minResidue=1e-10, const InitializationRule initializeRule=InitializationRule(), const WUpdateRule wUpdate=WUpdateRule(), const HUpdateRule hUpdate=HUpdateRule()) | |
Create the NMF object and (optionally) set the parameters which NMF will run with. More... | |
template<typename MatType > | |
void | Apply (const MatType &V, const size_t r, arma::mat &W, arma::mat &H) const |
Apply Non-Negative Matrix Factorization to the provided matrix. More... | |
const HUpdateRule & | HUpdate () const |
Access the H update rule. More... | |
HUpdateRule & | HUpdate () |
Modify the H update rule. More... | |
const InitializationRule & | InitializeRule () const |
Access the initialization rule. More... | |
InitializationRule & | InitializeRule () |
Modify the initialization rule. More... | |
size_t | MaxIterations () const |
Access the maximum number of iterations. More... | |
size_t & | MaxIterations () |
Modify the maximum number of iterations. More... | |
double | MinResidue () const |
Access the minimum residue before termination. More... | |
double & | MinResidue () |
Modify the minimum residue before termination. More... | |
const WUpdateRule & | WUpdate () const |
Access the W update rule. More... | |
WUpdateRule & | WUpdate () |
Modify the W update rule. More... | |
Private Attributes | |
HUpdateRule | hUpdate |
Instantiated H update rule. More... | |
InitializationRule | initializeRule |
Instantiated initialization Rule. More... | |
size_t | maxIterations |
The maximum number of iterations allowed before giving up. More... | |
double | minResidue |
The minimum residue, below which iteration is considered converged. More... | |
WUpdateRule | wUpdate |
Instantiated W update rule. More... | |
This class implements the NMF on the given matrix V.
Non-negative Matrix Factorization decomposes V in the form where W is called the basis matrix and H is called the encoding matrix. V is taken to be of size n x m and the obtained W is n x r and H is r x m. The size r is called the rank of the factorization.
The implementation requires two template types; the first contains the update rule for the W matrix during each iteration and the other contains the update rule for the H matrix during each iteration. This templatization allows the user to try various update rules (including ones not supplied with MLPACK) for factorization.
A simple example of how to run NMF is shown below.
For more information on non-negative matrix factorization, see the following paper:
WUpdateRule | The update rule for calculating W matrix at each iteration. |
HUpdateRule | The update rule for calculating H matrix at each iteration. |
mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::NMF | ( | const size_t | maxIterations = 10000 , |
const double | minResidue = 1e-10 , |
||
const InitializationRule | initializeRule = InitializationRule() , |
||
const WUpdateRule | wUpdate = WUpdateRule() , |
||
const HUpdateRule | hUpdate = HUpdateRule() |
||
) |
Create the NMF object and (optionally) set the parameters which NMF will run with.
The minimum residue refers to the root mean square of the difference between two subsequent iterations of the product W * H. A low residue indicates that subsequent iterations are not producing much change in W and H. Once the residue goes below the specified minimum residue, the algorithm terminates.
maxIterations | Maximum number of iterations allowed before giving up. A value of 0 indicates no limit. |
minResidue | The minimum allowed residue before the algorithm terminates. |
Initialize | Optional Initialization object for initializing the W and H matrices |
WUpdate | Optional WUpdateRule object; for when the update rule for the W vector has states that it needs to store. |
HUpdate | Optional HUpdateRule object; for when the update rule for the H vector has states that it needs to store. |
void mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::Apply | ( | const MatType & | V, |
const size_t | r, | ||
arma::mat & | W, | ||
arma::mat & | H | ||
) | const |
Apply Non-Negative Matrix Factorization to the provided matrix.
V | Input matrix to be factorized. |
W | Basis matrix to be output. |
H | Encoding matrix to output. |
r | Rank r of the factorization. |
|
inline |
Access the H update rule.
Definition at line 158 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::hUpdate.
|
inline |
Modify the H update rule.
Definition at line 160 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::hUpdate.
|
inline |
Access the initialization rule.
Definition at line 150 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::initializeRule.
|
inline |
Modify the initialization rule.
Definition at line 152 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::initializeRule.
|
inline |
Access the maximum number of iterations.
Definition at line 142 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::maxIterations.
|
inline |
Modify the maximum number of iterations.
Definition at line 144 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::maxIterations.
|
inline |
Access the minimum residue before termination.
Definition at line 146 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::minResidue.
|
inline |
Modify the minimum residue before termination.
Definition at line 148 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::minResidue.
|
inline |
Access the W update rule.
Definition at line 154 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::wUpdate.
|
inline |
Modify the W update rule.
Definition at line 156 of file nmf.hpp.
References mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::wUpdate.
|
private |
Instantiated H update rule.
Definition at line 138 of file nmf.hpp.
Referenced by mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::HUpdate().
|
private |
Instantiated initialization Rule.
Definition at line 134 of file nmf.hpp.
Referenced by mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::InitializeRule().
|
private |
The maximum number of iterations allowed before giving up.
Definition at line 130 of file nmf.hpp.
Referenced by mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::MaxIterations().
|
private |
The minimum residue, below which iteration is considered converged.
Definition at line 132 of file nmf.hpp.
Referenced by mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::MinResidue().
|
private |
Instantiated W update rule.
Definition at line 136 of file nmf.hpp.
Referenced by mlpack::nmf::NMF< InitializationRule, WUpdateRule, HUpdateRule >::WUpdate().