perplexity_calc | R Documentation |
Calculates the perplexity of a vector of (log-)probabilities.
perplexity_calc(x, na.rm = FALSE, log.p = TRUE)
x |
A vector of log-probabilities. |
na.rm |
Should missing values (including NaN) be removed? |
log.p |
If TRUE (default), x are assumed to be log-transformed probabilities with base e, if FALSE x are assumed to be raw probabilities, alternatively log.p can be the base of other logarithmic transformations. |
If x are raw probabilities (NOT the default), then perplexity is calculated as follows:
\left(\prod_{n} x_n \right)^\frac{1}{N}
The perplexity.
probs <- c(.3, .5, .6)
perplexity_calc(probs, log.p = FALSE)
lprobs <- log(probs)
perplexity_calc(lprobs, log.p = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.