Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

types

Testing NMF Objects


Description

The functions documented here tests different characteristics of NMF objects.

is.nmf tests if an object is an NMF model or a class that extends the class NMF.

hasBasis tests whether an objects contains a basis matrix – returned by a suitable method basis – with at least one row.

hasBasis tests whether an objects contains a coefficient matrix – returned by a suitable method coef – with at least one column.

is.partial.nmf tests whether an NMF model object contains either an empty basis or coefficient matrix. It is a shorcut for !hasCoef(x) || !hasBasis(x).

Usage

is.nmf(x)

  is.empty.nmf(x, ...)

  hasBasis(x)

  hasCoef(x)

  is.partial.nmf(x)

  isNMFfit(object, recursive = TRUE)

Arguments

x

an R object. See section Details, for how each function uses this argument.

...

extra parameters to allow extension or passed to subsequent calls

object

any R object.

recursive

if TRUE and object is a plain list then isNMFfit tests each element of the list. Note that the recursive test only applies in the case of lists that are not themselves NMFfit objects, like NMFfitXn objects for which the result of isNMFfit will always be TRUE, although they are list objects (a single logical value).

Details

is.nmf tests if object is the name of a class (if a character string), or inherits from a class, that extends NMF.

is.empty.nmf returns TRUE if the basis and coefficient matrices of x have respectively zero rows and zero columns. It returns FALSE otherwise.

In particular, this means that an empty model can still have a non-zero number of basis components, i.e. a factorization rank that is not null. This happens, for example, in the case of NMF models created calling the factory method nmfModel with a value only for the factorization rank.

isNMFfit checks if object inherits from class NMFfit or NMFfitX, which are the two types of objects returned by the function nmf. If object is a plain list and recursive=TRUE, then the test is performed on each element of the list, and the return value is a logical vector (or a list if object is a list of list) of the same length as object.

Value

isNMFfit returns a logical vector (or a list if object is a list of list) of the same length as object.

Note

The function is.nmf does some extra work with the namespace as this function needs to return correct results even when called in .onLoad. See discussion on r-devel: https://stat.ethz.ch/pipermail/r-devel/2011-June/061357.html

See Also

Examples

#----------
# is.nmf
#----------
# test if an object is an NMF model, i.e. that it implements the NMF interface
is.nmf(1:4)
is.nmf( nmfModel(3) )
is.nmf( nmf(rmatrix(10, 5), 2) )

#----------
# is.empty.nmf
#----------
# empty model
is.empty.nmf( nmfModel(3) )
# non empty models
is.empty.nmf( nmfModel(3, 10, 0) )
is.empty.nmf( rnmf(3, 10, 5) )

#----------
# isNMFfit
#----------
## Testing results of fits
# generate a random
V <- rmatrix(20, 10)

# single run -- using very low value for maxIter to speed up the example
res <- nmf(V, 3, maxIter=3L)
isNMFfit(res)

# multiple runs - keeping single fit
resm <- nmf(V, 3, nrun=2, maxIter=3L)
isNMFfit(resm)

# with a list of results
isNMFfit(list(res, resm, 'not a result'))
isNMFfit(list(res, resm, 'not a result'), recursive=FALSE)

NMF

Algorithms and Framework for Nonnegative Matrix Factorization (NMF)

v0.23.0
GPL (>= 2)
Authors
Renaud Gaujoux, Cathal Seoighe
Initial release
2020-07-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.