-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
First of all -- big kudos for creating the book! It's structured very well and the fact that it is accessible also to non-statisticians makes it a great self-learning tool for a wider audience!
I noticed what I think is an error in Chapter 3, in the first few plots showing the prior probability surfaces. Unless I'm mistaken, it's caused by this line:
M = np.dot(uni_x[:, None], uni_y[None, :])
which should instead be:
M = np.dot(uni_y[:, None], uni_x[None, :])
I think this becomes more clear if you look at a probability surface defined by two Gaussians with different standard deviations:
%matplotlib inline
import scipy.stats as stats
from IPython.core.pylabtools import figsize
import numpy as np
figsize(15.5, 4)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
jet = plt.cm.jet
fig = plt.figure()
x = y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)
plt.subplot(131)
norm_x = stats.norm.pdf(x, loc=0, scale=2)
norm_y = stats.norm.pdf(y, loc=0, scale=1)
M = np.dot(norm_y[:, None], norm_x[None, :])
im = plt.imshow(M, origin='lower',
cmap=jet, vmax=0.1, vmin=0, extent=(0, 5, 0, 5))
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.title("Landscape formed by Gaussian priors.")
ax = fig.add_subplot(132, projection='3d')
ax.plot_surface(X, Y, M, cmap=plt.cm.jet, vmax=0.1, vmin=0)
ax.view_init(azim=390)
plt.title("Gaussian prior landscape; alternate view")
plt.subplot(133)
plt.contour(X, Y, M)
The above snippet produces the following output:
And this is the output produced by np.dot(norm_x[:, None], norm_y[None, :])
:
with the latter stretching the distribution in the wrong direction.
This is not an issue for the first plot (uniform priors), but it makes a difference for the subsequent ones.