Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Chapter3_MCMC/IntroMCMC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
"from mpl_toolkits.mplot3d import Axes3D\n",
"\n",
"fig = plt.figure()\n",
"x = y = np.linspace(0,5, 100 )\n",
"x = y = np.linspace(0, 5, 100 )\n",
"X, Y = np.meshgrid(x, y)\n",
"\n",
"subplot(121)\n",
"uni_x = stats.uniform.pdf( x,loc=0, scale = 5)\n",
"uni_y = stats.uniform.pdf(x, loc=0, scale = 5)\n",
"uni_x = stats.uniform.pdf(x, loc=0, scale = 5)\n",
"uni_y = stats.uniform.pdf(y, loc=0, scale = 5)\n",
"M = np.dot( uni_x[:,None], uni_y[None,:] )\n",
"im = plt.imshow(M, interpolation='none', origin='lower',\n",
" cmap=cm.jet, vmax=1, vmin = -.15, extent=(0,5,0,5))\n",
Expand Down Expand Up @@ -557,7 +557,7 @@
"subplot(313)\n",
"p_trace = mcmc.trace(\"p\")[:]\n",
"plot( p_trace, label = \"$p$: frequency of assignment to cluster 0\",\n",
" color = \"#467821\", lw = 1)\n",
" color = \"#467821\", lw = lw)\n",
"plt.xlabel( \"Steps\" )\n",
"plt.ylim(0,1)\n",
"plt.legend();"
Expand Down Expand Up @@ -809,7 +809,7 @@
"\n",
"During MCMC, we are returned vectors representing samples from the unknown posteriors. Elements of different vectors cannot be used together, as this would break the above logic: perhaps a sample has returned that cluster 1 has a small standard deviation, hence all the other variables in that sample would incorporate that and be adjusted accordingly. It is easy to avoid this problem though, just make sure you are indexing traces correctly. \n",
"\n",
"Another small example to illustrate the point. Suppose two variables, $x$ and $y$, are related by $x+y=10$. We model $x$ as a Normal random variable with mean 4 and explore 300 samples. "
"Another small example to illustrate the point. Suppose two variables, $x$ and $y$, are related by $x+y=10$. We model $x$ as a Normal random variable with mean 4 and explore 500 samples. "
]
},
{
Expand Down Expand Up @@ -878,7 +878,7 @@
"In our case, $A$ represents $L_x = 1$ and $X$ is the evidence we have: we observe that $x = 175$. For a particular sample set of parameters for our posterior distribution, $( \\mu_0, \\sigma_0, \\mu_1, \\sigma_1, p)$, we are interested in asking \"Is the probability that $x$ is in cluster 1 *greater* than the probability it is in cluster 0?\", where the probability is dependent on the chosen parameters.\n",
"\n",
"\\begin{align}\n",
"& P(L_x = 1| x = 175 ) \\gt P( (L_x = 0| x = 175 ) \\\\\\\\[5pt]\n",
"& P(L_x = 1| x = 175 ) \\gt P(L_x = 0| x = 175 ) \\\\\\\\[5pt]\n",
"& \\frac{ P( x=175 | L_x = 1 )P( L_x = 1 ) }{P(x = 175) } \\gt \\frac{ P( x=175 | L_x = 0 )P( L_x = 0 )}{P(x = 175) }\n",
"\\end{align}\n",
"\n",
Expand Down