Skip to contents

\(\sum_{d,w} n(d,w) \log \sum_z P(z) P(d|z) P(w|z)\) for the aspect model of Hofmann (1999).

Usage

log_likelihood(n_dw, Pz, Pd_z, Pw_z)

Arguments

n_dw

Document-by-word count matrix.

Pz

Topic probabilities \(P(z)\).

Pd_z

Documents-by-topics matrix of \(P(d|z)\).

Pw_z

Words-by-topics matrix of \(P(w|z)\).

Value

The log-likelihood.

Examples

n_dw <- matrix(c(2, 0, 1, 3), 2)       # 2 documents x 2 words
Pz <- c(0.5, 0.5); Pd_z <- matrix(0.5, 2, 2); Pw_z <- matrix(c(0.7, 0.3, 0.2, 0.8), 2)
log_likelihood(n_dw, Pz, Pd_z, Pw_z)
#> [1] -8.317766