NMF-class: Generic Interface for Nonnegative Matrix Factorisation Models

Description Usage Arguments Details Value Functions Slots Implementing NMF models Creating NMF objects Methods (by generic) References See Also Examples

Description

The class NMF is a virtual class that defines a common interface to handle Nonnegative Matrix Factorization models (NMF models) in a generic way. Provided a minimum set of generic methods is implemented by concrete model classes, these benefit from a whole set of functions and utilities to perform common computations and tasks in the context of Nonnegative Matrix Factorization.

Usage

  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
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
## S4 method for signature 'NMF'
fitted(object, ...)

## S4 method for signature 'NMF'
.basis(object, ...)

## S4 replacement method for signature 'NMF,mMatrix'
.basis(object) <- value

## S4 method for signature 'NMF'
.coef(object, ...)

## S4 replacement method for signature 'NMF,mMatrix'
.coef(object) <- value

## S4 method for signature 'NMF'
scoef(object, scale = 1)

## S3 method for class 'NMF'
scale(x, center = c("basis", "coef"), scale = 1)

## S4 method for signature 'NMF'
show(object)

misc(object, ...)

## S4 method for signature 'NMF'
x$name

## S4 replacement method for signature 'NMF'
x$name <- value

## S3 method for class 'NMF'
.DollarNames(x, pattern = "")

## S4 method for signature 'NMF'
.DollarNames(x, pattern = "")

## S4 method for signature 'NMF'
rmatrix(x, ...)

## S4 method for signature 'NMF'
sparseness(x)

## S4 method for signature 'NMF,matrix'
basiscor(x, y, ...)

## S4 method for signature 'matrix,NMF'
basiscor(x, y, ...)

## S4 method for signature 'NMF,NMF'
basiscor(x, y, ...)

## S4 method for signature 'NMF,missing'
basiscor(x, y, ...)

## S4 method for signature 'NMF,matrix'
profcor(x, y, ...)

## S4 method for signature 'matrix,NMF'
profcor(x, y, ...)

## S4 method for signature 'NMF,NMF'
profcor(x, y, ...)

## S4 method for signature 'NMF,missing'
profcor(x, y, ...)

## S4 method for signature 'NMF'
connectivity(object, no.attrib = FALSE)

## S3 method for class 'NMF'
anyNA(x, recursive = FALSE)

## S3 method for class 'NMF'
t(x)

## S4 method for signature 'NMF'
c(x, ..., margin = 3L, recursive = FALSE)

## S4 method for signature 'NMF'
ibterms(object, ...)

## S4 method for signature 'NMF'
icterms(object, ...)

## S4 method for signature 'NMF,NMFfit'
nmf.equal(x, y, ...)

## S4 method for signature 'NMF'
nrun(object)

## S4 method for signature 'NMF'
consensus(object, ...)

## S4 method for signature 'NMF,NMFfitX'
nmf.equal(x, y, ...)

## S3 method for class 'NMF'
silhouette(x, what = NULL, order = NULL, ...)

Arguments

object

an object that inherit from class NMF

...

extra arguments not used.

scale

scaling coefficient applied to D, i.e. the value of alpha, or, if center='coef', the value of 1/alpha (see section Details).

x

an NMF object, as returned by nmf.

center

either a numeric normalising vector delta, or either 'basis' or 'coef', which respectively correspond to using the column sums of the basis matrix or the inverse of the row sums of the coefficient matrix as a normalising vector. If numeric, center should be a single value or a vector of length the rank of the NMF model, i.e. the number of columns in the basis matrix.

no.attrib

a logical that indicates if attributes containing information about the NMF model should be attached to the result (TRUE) or not (FALSE).

margin

integer that indicates the margin along which to concatenate (only used when ..1 is a matrix):

1L
2L
3L
4L

If missing the margin is heuristically determined by looking at common dimensions between the objects.

what

defines the type of clustering the computed silhouettes are meant to assess: 'samples' for the clustering of samples (i.e. the columns of the target matrix), 'features' for the clustering of features (i.e. the rows of the target matrix), and 'chc' for the consensus clustering of samples as defined by hierarchical clustering dendrogram, 'consensus' for the consensus clustering of samples, with clustered ordered as in the default hierarchical clustering used by consensusmap when plotting the heatmap of the consensus matrix (for multi-run NMF fits). That is dist = 1 - consensus(x), average linkage and reordering based on row means.

order

integer indexing vector that can be used to force the silhouette order.

Details

Class NMF makes it easy to develop new models that integrate well into the general framework implemented by the NMF package.

Following a few simple guidelines, new types of NMF models benefit from all the functionalities available for the built-in NMF models – that derive themselves from class NMF. See section Implementing NMF models below.

See NMFstd, and references and links therein for details on the built-in implementations of the standard NMF model and its extensions.

Value

an NMF object

Functions

Slots

misc

A list that is used internally to temporarily store algorithm parameters during the computation.

Implementing NMF models

The class NMF only defines a basic data/low-level interface for NMF models, as a collection of generic methods, responsible with data handling, upon which relies a comprehensive set of functions, composing a rich higher-level interface.

Actual NMF models are defined as sub-classes that inherits from class NMF, and implement the management of data storage, providing definitions for the interface's pure virtual methods.

The minimum requirement to define a new NMF model that integrates into the framework of the NMF package are the followings:

For concrete examples of NMF models implementations, see class NMFstd and its extensions (e.g. classes NMFOffset or NMFns).

Creating NMF objects

Strictly speaking, because class NMF is virtual, no object of class NMF can be instantiated, only objects from its sub-classes. However, those objects are sometimes shortly referred in the documentation and vignettes as "NMF objects" instead of "objects that inherits from class NMF".

For built-in models or for models that inherit from the standard model class NMFstd, the factory method nmfModel enables to easily create valid NMF objects in a variety of common situations. See documentation for the the factory method nmfModel for more details.

Methods (by generic)

.basis:

.basis<-:

.coef:

.coef<-:

[:

$:

$<-:

basis<-:

basiscor:

basismap:

c:

canFit:

coef<-:

coefficients:

coefmap:

connectivity:

consensus:

consensushc:

consensusmap:

deviance:

dim:

dimnames:

dimnames<-:

extractFeatures:

featureScore:

fit<-:

fitted:

ibterms:

icterms:

loadings:

metaHeatmap:

nmf:

nmf.equal:

nneg:

nrun:

predict:

profcor:

rmatrix:

rnmf:

rposneg:

run:

scale:

seed:

show:

silhouette:

sparseness:

summary:

t:

References

Definition of Nonnegative Matrix Factorization in its modern formulation: Lee DD, Seung HS (1999). “Learning the parts of objects by non-negative matrix factorization.” _Nature_, *401*(6755), 788-91. ISSN 0028-0836, doi: 10.1038/44565 (URL: https://doi.org/10.1038/44565).

Historical first definition and algorithms: Paatero P, Tapper U (1994). “Positive matrix factorization: A non-negative factor model with optimal utilization of error estimates of data values.” _Environmetrics_, *5*(2), 111-126. doi: 10.1002/env.3170050203 (URL: https://doi.org/10.1002/env.3170050203).

See Also

Main interface function nmf to perform NMF.

Built-in NMF models and factory method in nmfModel.

Method seed to set NMF objects with values suitable to start algorithms with.

predict

Other NMF-interface: basis(), nmfModel(), rnmf()

Other transforms: nneg()

Examples

  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
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
# show all the NMF models available (i.e. the classes that inherit from class NMF)
nmfModels()
# show all the built-in NMF models available
nmfModels(builtin.only=TRUE)

# class NMF is a virtual class so cannot be instantiated: 
try( new('NMF') )

# To instantiate an NMF model, use the factory method nmfModel. see ?nmfModel
nmfModel()
nmfModel(3)
nmfModel(3, model='NMFns')


# random 3-rank 10x5 NMF model
x <- rnmf(3, 10, 5)

# rescale based on basis
colSums(basis(x))
colSums(basis(scale(x)))

rx <- scale(x, 'basis', 10)
colSums(basis(rx))
rowSums(coef(rx))

# rescale based on coef
rowSums(coef(x))
rowSums(coef(scale(x, 'coef')))
rx <- scale(x, 'coef', 10)
rowSums(coef(rx))
colSums(basis(rx))

# fitted target matrix is identical but the factors have been rescaled
rx <- scale(x, 'basis')
all.equal(fitted(x), fitted(rx))
all.equal(basis(x), basis(rx))

# generate noisy fitted target from an NMF model (the true model)
gr <- as.numeric(mapply(rep, 1:3, 3))
h <- outer(1:3, gr, '==') + 0 
x <- rnmf(10, H=h)
y <- rmatrix(x)
## Not run: 
# show heatmap of the noisy target matrix: block patterns should be clear
aheatmap(y) 

## End(Not run)


# test NMF algorithm on noisy data
# add some noise to the true model (drawn from uniform [0,1])
res <- nmf(rmatrix(x), 3)
summary(res)

# add more noise to the true model (drawn from uniform [0,10])
res <- nmf(rmatrix(x, max=10), 3)
summary(res)


x <- rnmf(3, 100, 20)
x
# transpose
y <- t(x)
y

# factors are swapped-transposed
stopifnot( identical(basis(y), t(coef(x))) )
stopifnot( identical(coef(y), t(basis(x))) )


x <- rmatrix(100, 20, dimnames = list(paste0('a', 1:100), letters[1:20]))
# NB: using low value for maxIter for the example purpose only
res <- nmf(x, 4, nrun = 5, maxIter = 50)

# sample clustering from best fit
plot(silhouette(res))

# from consensus
plot(silhouette(res, what = 'consensus'))

# feature clustering
plot(silhouette(res, what = 'features')) 

# average silhouette are computed in summary measures
summary(res)

# consensus silhouettes are ordered as on default consensusmap heatmap
## Not run:  op <- par(mfrow = c(1,2)) 
consensusmap(res)
si <- silhouette(res, what = 'consensus')
plot(si)
## Not run:  par(op) 

# if the order is based on some custom numeric weights
## Not run:  op <- par(mfrow = c(1,2)) 
cm <- consensusmap(res, Rowv = runif(ncol(res)))
# NB: use reverse order because silhouettes are plotted top-down
si <- silhouette(res, what = 'consensus', order = rev(cm$rowInd))
plot(si)
## Not run:  par(op) 

# do the reverse: order the heatmap as a set of silhouettes
si <- silhouette(res, what = 'features')
## Not run:  op <- par(mfrow = c(1,2))  
basismap(res, Rowv = si)
plot(si)
## Not run:  par(op) 

renozao/NMF documentation built on June 14, 2020, 9:35 p.m.