Skip to content

Instantly share code, notes, and snippets.

@gweissman
Last active February 12, 2020 00:59
Show Gist options
  • Save gweissman/1c977a4cf57c7118887a4c6d1a699ca7 to your computer and use it in GitHub Desktop.
Save gweissman/1c977a4cf57c7118887a4c6d1a699ca7 to your computer and use it in GitHub Desktop.
Calculate the entropy of a set of predictions and estimate 95% confidence intervals.
# Libraries
library(gmish) # devtools::install_github('gweissman/gmish')
# Size
N <- 1000
# Softmax helper function
sm <- function(x) exp(x)/sum(exp(x))
# Make some predictions
preds <- data.frame(runif(N), runif(N), runif(N))
preds_sm <- t(apply(preds, 1, sm))
# Calculate entropy
ent(preds_sm)
# Get bias-corrected, accelerated bootstrap confidence intervals
bs_ci(preds_sm, metric = ent, btype = 'bca')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment