Skip to content

Commit 4876681

Browse files
committed
Ending code cells with a semicolon.
1 parent 74b7ee2 commit 4876681

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

Chapter3_MCMC/IntroMCMC.ipynb

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"ax = fig.add_subplot(122, projection='3d')\n",
6868
"ax.plot_surface(X, Y, M, cmap=plt.cm.jet, vmax=1, vmin=-.15)\n",
6969
"ax.view_init(azim=390)\n",
70-
"plt.title(\"Uniform prior landscape; alternate view\")\n"
70+
"plt.title(\"Uniform prior landscape; alternate view\");"
7171
],
7272
"language": "python",
7373
"metadata": {},
@@ -113,7 +113,7 @@
113113
"ax = fig.add_subplot(122, projection='3d')\n",
114114
"ax.plot_surface(X, Y, M, cmap=jet)\n",
115115
"ax.view_init(azim=390)\n",
116-
"plt.title(\"$Exp(3), Exp(10)$ prior landscape; \\nalternate view\")\n"
116+
"plt.title(\"$Exp(3), Exp(10)$ prior landscape; \\nalternate view\");"
117117
],
118118
"language": "python",
119119
"metadata": {},
@@ -168,7 +168,7 @@
168168
" for _x in x]).prod(axis=1)\n",
169169
"likelihood_y = np.array([stats.poisson.pmf(data[:, 1], _y)\n",
170170
" for _y in y]).prod(axis=1)\n",
171-
"L = np.dot(likelihood_x[:, None], likelihood_y[None, :])\n"
171+
"L = np.dot(likelihood_x[:, None], likelihood_y[None, :]);"
172172
],
173173
"language": "python",
174174
"metadata": {},
@@ -232,7 +232,7 @@
232232
"plt.title(\"Landscape warped by %d data observation;\\n Exponential priors on \\\n",
233233
"$p_1, p_2$.\" % N)\n",
234234
"plt.xlim(0, 5)\n",
235-
"plt.ylim(0, 5)\n"
235+
"plt.ylim(0, 5);"
236236
],
237237
"language": "python",
238238
"metadata": {},
@@ -324,7 +324,7 @@
324324
"plt.hist(data, bins=20, color=\"k\", histtype=\"stepfilled\", alpha=0.8)\n",
325325
"plt.title(\"Histogram of the dataset\")\n",
326326
"plt.ylim([0, None])\n",
327-
"print data[:10], \"...\"\n"
327+
"print data[:10], \"...\";"
328328
],
329329
"language": "python",
330330
"metadata": {},
@@ -378,7 +378,7 @@
378378
"\n",
379379
"assignment = pm.Categorical(\"assignment\", [p, 1 - p], size=data.shape[0])\n",
380380
"print \"prior assignment, with p = %.2f:\" % p.value\n",
381-
"print assignment.value[:10], \"...\"\n"
381+
"print assignment.value[:10], \"...\";"
382382
],
383383
"language": "python",
384384
"metadata": {},
@@ -423,17 +423,19 @@
423423
"to a set of parameters, located in the (1,2) arrays `taus` and `centers`.\n",
424424
"\"\"\"\n",
425425
"\n",
426+
"\n",
426427
"@pm.deterministic\n",
427428
"def center_i(assignment=assignment, centers=centers):\n",
428429
" return centers[assignment]\n",
429430
"\n",
431+
"\n",
430432
"@pm.deterministic\n",
431433
"def tau_i(assignment=assignment, taus=taus):\n",
432434
" return taus[assignment]\n",
433435
"\n",
434436
"print \"Random assignments: \", assignment.value[:4], \"...\"\n",
435437
"print \"Assigned center: \", center_i.value[:4], \"...\"\n",
436-
"print \"Assigned precision: \", tau_i.value[:4], \"...\"\n"
438+
"print \"Assigned precision: \", tau_i.value[:4], \"...\";"
437439
],
438440
"language": "python",
439441
"metadata": {},
@@ -458,7 +460,7 @@
458460
"observations = pm.Normal(\"obs\", center_i, tau_i, value=data, observed=True)\n",
459461
"\n",
460462
"# below we create a model class\n",
461-
"model = pm.Model([p, assignment, taus, centers])\n"
463+
"model = pm.Model([p, assignment, taus, centers]);"
462464
],
463465
"language": "python",
464466
"metadata": {},
@@ -481,7 +483,7 @@
481483
"collapsed": false,
482484
"input": [
483485
"mcmc = pm.MCMC(model)\n",
484-
"mcmc.sample(50000)\n"
486+
"mcmc.sample(50000);"
485487
],
486488
"language": "python",
487489
"metadata": {},
@@ -533,18 +535,18 @@
533535
"plt.subplot(312)\n",
534536
"std_trace = mcmc.trace(\"stds\")[:]\n",
535537
"plt.plot(std_trace[:, 0], label=\"trace of standard deviation of cluster 0\",\n",
536-
" c=colors[0], lw=lw)\n",
538+
" c=colors[0], lw=lw)\n",
537539
"plt.plot(std_trace[:, 1], label=\"trace of standard deviation of cluster 1\",\n",
538-
" c=colors[1], lw=lw)\n",
540+
" c=colors[1], lw=lw)\n",
539541
"plt.legend(loc=\"upper left\")\n",
540542
"\n",
541543
"plt.subplot(313)\n",
542544
"p_trace = mcmc.trace(\"p\")[:]\n",
543545
"plt.plot(p_trace, label=\"$p$: frequency of assignment to cluster 0\",\n",
544-
" color=\"#467821\", lw=lw)\n",
546+
" color=\"#467821\", lw=lw)\n",
545547
"plt.xlabel(\"Steps\")\n",
546548
"plt.ylim(0, 1)\n",
547-
"plt.legend()\n"
549+
"plt.legend();"
548550
],
549551
"language": "python",
550552
"metadata": {},
@@ -580,7 +582,7 @@
580582
"cell_type": "code",
581583
"collapsed": false,
582584
"input": [
583-
"mcmc.sample(100000)\n"
585+
"mcmc.sample(100000);"
584586
],
585587
"language": "python",
586588
"metadata": {},
@@ -613,9 +615,9 @@
613615
"\n",
614616
"x = np.arange(50000)\n",
615617
"plt.plot(x, prev_center_trace[:, 0], label=\"previous trace of center 0\",\n",
616-
" lw=lw, alpha=0.4, c=colors[1])\n",
618+
" lw=lw, alpha=0.4, c=colors[1])\n",
617619
"plt.plot(x, prev_center_trace[:, 1], label=\"previous trace of center 1\",\n",
618-
" lw=lw, alpha=0.4, c=colors[0])\n",
620+
" lw=lw, alpha=0.4, c=colors[0])\n",
619621
"\n",
620622
"x = np.arange(50000, 150000)\n",
621623
"plt.plot(x, center_trace[:, 0], label=\"new trace of center 0\", lw=lw, c=\"#348ABD\")\n",
@@ -624,7 +626,7 @@
624626
"plt.title(\"Traces of unknown center parameters\")\n",
625627
"leg = plt.legend(loc=\"upper right\")\n",
626628
"leg.get_frame().set_alpha(0.8)\n",
627-
"plt.xlabel(\"Steps\")\n"
629+
"plt.xlabel(\"Steps\");"
628630
],
629631
"language": "python",
630632
"metadata": {},
@@ -671,7 +673,7 @@
671673
" histtype=\"stepfilled\")\n",
672674
" # plt.autoscale(tight=True)\n",
673675
"\n",
674-
"plt.tight_layout()\n"
676+
"plt.tight_layout();"
675677
],
676678
"language": "python",
677679
"metadata": {},
@@ -704,12 +706,12 @@
704706
"figsize(12.5, 4.5)\n",
705707
"plt.cmap = mpl.colors.ListedColormap(colors)\n",
706708
"plt.imshow(mcmc.trace(\"assignment\")[::400, np.argsort(data)],\n",
707-
" cmap=plt.cmap, aspect=.4, alpha=.9)\n",
709+
" cmap=plt.cmap, aspect=.4, alpha=.9)\n",
708710
"plt.xticks(np.arange(0, data.shape[0], 40),\n",
709-
" [\"%.2f\" % s for s in np.sort(data)[::40]])\n",
711+
" [\"%.2f\" % s for s in np.sort(data)[::40]])\n",
710712
"plt.ylabel(\"posterior sample\")\n",
711713
"plt.xlabel(\"value of $i$th data point\")\n",
712-
"plt.title(\"Posterior labels of data points\")\n"
714+
"plt.title(\"Posterior labels of data points\");"
713715
],
714716
"language": "python",
715717
"metadata": {},
@@ -739,12 +741,12 @@
739741
"cmap = mpl.colors.LinearSegmentedColormap.from_list(\"BMH\", colors)\n",
740742
"assign_trace = mcmc.trace(\"assignment\")[:]\n",
741743
"plt.scatter(data, 1 - assign_trace.mean(axis=0), cmap=cmap,\n",
742-
" c=assign_trace.mean(axis=0), s=50)\n",
744+
" c=assign_trace.mean(axis=0), s=50)\n",
743745
"plt.ylim(-0.05, 1.05)\n",
744746
"plt.xlim(35, 300)\n",
745747
"plt.title(\"Probability of data point belonging to cluster 0\")\n",
746748
"plt.ylabel(\"probability\")\n",
747-
"plt.xlabel(\"value of data point\")\n"
749+
"plt.xlabel(\"value of data point\");"
748750
],
749751
"language": "python",
750752
"metadata": {},
@@ -788,7 +790,7 @@
788790
"posterior_p_mean = mcmc.trace(\"p\")[:].mean()\n",
789791
"\n",
790792
"plt.hist(data, bins=20, histtype=\"step\", normed=True, color=\"k\",\n",
791-
" lw=2, label=\"histogram of data\")\n",
793+
" lw=2, label=\"histogram of data\")\n",
792794
"y = posterior_p_mean * norm.pdf(x, loc=posterior_center_means[0],\n",
793795
" scale=posterior_std_means[0])\n",
794796
"plt.plot(x, y, label=\"Cluster 0 (using posterior-mean parameters)\", lw=3)\n",
@@ -800,7 +802,7 @@
800802
"plt.fill_between(x, y, color=colors[0], alpha=0.3)\n",
801803
"\n",
802804
"plt.legend(loc=\"upper left\")\n",
803-
"plt.title(\"Visualizing Clusters using posterior-mean parameters\")\n"
805+
"plt.title(\"Visualizing Clusters using posterior-mean parameters\");"
804806
],
805807
"language": "python",
806808
"metadata": {},
@@ -851,7 +853,7 @@
851853
"\n",
852854
"plt.plot(ex_mcmc.trace(\"x\")[:])\n",
853855
"plt.plot(ex_mcmc.trace(\"y\")[:])\n",
854-
"plt.title(\"Displaying (extreme) case of dependence between unknowns\")\n"
856+
"plt.title(\"Displaying (extreme) case of dependence between unknowns\");"
855857
],
856858
"language": "python",
857859
"metadata": {},
@@ -940,7 +942,7 @@
940942
"v = p_trace * norm_pdf(x, loc=center_trace[:, 0], scale=std_trace[:, 0]) > \\\n",
941943
" (1 - p_trace) * norm_pdf(x, loc=center_trace[:, 1], scale=std_trace[:, 1])\n",
942944
"\n",
943-
"print \"Probability of belonging to cluster 1:\", v.mean()\n"
945+
"print \"Probability of belonging to cluster 1:\", v.mean();"
944946
],
945947
"language": "python",
946948
"metadata": {},
@@ -1034,7 +1036,7 @@
10341036
"plt.plot(y_t, label=\"$y_t$\", lw=3)\n",
10351037
"plt.plot(x_t, label=\"$x_t$\", lw=3)\n",
10361038
"plt.xlabel(\"time, $t$\")\n",
1037-
"plt.legend()\n"
1039+
"plt.legend();"
10381040
],
10391041
"language": "python",
10401042
"metadata": {},
@@ -1080,7 +1082,7 @@
10801082
"plt.legend(title=\"Autocorrelation\")\n",
10811083
"plt.ylabel(\"measured correlation \\nbetween $y_t$ and $y_{t-k}$.\")\n",
10821084
"plt.xlabel(\"k (lag)\")\n",
1083-
"plt.title(\"Autocorrelation plot of $y_t$ and $x_t$ for differing $k$ lags.\")\n"
1085+
"plt.title(\"Autocorrelation plot of $y_t$ and $x_t$ for differing $k$ lags.\");"
10841086
],
10851087
"language": "python",
10861088
"metadata": {},
@@ -1140,7 +1142,7 @@
11401142
"plt.ylabel(\"measured correlation \\nbetween $y_t$ and $y_{t-k}$.\")\n",
11411143
"plt.xlabel(\"k (lag)\")\n",
11421144
"plt.title(\"Autocorrelation of $y_t$ (no thinning vs. thinning) \\\n",
1143-
"at differing $k$ lags.\")\n"
1145+
"at differing $k$ lags.\");"
11441146
],
11451147
"language": "python",
11461148
"metadata": {},
@@ -1187,7 +1189,7 @@
11871189
"from pymc.Matplot import plot as mcplot\n",
11881190
"\n",
11891191
"mcmc.sample(25000, 0, 10)\n",
1190-
"mcplot(mcmc.trace(\"centers\", 2), common_scale=False)\n"
1192+
"mcplot(mcmc.trace(\"centers\", 2), common_scale=False);"
11911193
],
11921194
"language": "python",
11931195
"metadata": {},
@@ -1310,7 +1312,7 @@
13101312
"def css_styling():\n",
13111313
" styles = open(\"../styles/custom.css\", \"r\").read()\n",
13121314
" return HTML(styles)\n",
1313-
"css_styling()\n"
1315+
"css_styling();"
13141316
],
13151317
"language": "python",
13161318
"metadata": {},

0 commit comments

Comments
 (0)