ent: Calculate the mean Shannon entropy for the predicted...

View source: R/ent.R

entR Documentation

Calculate the mean Shannon entropy for the predicted probabilities over an arbitrary set of classes. NB. This is *not* the cross-entropy.

Description

Calculate the mean Shannon entropy for the predicted probabilities over an arbitrary set of classes. NB. This is *not* the cross-entropy.

Usage

ent(preds)

Arguments

preds

A vector, matrix, or data frame of predicted probabilities. Each column should contain probabilities for a unique class.

Value

The mean entropy over all predictions given by

E = \frac{1}{N} \sum -\sum (p log(p))

Examples

# Generate some predictions
predictions <- runif(1000)
# Calculate the mean entropy
ent(predictions)
# Now try with a few classes
p2 <- data.frame(runif(1000), runif(1000), runif(1000))
sm <- function(v) exp(v) / sum(exp(v))
p2_sm <- t(apply(p2, 1, function(r) sm(r)))
ent(p2_sm)

gweissman/gmish documentation built on Sept. 3, 2024, 11:39 p.m.