Skip to content

Commit 9018219

Browse files
committed
Chapter 2: minor code formatting
1 parent 9794bf4 commit 9018219

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Chapter2_MorePyMC/MorePyMC.ipynb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@
797797
" label = \"$N$: %d, $p$: %.1f\"%(N,p), \n",
798798
" linewidth=3)\n",
799799
" \n",
800-
"\n",
801800
"plt.legend(loc=\"upper left\")\n",
802801
"plt.xlim(0, 10.5)\n",
803802
"plt.xlabel(\"$k$\")\n",
@@ -1341,6 +1340,7 @@
13411340
"\n",
13421341
"def logistic( x, beta):\n",
13431342
" return 1.0/( 1.0 + np.exp( beta*x) )\n",
1343+
"\n",
13441344
"x = np.linspace( -4, 4, 100 )\n",
13451345
"plt.plot(x, logistic( x, 1), label = r\"$\\beta = 1$\")\n",
13461346
"plt.plot(x, logistic( x, 3), label = r\"$\\beta = 3$\")\n",
@@ -1430,6 +1430,7 @@
14301430
"collapsed": false,
14311431
"input": [
14321432
"import scipy.stats as stats\n",
1433+
"\n",
14331434
"nor = stats.norm\n",
14341435
"x = np.linspace( -8, 7, 150 )\n",
14351436
"mu = (-2, 0, 3)\n",
@@ -1442,8 +1443,6 @@
14421443
" label =\"$\\mu = %d,\\;\\\\tau = %.1f$\"%(_mu, _tau), color = _color )\n",
14431444
" plt.fill_between( x, nor.pdf( x, _mu, scale =1./_tau ), color = _color, \\\n",
14441445
" alpha = .33)\n",
1445-
" \n",
1446-
"\n",
14471446
"\n",
14481447
"plt.legend(loc = \"upper right\")\n",
14491448
"plt.xlabel(\"$x$\")\n",
@@ -1634,6 +1633,7 @@
16341633
"collapsed": false,
16351634
"input": [
16361635
"figsize( 12.5, 4)\n",
1636+
"\n",
16371637
"plt.plot( t, mean_prob_t, lw = 3, label = \"average posterior \\nprobability \\\n",
16381638
"of defect\")\n",
16391639
"plt.plot( t, p_t[0, :], ls=\"--\",label=\"realization from posterior\" )\n",
@@ -1671,6 +1671,7 @@
16711671
"collapsed": false,
16721672
"input": [
16731673
"from scipy.stats.mstats import mquantiles\n",
1674+
"\n",
16741675
"# vectorized bottom and top 5% quantiles for \"confidence interval\"\n",
16751676
"qs = mquantiles(p_t,[0.05,0.95],axis=0)\n",
16761677
"plt.fill_between(t[:,0],*qs,alpha = 0.7,\n",
@@ -1723,6 +1724,7 @@
17231724
"collapsed": false,
17241725
"input": [
17251726
"figsize(12.5, 2.5)\n",
1727+
"\n",
17261728
"prob_31 = logistic( 31, beta_samples, alpha_samples )\n",
17271729
"\n",
17281730
"plt.xlim( 0.995, 1)\n",
@@ -1768,7 +1770,6 @@
17681770
"simulated = mc.Bernoulli( \"bernoulli_sim\", p)\n",
17691771
"N = 10000\n",
17701772
"\n",
1771-
"\n",
17721773
"mcmc = mc.MCMC( [simulated, alpha, beta, observed ] )\n",
17731774
"mcmc.sample( N )"
17741775
],
@@ -1798,6 +1799,7 @@
17981799
"collapsed": false,
17991800
"input": [
18001801
"figsize(12.5, 5)\n",
1802+
"\n",
18011803
"simulations = mcmc.trace(\"bernoulli_sim\")[:]\n",
18021804
"print simulations.shape\n",
18031805
"\n",
@@ -1962,9 +1964,10 @@
19621964
"cell_type": "code",
19631965
"collapsed": false,
19641966
"input": [
1965-
"figsize( 11., 1.5 )\n",
19661967
"from separation_plot import separation_plot\n",
19671968
"\n",
1969+
"figsize( 11., 1.5 )\n",
1970+
"\n",
19681971
"separation_plot(posterior_probability, D )"
19691972
],
19701973
"language": "python",
@@ -2071,6 +2074,7 @@
20712074
"input": [
20722075
"#type your code here.\n",
20732076
"figsize(12.5, 4 )\n",
2077+
"\n",
20742078
"plt.scatter( alpha_samples, beta_samples, alpha = 0.1 )\n",
20752079
"plt.title( \"Why does the plot look like this?\" )\n",
20762080
"plt.xlabel( r\"$\\alpha$\")\n",

0 commit comments

Comments
 (0)