Last active
September 28, 2018 01:00
-
-
Save ericnovik/7facfc1f58e6cdc1cce8f96ea7ffde2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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