Skip to content

Commit

Permalink
add reordering plot to slides
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias-Brock committed Nov 3, 2023
1 parent 6f08120 commit 9e44eee
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 39 additions & 6 deletions slides/information-theory/rsrc/make_entropy_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,45 @@ library(gridExtra)

# DATA -------------------------------------------------------------------------

p1 <- c(0.2, 0.2, 0.2, 0.2, 0.2)
p2 <- c(0.1, 0.2, 0.4, 0.2, 0.1)
p3 <- c(0.4, 0.2, 0.2, 0.1, 0.1)
p4 <- c(0.1, 0.1, 0.6, 0.1, 0.1)
p1 <- c(0.0, 0.0, 1, 0, 0)
p2 <- c(0, 0.1, 0.8, 0.1, 0)
p3 <- c(0.1, 0.1, 0.6, 0.1, 0.1)
p4 <- c(0.15, 0.15, 0.4, 0.15, 0.15)
p5 <- c(0.175, 0.175, 0.3, 0.175, 0.175)
p6 <- c(0.2, 0.2, 0.2, 0.2, 0.2)

# PLOTS ------------------------------------------------------------------------
# ENTROPY MAXIMAL FOR UNIFORM DISTRIBUTION PLOTS ------------------------------------------------------------------------

plot_ent <- function(p) {
n <- length(p)
lp <- -log(p)
lp <- ifelse(p == 0, 0, lp)
r <- p * lp
H <- sum(r)
dd <- data.frame(x = 1:n, p = p, lp = lp, r = r)
pl <- ggplot(data = dd, aes(x = x)) +
geom_bar(aes(y = p), stat = "identity") +
ggtitle(sprintf("Entropy H(p) = %.1f", H)
)
return(pl)
}


plot_list = lapply(list(p1, p2, p3, p4, p5, p6), plot_ent)

for (i in 1:length(plot_list)){
ggsave(paste0(".../figure/max_entropy_", i, ".pdf"), plot_list[[i]], width = 6.5, height = 5)
}


# DATA -------------------------------------------------------------------------

p1 <- c(0.4, 0.2, 0.2, 0.1, 0.1)
p2 <- c(0.2, 0.4, 0.2, 0.1, 0.1)
p3 <- c(0.1, 0.2, 0.4, 0.2, 0.1)
p4 <- c(0.1, 0.1, 0.2, 0.4, 0.2)

# ENTROPY INVARIANT TO REORDERING PLOTS ------------------------------------------------------------------------

plot_ent <- function(p) {
n <- length(p)
Expand All @@ -30,4 +63,4 @@ plot_ent <- function(p) {
}

p <- grid.arrange(grobs = lapply(list(p1, p2, p3, p4), plot_ent), nrow = 2, ncol = 2)
ggsave(filename = "../figure/entropy_plot.png", plot = p, width = 5, height = 3)
ggsave(filename = ".../figure/entropy_plot_reordering.png", plot = p, width = 5, height = 3)
9 changes: 6 additions & 3 deletions slides/information-theory/slides-info-entropy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@
\end{vbframe}


\begin{vbframe}{Entropy Examples}
\begin{vbframe}{Entropy Re-Ordering}

\begin{center}
\includegraphics[width = 8cm ]{figure/entropy_plot.png} \\
\includegraphics[width = 10cm ]{figure/entropy_plot_reordering.png} \\
\end{center}

Naive observations: Uniform seems maximal, re-ordering does not matter, and the more peaked, the less entropy.
\begin{itemize}
\item Naive observation: Re-ordering does not matter.
\end{itemize}

\end{vbframe}

\begin{vbframe}{Entropy of Bernoulli distribution}
Expand Down

0 comments on commit 9e44eee

Please sign in to comment.