Computes the nonnegative matrix factorization of a data matrix X
using the factorization parameter r
.
Multiple algorithms and initialization methods are implemented in the nmfgpu library using CUDA hardware acceleration.
Depending on the available hardware, these algorithms should outperform traditional CPU implementations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  nmf(...)
## Default S3 method:
nmf(data, r, algorithm = "mu",
initMethod = "AllRandomValues", seed = floor(runif(1, 0,
.Machine$integer.max)), threshold = 0.1, maxiter = 2000, runs = 1,
parameters = NULL, useSinglePrecision = F, verbose = T, ssnmf = F,
...)
## S3 method for class 'formula'
nmf(formula, data, ...)
## S3 method for class 'nmfgpu'
fitted(object, ...)
## S3 method for class 'nmfgpu'
predict(object, newdata, ...)

... 
Other arguments 
data 
Data matrix of dimension n x m with n attributes and m observations. Please note that this differs from most other data mining/machine learning algorithms! 
r 
Factorization parameter, which affects the quality of the approximation and runtime. 
algorithm 
Choosing the right algorithm depends on the data structure. Currently the following algorithms are implemented in the nmfgpu library:

initMethod 
All initialization methods depend on the selected algorithm. Using the fact that a least squares type
algorithm computes the matrix

seed 
The 
threshold 
First convergence criterion: The 
maxiter 
Second convergence criterion: If the first convergence criterion is not reached, but a maximum number of iterations, the execution of the algorithm will be aborted. 
runs 
Performs the specified amount of runs and stores the best factorization result. 
parameters 
A list of additional parameters, which are required by some 
useSinglePrecision 
By default R only knows about double precision numerical data types. If this parameter is set to true, then the algorithm will convert the double precision data to single precision for computation. The result will be converted back to double precision data. 
verbose 
By default information about the factorization process and current status will be written to the console. For silent execution 
ssnmf 
Internal flag (Don't use it) 
formula 
Formula object with no intercept and labels for selected attributes. Note that die labels are selected from the rows instead of the columns, because NMF expects rows to be attributes. 
object 
Object of class " 
newdata 
New data matrix compatible to the training data matrix, for computing the corresponding mixing matrix. 
If the factorization process was successful, then a list of the following values will be returned otherwise NULL:
W  Factorized matrix W with n attributes and r basis features of the data matrix. 
H  Factorized matrix H with r mixing vectors for m data entries in the data matrix. 
Frobenius  Contains the frobenius norm of the factorization at the end of algorithm execution. 
RMSD  Contains the rootmeansquare deviation (RMSD) of the factorization at the end of algorithm execution. 
ElapsedTime  Contains the elapsed time for initialization and algorithm execution. 
NumIterations  Number of iterations until the algorithm had converged. 
P. Paatero and U. Tapper, "Positive matrix factorization: A nonnegative factor model with optimal utilization of error estimates of data values", Environmetrics, vol. 5, no. 2, pp. 111126, 1994.
D. D. Lee and H. S. Seung, "Algorithms for nonnegative matrix factorization", in Advances in Neural Information Processing Systems 13 (T. Leen, T. Dietterich, and V. Tresp, eds.), pp. 556562, MIT Press, 2001.
V. P. Pauca, J. Piper, and R. J. Plemmons, "Nonnegative matrix factorization for spectral data analysis", Linear Algebra and its Applications, vol. 416, no. 1, pp. 2947, 2006. Special Issue devoted to the Haifa 2005 conference on matrix theory.
A. N. Langville, C. D. Meyer, R. Albright, J. Cox, and D. Duling, "Algorithms, initializations, and convergence for the nonnegative matrix factorization", CoRR, vol. abs/1407.7299, 2014.
L. Gong and A. Nandi, "An enhanced initialization method for nonnegative matrix factorization", in 2013 IEEE International Workshop on Machine Learning for Signal Processing (MLSP), pp. 16, Sept 2013.
A. PascualMontano, J. M. Carazo, K. Kochi, D. Lehmann and R. D. PascualMarqui "Nonsmooth nonnegative matrix factorization (nsNMF)", in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 28, pp. 403415, 2006
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35  ## Not run:
# Initialize the library
library(nmfgpu4R)
nmfgpu4R.init()
# Create dummy data
data < runif(256*1024)
dim(data) < c(256, 1024)
# Compute several factorization models
result < nmf(data, 128, algorithm="mu", initMethod="KMeans/Random", maxiter=500)
result < nmf(data, 128, algorithm="mu", initMethod="CopyExisting",
parameters=list(W=result$W, H=result$H), maxiter=500)
result < nmf(data, 128, algorithm="gdcls", maxiter=500, parameters=list(lambda=0.1))
result < nmf(data, 128, algorithm="als", maxiter=500)
result < nmf(data, 128, algorithm="acls", maxiter=500,
parameters=list(lambdaH=0.1, lambdaW=0.1))
result < nmf(data, 128, algorithm="ahcls", maxiter=500,
parameters=list(lambdaH=0.1, lambdaW=0.1, alphaH=0.5, alphaW=0.5))
result < nmf(data, 128, algorithm="nsnmf", maxiter=500, parameters=list(theta=0.25))
# Compute encoding matrices for training and test data
set.seed(42)
idx < sample(1:nrow(iris), 100, replace=F)
data.train < iris[idx,]
data.test < iris[idx,]
model.nmf < nmf(t(data.train[,5]), 2)
encoding.train < t(predict(model.nmf))
encoding.test < t(predict(model.nmf, t(data.test[,5])))
plot(encoding.train, col=data.train[,5], pch=1)
points(encoding.test, col=data.test[,5], pch=4)
## End(Not run)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.