loglik_poisson_nmf {fastTopics} | R Documentation |
NMF and Topic Model Likelihoods and Deviances
Description
Compute log-likelihoods and deviances for assessing fit of a topic model or a non-negative matrix factorization (NMF).
Usage
loglik_poisson_nmf(X, fit, e = 1e-08)
loglik_multinom_topic_model(X, fit, e = 1e-08)
deviance_poisson_nmf(X, fit, e = 1e-08)
cost(X, A, B, e = 1e-08, family = c("poisson", "multinom"), version)
Arguments
X |
The n x m matrix of counts or pseudocounts. It can be a
sparse matrix (class |
fit |
A Poisson NMF or multinomial topic model fit, such as an
output from |
e |
A small, non-negative number added to the terms inside the logarithms to avoid computing logarithms of zero. This prevents numerical problems at the cost of introducing a very small inaccuracy in the computation. |
A |
The n x k matrix of loadings. It should be a dense matrix. |
B |
The k x m matrix of factors. It should be a dense matrix. |
family |
If |
version |
When |
Details
Function cost
computes loss functions proportional
to the negative log-likelihoods, and is mainly for internal use to
quickly compute log-likelihoods and deviances; it should not be
used directly unless you know what you are doing. In particular,
little argument checking is performed by cost
.
Value
A numeric vector with one entry per row of X
.
Examples
# Generate a small counts matrix.
set.seed(1)
out <- simulate_count_data(10,20,3)
X <- out$X
fit <- out[c("F","L")]
class(fit) <- c("poisson_nmf_fit","list")
# Compute the Poisson log-likelihoods and deviances.
data.frame(loglik = loglik_poisson_nmf(X,fit),
deviance = deviance_poisson_nmf(X,fit))
# Compute multinomial log-likelihoods.
loglik_multinom_topic_model(X,fit)