Skip to content

Commit

Permalink
Move grid behind lines
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaakshat committed Nov 3, 2021
1 parent 4b206e2 commit 0c2c8ee
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ch08.r
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ L_df = data.frame(L)
colnames(L_df) = S

plot(theta, L_df$"12", type="n")
grid()
lines(theta, L_df$"12", lwd=6)
title(expression(paste("L(", theta, " | S = 12)")))
grid()

## ML estimation for single-photon imaging

Expand Down Expand Up @@ -83,20 +83,20 @@ theta = seq(0.1, 0.9, (0.1+0.9)/1000)
L = S * log(theta) + (N-S) * log(1-theta)
plot(theta, L, type="n", xlab=expression(theta), ylab=expression(paste("Log L(", theta, "|S = 20)")))
title("Bernoulli")
lines(theta, L, lwd=6, col="#8080BF")
grid()
lines(theta, L, lwd=6, col="#8080BF")

h_theta = -log(1-theta)
plot(theta, h_theta, type="n", xlab=expression(theta), ylab=expression(paste(eta, " = h(", theta, ")")))
lines(theta, h_theta, lwd=6)
grid()
lines(theta, h_theta, lwd=6)

theta = seq(0.1, 2.5, (0.1+2.5)/1000)
L = S * log(1-exp(-theta)) - theta * (N-S)
plot(theta, L, type="n")
title("Truncated Poisson")
lines(theta, L, lwd=6, col="#0000BF")
grid()
lines(theta, L, lwd=6, col="#0000BF")

#############
# Chapter 8.3 Maximum-a-Posteriori Estimation
Expand Down Expand Up @@ -127,11 +127,11 @@ prior = dnorm(t, mu0, sigma0)/10
plot(t, p1, type="n")
title("N = 5")
legend(-2, 0.9, legend=c("Likelihood", "Posterior", "Prior", "Data"), col=c("blue", "orange", "green", "purple"), lty=1:1)
grid()
lines(t, p0, lwd = 4, col="blue")
lines(t, p1, lwd = 4, col="orange")
lines(t, prior, lwd = 4, col="green")
lines(t, q, lwd = 4, col="purple")
grid()

## Conjugate priors

Expand All @@ -158,6 +158,7 @@ for (i in 1:7) {
}

plot(t, posterior[[7]], type="n", xlab="", ylab="")
grid()
lines(t, posterior[[1]], lwd=3, col="red")
lines(t, posterior[[2]], lwd=3, col="orange")
lines(t, posterior[[3]], lwd=3, col="yellow")
Expand All @@ -167,6 +168,5 @@ lines(t, posterior[[6]], lwd=3, col="blue")
lines(t, posterior[[7]], lwd=3, col="purple")

legend(-0.9, 7, legend=c("N = 0", "N = 1", "N = 2", "N = 5", "N = 8", "N = 12", "N = 20"), col=c("red", "orange", "yellow", "green", "turquoise", "blue", "purple"), lty=1:1, lwd=3)
grid()

#############

0 comments on commit 0c2c8ee

Please sign in to comment.