Skip to content

Commit

Permalink
proofreading
Browse files Browse the repository at this point in the history
  • Loading branch information
avehtari committed Aug 21, 2015
1 parent 99bca6a commit 351082d
Show file tree
Hide file tree
Showing 28 changed files with 142 additions and 142 deletions.
4 changes: 2 additions & 2 deletions demos_ch2/demo2_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bayesian data analysis\n",
"### Bayesian Data Analysis, 3rd ed\n",
"## Chapter 2, demo 1\n",
"\n",
"437 girls and 543 boys have been observed. Calculate and plot the posterior distribution of the proportion of girls $\\theta $, using\n",
Expand Down Expand Up @@ -115,4 +115,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion demos_ch2/demo2_1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Bayesian data analysis
"""Bayesian Data Analysis, 3rd ed
Chapter 2, demo 1
437 girls and 543 boys have been observed. Calculate and plot the posterior
Expand Down
6 changes: 3 additions & 3 deletions demos_ch2/demo2_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bayesian data analysis\n",
"### Bayesian Data Analysis, 3rd ed\n",
"## Chapter 2, demo2\n",
"\n",
"Illustrate the effect of prior. Comparison of posterior distributions with different parameter values for the beta prior distribution."
"Illustrate the effect of a prior. Comparison of posterior distributions with different parameter values for Beta prior distribution."
]
},
{
Expand Down Expand Up @@ -143,4 +143,4 @@
"metadata": {}
}
]
}
}
6 changes: 3 additions & 3 deletions demos_ch2/demo2_2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Bayesian data analysis
"""Bayesian data analysis, 3rd ed
Chapter 2, demo 2
Illustrate the effect of prior. Comparison of posterior distributions with
different parameter values for the beta prior distribution.
Illustrate the effect of a prior. Comparison of posterior distributions with
different parameter values for Beta prior distribution.
"""

Expand Down
4 changes: 2 additions & 2 deletions demos_ch2/demo2_3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bayesian data analysis\n",
"### Bayesian Data Analysis, 3rd ed\n",
"## Chapter 2, demo3\n",
"\n",
"Simulate samples from Beta(438,544), draw a histogram with quantiles, and do the same for a transformed variable."
Expand Down Expand Up @@ -112,4 +112,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion demos_ch2/demo2_3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Bayesian data analysis
"""Bayesian Data Analysis, 3rd ed
Chapter 2, demo 3
Simulate samples from Beta(438,544), draw a histogram with quantiles, and do
Expand Down
8 changes: 4 additions & 4 deletions demos_ch2/demo2_4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bayesian data analysis\n",
"### Bayesian Data Analysis, 3rd ed\n",
"## Chapter 2, demo4\n",
"\n",
"Calculate the posterior distribution on a discrete grid of points by multiplying the likelihood and a non-conjugate prior at each point, and normalizing over the points. Simulate samples from the resulting non-standard posterior distribution using inverse cdf using the discrete grid."
Expand Down Expand Up @@ -72,7 +72,7 @@
"x = np.linspace(0, 1, nx)\n",
"\n",
"# Compute density of non-conjugate prior in grid\n",
"# This non-conjugate prior is same as in figure 2.4 in the book\n",
"# This non-conjugate prior is same as in Figure 2.4 in the book\n",
"pp = np.ones(nx)\n",
"ascent = (0.385 <= x) & (x <= 0.485)\n",
"descent = (0.485 <= x) & (x <= 0.585)\n",
Expand All @@ -82,7 +82,7 @@
"# Normalize the prior\n",
"pp /= np.sum(pp)\n",
"\n",
"# Unnormalsed non-conjugate posterior in grid\n",
"# Unnormalised non-conjugate posterior in grid\n",
"po = beta.pdf(x, a, b)*pp\n",
"po /= np.sum(po)\n",
"# Cumulative\n",
Expand Down Expand Up @@ -184,4 +184,4 @@
"metadata": {}
}
]
}
}
6 changes: 3 additions & 3 deletions demos_ch2/demo2_4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Bayesian data analysis
"""Bayesian Data Analysis, 3rd ed
Chapter 2, demo 4
Calculate the posterior distribution on a discrete grid of points by
Expand Down Expand Up @@ -28,7 +28,7 @@
x = np.linspace(0, 1, nx)

# Compute density of non-conjugate prior in grid
# This non-conjugate prior is same as in figure 2.4 in the book
# This non-conjugate prior is same as in Figure 2.4 in the book
pp = np.ones(nx)
ascent = (0.385 <= x) & (x <= 0.485)
descent = (0.485 <= x) & (x <= 0.585)
Expand All @@ -38,7 +38,7 @@
# Normalize the prior
pp /= np.sum(pp)

# Unnormalsed non-conjugate posterior in grid
# Unnormalised non-conjugate posterior in grid
po = beta.pdf(x, a, b)*pp
po /= np.sum(po)
# Cumulative
Expand Down
40 changes: 20 additions & 20 deletions demos_ch3/demo3_1-4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bayesian data analysis\n",
"## Chapter 3, demo 1-4\n",
"### Bayesian Data Analysis, 3rd ed\n",
"## Chapter 3, demos 1-4\n",
"\n",
"Examples and illustrations for normal model with unknown mean and variance\n",
"(BDA section 3.2 on p. 64)."
"Examples and illustrations for a normal model with unknown mean and variance\n",
"(BDA3 section 3.2 on p. 64)."
]
},
{
Expand Down Expand Up @@ -116,7 +116,7 @@
"tlynew = [50, 185]\n",
"xynew = np.linspace(tlynew[0], tlynew[1], 1000)\n",
"\n",
"# evaluate joint density in grid\n",
"# evaluate the joint density in a grid\n",
"# note that the following is not normalized, but for plotting\n",
"# contours it does not matter\n",
"Z = stats.norm.pdf(t1, my, t2[:,np.newaxis]/np.sqrt(n))\n",
Expand All @@ -127,7 +127,7 @@
"# z=(x-mean(y))/sqrt(s2/n), see BDA3 p. 21\n",
"pm_mu = stats.t.pdf((t1 - my) / np.sqrt(s2/n), n-1) / np.sqrt(s2/n)\n",
"\n",
"# estimate the marginal density for mu using samples and ad hoc Gaussian\n",
"# estimate the marginal density for mu using samples and an ad hoc Gaussian\n",
"# kernel approximation\n",
"pk_mu = stats.gaussian_kde(mu).evaluate(t1)\n",
"\n",
Expand All @@ -137,7 +137,7 @@
"pm_sigma = sinvchi2.pdf(t2**2, n-1, s2)*2*t2\n",
"# N.B. this was already calculated in the joint distribution case\n",
"\n",
"# estimate the marginal density for sigma using samples and ad hoc Gaussian\n",
"# estimate the marginal density for sigma using samples and an ad hoc Gaussian\n",
"# kernel approximation\n",
"pk_sigma = stats.gaussian_kde(sigma).evaluate(t2)\n",
"\n",
Expand All @@ -155,7 +155,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualise joint density and marginal densities of posterior of normal \n",
"Visualise the joint density and marginal densities of the posterior of normal \n",
"distribution with unknown mean and variance."
]
},
Expand All @@ -167,13 +167,13 @@
"plotgrid = gridspec.GridSpec(2, 2, width_ratios=[3,2], height_ratios=[3,2])\n",
"fig = plt.figure(figsize=(10,10))\n",
"\n",
"# plot joint distribution\n",
"# plot the joint distribution\n",
"plt.subplot(plotgrid[0,0])\n",
"# plot the contour plot of the exact posterior (c_levels is used to give\n",
"# a vector of linearly spaced values at which levels contours are drawn)\n",
"c_levels = np.linspace(1e-5, Z.max(), 6)[:-1]\n",
"plt.contour(t1, t2, Z, c_levels, colors='blue')\n",
"# plot samples from the joint posterior\n",
"# plot the samples from the joint posterior\n",
"samps = plt.scatter(mu, sigma, 5, color=[0.25, 0.75, 0.25])\n",
"# decorate\n",
"plt.xlim(tl1)\n",
Expand All @@ -187,7 +187,7 @@
" loc='upper center', \n",
")\n",
"\n",
"# plot marginal of mu\n",
"# plot the marginal of mu\n",
"plt.subplot(plotgrid[1,0])\n",
"# empirical\n",
"plt.plot(t1, pk_mu, color='#ff8f20', linewidth=2.5, label='empirical')\n",
Expand All @@ -199,7 +199,7 @@
"plt.yticks(())\n",
"plt.legend()\n",
"\n",
"# plot marginal of sigma\n",
"# plot the marginal of sigma\n",
"plt.subplot(plotgrid[0,1])\n",
"# empirical\n",
"plt.plot(pk_sigma, t2, color='#ff8f20', linewidth=2.5, label='empirical')\n",
Expand Down Expand Up @@ -230,7 +230,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualise factored sampling and corresponding marginal and conditional density."
"Visualise factored sampling and the corresponding marginal and conditional densities."
]
},
{
Expand All @@ -241,7 +241,7 @@
"plotgrid = gridspec.GridSpec(1, 2, width_ratios=[3,2])\n",
"fig = plt.figure(figsize=(10,7))\n",
"\n",
"# plot joint distribution\n",
"# plot the joint distribution\n",
"ax0 = plt.subplot(plotgrid[0,0])\n",
"# plot the contour plot of the exact posterior (c_levels is used to give\n",
"# a vector of linearly spaced values at which levels contours are drawn)\n",
Expand Down Expand Up @@ -272,7 +272,7 @@
" fontsize=14\n",
")\n",
"\n",
"# plot marginal of sigma\n",
"# plot the marginal of sigma\n",
"ax1 = plt.subplot(plotgrid[0,1])\n",
"plt.plot(pm_sigma, t2, 'b', linewidth=1.5)\n",
"# decorate\n",
Expand All @@ -298,7 +298,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualise marginal distribution of mu as a mixture of normals."
"Visualise the marginal distribution of mu as a mixture of normals."
]
},
{
Expand Down Expand Up @@ -360,13 +360,13 @@
"\n",
"fig = plt.figure(figsize=(11,11))\n",
"\n",
"# plot joint distribution\n",
"# plot the joint distribution\n",
"plt.subplot(2,2,1)\n",
"# plot the contour plot of the exact posterior (c_levels is used to give\n",
"# a vector of linearly spaced values at which levels contours are drawn)\n",
"c_levels = np.linspace(1e-5, Z.max(), 6)[:-1]\n",
"plt.contour(t1, t2, Z, c_levels, colors='blue')\n",
"# plot samples from the joint posterior\n",
"# plot the samples from the joint posterior\n",
"samps = plt.scatter(mu, sigma, 5, color=[0.25, 0.75, 0.25])\n",
"# decorate\n",
"plt.xlim(tl1)\n",
Expand All @@ -385,7 +385,7 @@
"\n",
"# plot first ynew\n",
"plt.subplot(2,2,2)\n",
"# plot first distribution and the respective sample\n",
"# plot the distribution and the respective sample\n",
"line1, = plt.plot(xynew, ynewdists[0], 'b', linewidth=1.5)\n",
"ax1_hs = plt.scatter(ynew[0], 0.02*np.max(ynewdists), 40, 'r')\n",
"# decorate\n",
Expand Down Expand Up @@ -434,4 +434,4 @@
"metadata": {}
}
]
}
}
20 changes: 10 additions & 10 deletions demos_ch3/demo3_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Bayesian data analysis
"""Bayesian Data Analysis, 3r ed
Chapter 3, demo 1
Visualise joint density and marginal densities of posterior of normal
Visualise the joint density and marginal densities of posterior of normal
distribution with unknown mean and variance.
"""
Expand Down Expand Up @@ -51,7 +51,7 @@
tl2 = [10, 60]
t2 = np.linspace(tl2[0], tl2[1], 1000)

# evaluate joint density in grid
# evaluate the joint density in a grid
# note that the following is not normalized, but for plotting
# contours it does not matter
Z = stats.norm.pdf(t1, my, t2[:,np.newaxis]/np.sqrt(n))
Expand All @@ -62,8 +62,8 @@
# z=(x-mean(y))/sqrt(s2/n), see BDA3 p. 21
pm_mu = stats.t.pdf((t1 - my) / np.sqrt(s2/n), n-1) / np.sqrt(s2/n)

# estimate the marginal density for mu using samples and ad hoc Gaussian
# kernel approximation
# estimate the marginal density for mu using samples and an ad hoc
# Gaussian kernel approximation
pk_mu = stats.gaussian_kde(mu).evaluate(t1)

# compute the exact marginal density for sigma
Expand All @@ -72,7 +72,7 @@
pm_sigma = sinvchi2.pdf(t2**2, n-1, s2)*2*t2
# N.B. this was already calculated in the joint distribution case

# estimate the marginal density for sigma using samples and ad hoc Gaussian
# estimate the marginal density for sigma using samples and an ad hoc Gaussian
# kernel approximation
pk_sigma = stats.gaussian_kde(sigma).evaluate(t2)

Expand All @@ -83,13 +83,13 @@
plotgrid = gridspec.GridSpec(2, 2, width_ratios=[3,2], height_ratios=[3,2])
plt.figure(figsize=(12,12))

# plot joint distribution
# plot the joint distribution
plt.subplot(plotgrid[0,0])
# plot the contour plot of the exact posterior (c_levels is used to give
# a vector of linearly spaced values at which levels contours are drawn)
c_levels = np.linspace(1e-5, Z.max(), 6)[:-1]
plt.contour(t1, t2, Z, c_levels, colors='blue')
# plot samples from the joint posterior
# plot the samples from the joint posterior
samps = plt.scatter(mu, sigma, 5, color=[0.25, 0.75, 0.25])
# decorate
plt.xlim(tl1)
Expand All @@ -102,7 +102,7 @@
('exact contour plot', 'samples')
)

# plot marginal of mu
# plot the marginal of mu
plt.subplot(plotgrid[1,0])
# empirical
plt.plot(t1, pk_mu, color='#ff8f20', linewidth=2.5, label='empirical')
Expand All @@ -114,7 +114,7 @@
plt.yticks(())
plt.legend()

# plot marginal of sigma
# plot the marginal of sigma
plt.subplot(plotgrid[0,1])
# empirical
plt.plot(pk_sigma, t2, color='#ff8f20', linewidth=2.5, label='empirical')
Expand Down
Loading

0 comments on commit 351082d

Please sign in to comment.