This tutorial explains how to use the nonnegative matrix factorization (NMF) functionality in ViennaCL.
The first step is to include the necessary headers and define the floating point type used for the computations:
The following routine fills a matrix with uniformly distributed random values from the interval [0,1]. This is used to initialize the matrices to be factored
In the main routine we set up a matrix V and compute approximate factors W and H such that , where all three matrices carry nonnegative entries only. Since W and H are usually chosen to represent a rank-k-approximation of V, we use a similar low-rank approximation here.
Approximate the 7-by-6-matrix V by a 7-by-3-matrix W and a 3-by-6-matrix H
Fill the matrices randomly. Initial guesses for W and H consisting of only zeros won't work.
Create configuration object to hold (and adjust) the respective parameters.
Call the NMF routine and print the results
Print the product W*H approximating V for comparison and exit:
Matrix Factorization