|
47 | 47 | "from mpl_toolkits.mplot3d import Axes3D\n",
|
48 | 48 | "\n",
|
49 | 49 | "fig = plt.figure()\n",
|
50 |
| - "x = y = np.linspace(0,5, 100 )\n", |
| 50 | + "x = y = np.linspace(0, 5, 100 )\n", |
51 | 51 | "X, Y = np.meshgrid(x, y)\n",
|
52 | 52 | "\n",
|
53 | 53 | "subplot(121)\n",
|
54 |
| - "uni_x = stats.uniform.pdf( x,loc=0, scale = 5)\n", |
55 |
| - "uni_y = stats.uniform.pdf(x, loc=0, scale = 5)\n", |
| 54 | + "uni_x = stats.uniform.pdf(x, loc=0, scale = 5)\n", |
| 55 | + "uni_y = stats.uniform.pdf(y, loc=0, scale = 5)\n", |
56 | 56 | "M = np.dot( uni_x[:,None], uni_y[None,:] )\n",
|
57 | 57 | "im = plt.imshow(M, interpolation='none', origin='lower',\n",
|
58 | 58 | " cmap=cm.jet, vmax=1, vmin = -.15, extent=(0,5,0,5))\n",
|
|
557 | 557 | "subplot(313)\n",
|
558 | 558 | "p_trace = mcmc.trace(\"p\")[:]\n",
|
559 | 559 | "plot( p_trace, label = \"$p$: frequency of assignment to cluster 0\",\n",
|
560 |
| - " color = \"#467821\", lw = 1)\n", |
| 560 | + " color = \"#467821\", lw = lw)\n", |
561 | 561 | "plt.xlabel( \"Steps\" )\n",
|
562 | 562 | "plt.ylim(0,1)\n",
|
563 | 563 | "plt.legend();"
|
|
809 | 809 | "\n",
|
810 | 810 | "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",
|
811 | 811 | "\n",
|
812 |
| - "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. " |
| 812 | + "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. " |
813 | 813 | ]
|
814 | 814 | },
|
815 | 815 | {
|
|
878 | 878 | "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",
|
879 | 879 | "\n",
|
880 | 880 | "\\begin{align}\n",
|
881 |
| - "& P(L_x = 1| x = 175 ) \\gt P( (L_x = 0| x = 175 ) \\\\\\\\[5pt]\n", |
| 881 | + "& P(L_x = 1| x = 175 ) \\gt P(L_x = 0| x = 175 ) \\\\\\\\[5pt]\n", |
882 | 882 | "& \\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",
|
883 | 883 | "\\end{align}\n",
|
884 | 884 | "\n",
|
|
0 commit comments