NMF (version 0.21.0)

is.nmf: 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).

Value

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

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.

See Also

'>NMFfit, '>NMFfitX, '>NMFfitXn

Examples

Run this code
# NOT RUN {
#----------
# is.nmf
#----------
# test if an object is an NMF model, i.e. that it implements the NMF interface
is.nmf(1:4)
is.nmf('NMFstd')
is.nmf('NMFblah')
is.nmf( nmfModel(3) )
is.nmf( nmf(rmatrix(20,10), 3) )

#----------
# 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=3, 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)
# }

Run the code above in your browser using DataCamp Workspace