Skip to content

Instantly share code, notes, and snippets.

@ericnovik
Last active September 28, 2018 01:00
Show Gist options
  • Save ericnovik/7facfc1f58e6cdc1cce8f96ea7ffde2c to your computer and use it in GitHub Desktop.
Save ericnovik/7facfc1f58e6cdc1cce8f96ea7ffde2c to your computer and use it in GitHub Desktop.
library(ggplot2)
entropy <- function(p) -sum(p * log(p))
n <- 1e3
p <- runif(n)
q <- 1 - p
z <- matrix(c(p, q), ncol = 2)
ent <- apply(z, 1, entropy)
qplot(q, ent, geom = "line") +
ylab("Entropy") + xlab("Probability") +
ggtitle("Entropy For Two Events")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment