Title: | Hierarchical Non-Negative Matrix Factorization |
---|---|
Description: | Hierarchical and single-level non-negative matrix factorization. Several NMF algorithms are available. |
Authors: | Nicolas Sauwen |
Maintainer: | Nicolas Sauwen <[email protected]> |
License: | GPL-3 |
Version: | 1.0 |
Built: | 2025-02-22 03:55:36 UTC |
Source: | https://github.com/cran/hNMF |
Accelerated hierarchical alternating least squares NMF. For a reference to the method, see N. Gillis, Nonnegative matrix factorization: complexity, algorithms and applications [Section 4.2, Algo. 6], PhD thesis, Université catholique de Louvain, February 2011.
HALSacc(X, nmfMod, alpha = 1, maxiter = 1000, checkDivergence = FALSE)
HALSacc(X, nmfMod, alpha = 1, maxiter = 1000, checkDivergence = FALSE)
X |
Input data matrix, each column represents one observation and the rows correspond to the different features |
nmfMod |
Valid NMF model, containing initialized factor matrices (in accordance with the NMF package definition) |
alpha |
Nonnegative parameter of the accelerated method |
maxiter |
Maximum number of iterations |
checkDivergence |
currently not in use, to be implemented |
Resulting NMF model (in accordance with the NMF package definition)
nsauwen
Hierarchical non-negative matrix factorization.
hNMF(nmfInput, nmfMethod = "HALSacc")
hNMF(nmfInput, nmfMethod = "HALSacc")
nmfInput |
List with NMF input attributes |
nmfMethod |
String referring to the NMF algorithm to be used. |
Resulting NMF model (in accordance with NMF package definition)
Nicolas Sauwen
# create nmfInput object X <- matrix(runif(10*20), 10,20) bgImageTensor <- array(0,dim=dim(X)) selectVect <- array(1,dim=dim(X)) nmfInput <- NULL nmfInput$numRows <- nrow(X) nmfInput$numCols <- ncol(X) nmfInput$numSlices <- 1 nmfInput$bgImageTensor <- bgImageTensor nmfInput$selectVect <- selectVect # run NMF with default algorithm, 5 runs with random initialization NMFresult1 <- oneLevelNMF(X, rank=2, nruns=5) # run NMF with specified algorithm and with initialized sources W0 <- initializeSPA(X,3) NMFresult2 <- oneLevelNMF(X, rank=3, method="HALSacc", initData = W0)
# create nmfInput object X <- matrix(runif(10*20), 10,20) bgImageTensor <- array(0,dim=dim(X)) selectVect <- array(1,dim=dim(X)) nmfInput <- NULL nmfInput$numRows <- nrow(X) nmfInput$numCols <- ncol(X) nmfInput$numSlices <- 1 nmfInput$bgImageTensor <- bgImageTensor nmfInput$selectVect <- selectVect # run NMF with default algorithm, 5 runs with random initialization NMFresult1 <- oneLevelNMF(X, rank=2, nruns=5) # run NMF with specified algorithm and with initialized sources W0 <- initializeSPA(X,3) NMFresult2 <- oneLevelNMF(X, rank=3, method="HALSacc", initData = W0)
Overlay a mask or a color scaled image on top of a background image
imoverlay(image, overlay, selectVect = NULL, color = c(0, 1, 0))
imoverlay(image, overlay, selectVect = NULL, color = c(0, 1, 0))
image |
A matrix, background image |
overlay |
A matrix, serving as the overlay mask or figure |
selectVect |
A matrix (binary values), specifying which matrix elements are to be overlaid |
color |
3-element vector, defining the RGB color to be used in case the overlay is a mask |
Nicolas Sauwen
Initialize NMF model with initial spectral data
initializeNMF(X, initData = NULL)
initializeNMF(X, initData = NULL)
X |
input matrix |
initData |
source or abundance matrix with initial values |
The successive projection algorithm, a useful method for initializing the NMF source matrix
initializeSPA(data, nSources)
initializeSPA(data, nSources)
data |
Input data matrix. The columns correspond to the data points, each row represents one feature |
nSources |
Number of sources to be obtained |
Matrix with initialized sources as its columns
Nicolas Sauwen
# random data X <- matrix(runif(10*20), 10,20) # Create initial source matrix for 3 sources W0 <- initializeSPA(X,3)
# random data X <- matrix(runif(10*20), 10,20) # Create initial source matrix for 3 sources W0 <- initializeSPA(X,3)
Perform Non-Negative Matrix factorization
oneLevelNMF(X, rank, initData = NULL, method = "PGNMF", nruns = 10, checkDivergence = TRUE)
oneLevelNMF(X, rank, initData = NULL, method = "PGNMF", nruns = 10, checkDivergence = TRUE)
X |
input matrix. Each column represents one observation and the rows correspond to the different features |
rank |
number of NMF components to be found |
initData |
either of the NMF factor matrices, with initial values |
method |
name of the NMF method to be used. "PGNMF" (default) and "HALSacc" are available by default. Any method from the NMF package can also be specified |
nruns |
number of NMF runs. It is recommended to run the NMF analyses multiple times when random seeding is used, to avoid a suboptimal solution |
checkDivergence |
Boolean indicating whether divergence checking should be performed |
Scaled NMF model (in accordance with the NMF package definition)
Nicolas Sauwen
# random data X <- matrix(runif(10*20), 10,20) # run NMF with default algorithm, 5 runs with random initialization NMFresult1 <- oneLevelNMF(X, rank=2, nruns=5) # run NMF with specified algorithm and with initialized sources W0 <- initializeSPA(X,3) NMFresult2 <- oneLevelNMF(X, rank=3, method="HALSacc", initData = W0)
# random data X <- matrix(runif(10*20), 10,20) # run NMF with default algorithm, 5 runs with random initialization NMFresult1 <- oneLevelNMF(X, rank=2, nruns=5) # run NMF with specified algorithm and with initialized sources W0 <- initializeSPA(X,3) NMFresult2 <- oneLevelNMF(X, rank=3, method="HALSacc", initData = W0)
NMF by alternating non-negative least squares using projected gradients. For a reference to the method, see C.-J. Lin, "Projected Gradient Methods for Non-negative Matrix Factorization", Neural computation 19.10 (2007): 2756-2779.
PGNMF(X, nmfMod, tol = 1e-05, maxIter = 500, timeLimit = 300, checkDivergence = TRUE)
PGNMF(X, nmfMod, tol = 1e-05, maxIter = 500, timeLimit = 300, checkDivergence = TRUE)
X |
Input data matrix, each column represents one data point and the rows correspond to the different features |
nmfMod |
Valid NMF model, containing initialized factor matrices (in accordance with the NMF package definition) |
tol |
Tolerance for a relative stopping condition |
maxIter |
Maximum number of iterations |
timeLimit |
Limit of time duration NMF analysis |
checkDivergence |
Boolean indicating whether divergence checking should be performed Default is TRUE, but it should be set to FALSE when using random initialization |
Resulting NMF model (in accordance with the NMF package definition)
nsauwen
Condition input data matrix properly for NMF
preProcesInputData(X)
preProcesInputData(X)
X |
input matrix |
matrix with non-zero elements
Computation of relative NMF residual per observation
residualNMF(X, nmfFit)
residualNMF(X, nmfFit)
X |
Input data matrix, each column represents one observation |
nmfFit |
NMF model fitted to the input data in X |
Relative residual per observation, returned as a vector
nsauwen
Apply fixed scaling to NMF model matrices by normalizing the basis vectors
scaleNMFResult(NMFResult)
scaleNMFResult(NMFResult)
NMFResult |
Fitted NMF model |
NMFResult Rescaled NMF model
Nicolas Sauwen
Semi-NMF based on multiplicative update rules. Reference: C. Ding, T. Li, and M.I. Jordan, "Convex and semi-nonnegative matrix factorizations", IEEE Transations on Pattern Analysis and Machine Intelligence, vol. 32, no. 1, pp. 45-55, 2010.
semiNMF(X, nmfMod, maxiter = 2000, checkDivergence = FALSE)
semiNMF(X, nmfMod, maxiter = 2000, checkDivergence = FALSE)
X |
Input data matrix, each column represents one observation and the rows correspond to the different features |
nmfMod |
Valid NMF model, containing initialized factor matrices (in accordance with the NMF package definition) |
maxiter |
Maximum number of iterations |
checkDivergence |
currently not in use, to be implemented |
Resulting NMF model (in accordance with the NMF package definition)
nsauwen