Skip to content

Commit da48932

Browse files
Revert "Ending code cells with a semicolon."
This reverts commit 4876681.
1 parent fa1aa60 commit da48932

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

Chapter3_MCMC/IntroMCMC.ipynb

Lines changed: 32 additions & 34 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\");"
70+
"plt.title(\"Uniform prior landscape; alternate view\")\n"
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\");"
116+
"plt.title(\"$Exp(3), Exp(10)$ prior landscape; \\nalternate view\")\n"
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, :]);"
171+
"L = np.dot(likelihood_x[:, None], likelihood_y[None, :])\n"
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);"
235+
"plt.ylim(0, 5)\n"
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], \"...\";"
327+
"print data[:10], \"...\"\n"
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], \"...\";"
381+
"print assignment.value[:10], \"...\"\n"
382382
],
383383
"language": "python",
384384
"metadata": {},
@@ -423,19 +423,17 @@
423423
"to a set of parameters, located in the (1,2) arrays `taus` and `centers`.\n",
424424
"\"\"\"\n",
425425
"\n",
426-
"\n",
427426
"@pm.deterministic\n",
428427
"def center_i(assignment=assignment, centers=centers):\n",
429428
" return centers[assignment]\n",
430429
"\n",
431-
"\n",
432430
"@pm.deterministic\n",
433431
"def tau_i(assignment=assignment, taus=taus):\n",
434432
" return taus[assignment]\n",
435433
"\n",
436434
"print \"Random assignments: \", assignment.value[:4], \"...\"\n",
437435
"print \"Assigned center: \", center_i.value[:4], \"...\"\n",
438-
"print \"Assigned precision: \", tau_i.value[:4], \"...\";"
436+
"print \"Assigned precision: \", tau_i.value[:4], \"...\"\n"
439437
],
440438
"language": "python",
441439
"metadata": {},
@@ -460,7 +458,7 @@
460458
"observations = pm.Normal(\"obs\", center_i, tau_i, value=data, observed=True)\n",
461459
"\n",
462460
"# below we create a model class\n",
463-
"model = pm.Model([p, assignment, taus, centers]);"
461+
"model = pm.Model([p, assignment, taus, centers])\n"
464462
],
465463
"language": "python",
466464
"metadata": {},
@@ -483,7 +481,7 @@
483481
"collapsed": false,
484482
"input": [
485483
"mcmc = pm.MCMC(model)\n",
486-
"mcmc.sample(50000);"
484+
"mcmc.sample(50000)\n"
487485
],
488486
"language": "python",
489487
"metadata": {},
@@ -535,18 +533,18 @@
535533
"plt.subplot(312)\n",
536534
"std_trace = mcmc.trace(\"stds\")[:]\n",
537535
"plt.plot(std_trace[:, 0], label=\"trace of standard deviation of cluster 0\",\n",
538-
" c=colors[0], lw=lw)\n",
536+
" c=colors[0], lw=lw)\n",
539537
"plt.plot(std_trace[:, 1], label=\"trace of standard deviation of cluster 1\",\n",
540-
" c=colors[1], lw=lw)\n",
538+
" c=colors[1], lw=lw)\n",
541539
"plt.legend(loc=\"upper left\")\n",
542540
"\n",
543541
"plt.subplot(313)\n",
544542
"p_trace = mcmc.trace(\"p\")[:]\n",
545543
"plt.plot(p_trace, label=\"$p$: frequency of assignment to cluster 0\",\n",
546-
" color=\"#467821\", lw=lw)\n",
544+
" color=\"#467821\", lw=lw)\n",
547545
"plt.xlabel(\"Steps\")\n",
548546
"plt.ylim(0, 1)\n",
549-
"plt.legend();"
547+
"plt.legend()\n"
550548
],
551549
"language": "python",
552550
"metadata": {},
@@ -582,7 +580,7 @@
582580
"cell_type": "code",
583581
"collapsed": false,
584582
"input": [
585-
"mcmc.sample(100000);"
583+
"mcmc.sample(100000)\n"
586584
],
587585
"language": "python",
588586
"metadata": {},
@@ -615,9 +613,9 @@
615613
"\n",
616614
"x = np.arange(50000)\n",
617615
"plt.plot(x, prev_center_trace[:, 0], label=\"previous trace of center 0\",\n",
618-
" lw=lw, alpha=0.4, c=colors[1])\n",
616+
" lw=lw, alpha=0.4, c=colors[1])\n",
619617
"plt.plot(x, prev_center_trace[:, 1], label=\"previous trace of center 1\",\n",
620-
" lw=lw, alpha=0.4, c=colors[0])\n",
618+
" lw=lw, alpha=0.4, c=colors[0])\n",
621619
"\n",
622620
"x = np.arange(50000, 150000)\n",
623621
"plt.plot(x, center_trace[:, 0], label=\"new trace of center 0\", lw=lw, c=\"#348ABD\")\n",
@@ -626,7 +624,7 @@
626624
"plt.title(\"Traces of unknown center parameters\")\n",
627625
"leg = plt.legend(loc=\"upper right\")\n",
628626
"leg.get_frame().set_alpha(0.8)\n",
629-
"plt.xlabel(\"Steps\");"
627+
"plt.xlabel(\"Steps\")\n"
630628
],
631629
"language": "python",
632630
"metadata": {},
@@ -673,7 +671,7 @@
673671
" histtype=\"stepfilled\")\n",
674672
" # plt.autoscale(tight=True)\n",
675673
"\n",
676-
"plt.tight_layout();"
674+
"plt.tight_layout()\n"
677675
],
678676
"language": "python",
679677
"metadata": {},
@@ -706,12 +704,12 @@
706704
"figsize(12.5, 4.5)\n",
707705
"plt.cmap = mpl.colors.ListedColormap(colors)\n",
708706
"plt.imshow(mcmc.trace(\"assignment\")[::400, np.argsort(data)],\n",
709-
" cmap=plt.cmap, aspect=.4, alpha=.9)\n",
707+
" cmap=plt.cmap, aspect=.4, alpha=.9)\n",
710708
"plt.xticks(np.arange(0, data.shape[0], 40),\n",
711-
" [\"%.2f\" % s for s in np.sort(data)[::40]])\n",
709+
" [\"%.2f\" % s for s in np.sort(data)[::40]])\n",
712710
"plt.ylabel(\"posterior sample\")\n",
713711
"plt.xlabel(\"value of $i$th data point\")\n",
714-
"plt.title(\"Posterior labels of data points\");"
712+
"plt.title(\"Posterior labels of data points\")\n"
715713
],
716714
"language": "python",
717715
"metadata": {},
@@ -741,12 +739,12 @@
741739
"cmap = mpl.colors.LinearSegmentedColormap.from_list(\"BMH\", colors)\n",
742740
"assign_trace = mcmc.trace(\"assignment\")[:]\n",
743741
"plt.scatter(data, 1 - assign_trace.mean(axis=0), cmap=cmap,\n",
744-
" c=assign_trace.mean(axis=0), s=50)\n",
742+
" c=assign_trace.mean(axis=0), s=50)\n",
745743
"plt.ylim(-0.05, 1.05)\n",
746744
"plt.xlim(35, 300)\n",
747745
"plt.title(\"Probability of data point belonging to cluster 0\")\n",
748746
"plt.ylabel(\"probability\")\n",
749-
"plt.xlabel(\"value of data point\");"
747+
"plt.xlabel(\"value of data point\")\n"
750748
],
751749
"language": "python",
752750
"metadata": {},
@@ -790,7 +788,7 @@
790788
"posterior_p_mean = mcmc.trace(\"p\")[:].mean()\n",
791789
"\n",
792790
"plt.hist(data, bins=20, histtype=\"step\", normed=True, color=\"k\",\n",
793-
" lw=2, label=\"histogram of data\")\n",
791+
" lw=2, label=\"histogram of data\")\n",
794792
"y = posterior_p_mean * norm.pdf(x, loc=posterior_center_means[0],\n",
795793
" scale=posterior_std_means[0])\n",
796794
"plt.plot(x, y, label=\"Cluster 0 (using posterior-mean parameters)\", lw=3)\n",
@@ -802,7 +800,7 @@
802800
"plt.fill_between(x, y, color=colors[0], alpha=0.3)\n",
803801
"\n",
804802
"plt.legend(loc=\"upper left\")\n",
805-
"plt.title(\"Visualizing Clusters using posterior-mean parameters\");"
803+
"plt.title(\"Visualizing Clusters using posterior-mean parameters\")\n"
806804
],
807805
"language": "python",
808806
"metadata": {},
@@ -853,7 +851,7 @@
853851
"\n",
854852
"plt.plot(ex_mcmc.trace(\"x\")[:])\n",
855853
"plt.plot(ex_mcmc.trace(\"y\")[:])\n",
856-
"plt.title(\"Displaying (extreme) case of dependence between unknowns\");"
854+
"plt.title(\"Displaying (extreme) case of dependence between unknowns\")\n"
857855
],
858856
"language": "python",
859857
"metadata": {},
@@ -942,7 +940,7 @@
942940
"v = p_trace * norm_pdf(x, loc=center_trace[:, 0], scale=std_trace[:, 0]) > \\\n",
943941
" (1 - p_trace) * norm_pdf(x, loc=center_trace[:, 1], scale=std_trace[:, 1])\n",
944942
"\n",
945-
"print \"Probability of belonging to cluster 1:\", v.mean();"
943+
"print \"Probability of belonging to cluster 1:\", v.mean()\n"
946944
],
947945
"language": "python",
948946
"metadata": {},
@@ -1036,7 +1034,7 @@
10361034
"plt.plot(y_t, label=\"$y_t$\", lw=3)\n",
10371035
"plt.plot(x_t, label=\"$x_t$\", lw=3)\n",
10381036
"plt.xlabel(\"time, $t$\")\n",
1039-
"plt.legend();"
1037+
"plt.legend()\n"
10401038
],
10411039
"language": "python",
10421040
"metadata": {},
@@ -1082,7 +1080,7 @@
10821080
"plt.legend(title=\"Autocorrelation\")\n",
10831081
"plt.ylabel(\"measured correlation \\nbetween $y_t$ and $y_{t-k}$.\")\n",
10841082
"plt.xlabel(\"k (lag)\")\n",
1085-
"plt.title(\"Autocorrelation plot of $y_t$ and $x_t$ for differing $k$ lags.\");"
1083+
"plt.title(\"Autocorrelation plot of $y_t$ and $x_t$ for differing $k$ lags.\")\n"
10861084
],
10871085
"language": "python",
10881086
"metadata": {},
@@ -1142,7 +1140,7 @@
11421140
"plt.ylabel(\"measured correlation \\nbetween $y_t$ and $y_{t-k}$.\")\n",
11431141
"plt.xlabel(\"k (lag)\")\n",
11441142
"plt.title(\"Autocorrelation of $y_t$ (no thinning vs. thinning) \\\n",
1145-
"at differing $k$ lags.\");"
1143+
"at differing $k$ lags.\")\n"
11461144
],
11471145
"language": "python",
11481146
"metadata": {},
@@ -1189,7 +1187,7 @@
11891187
"from pymc.Matplot import plot as mcplot\n",
11901188
"\n",
11911189
"mcmc.sample(25000, 0, 10)\n",
1192-
"mcplot(mcmc.trace(\"centers\", 2), common_scale=False);"
1190+
"mcplot(mcmc.trace(\"centers\", 2), common_scale=False)\n"
11931191
],
11941192
"language": "python",
11951193
"metadata": {},
@@ -1312,7 +1310,7 @@
13121310
"def css_styling():\n",
13131311
" styles = open(\"../styles/custom.css\", \"r\").read()\n",
13141312
" return HTML(styles)\n",
1315-
"css_styling();"
1313+
"css_styling()\n"
13161314
],
13171315
"language": "python",
13181316
"metadata": {},

0 commit comments

Comments
 (0)