Skip to content

Commit 6e16632

Browse files
committed
Ending code cells with a semicolon.
1 parent fb393dd commit 6e16632

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

Chapter6_Priorities/Priors.ipynb

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"plt.ylim(0, 4)\n",
8080
"leg = plt.legend(loc=\"upper left\")\n",
8181
"leg.get_frame().set_alpha(0.4)\n",
82-
"plt.title(\"Comparing objective vs. subjective priors for an unknown probability\")\n"
82+
"plt.title(\"Comparing objective vs. subjective priors for an unknown probability\");"
8383
],
8484
"language": "python",
8585
"metadata": {},
@@ -200,7 +200,7 @@
200200
" plt.fill_between(x, 0, y, alpha=0.2, color=lines[0].get_color())\n",
201201
" plt.autoscale(tight=True)\n",
202202
"\n",
203-
"plt.legend(title=r\"$\\alpha, \\beta$ - parameters\")\n"
203+
"plt.legend(title=r\"$\\alpha, \\beta$ - parameters\");"
204204
],
205205
"language": "python",
206206
"metadata": {},
@@ -240,7 +240,7 @@
240240
" cmap=plt.cm.hot)\n",
241241
" ax.axis(\"off\")\n",
242242
"\n",
243-
"plt.suptitle(\"Random matrices from a Wishart Distribution\")\n"
243+
"plt.suptitle(\"Random matrices from a Wishart Distribution\");"
244244
],
245245
"language": "python",
246246
"metadata": {},
@@ -292,7 +292,7 @@
292292
" plt.fill_between(x, 0, y, alpha=0.2, color=lines[0].get_color())\n",
293293
" plt.autoscale(tight=True)\n",
294294
"plt.ylim(0)\n",
295-
"plt.legend(loc='upper left', title=\"(a,b)-parameters\")\n"
295+
"plt.legend(loc='upper left', title=\"(a,b)-parameters\");"
296296
],
297297
"language": "python",
298298
"metadata": {},
@@ -457,7 +457,7 @@
457457
"\n",
458458
" self.bb_score = np.r_[self.bb_score, bb_score]\n",
459459
" self.choices = np.r_[self.choices, choices]\n",
460-
" return\n"
460+
" return;"
461461
],
462462
"language": "python",
463463
"metadata": {},
@@ -498,7 +498,7 @@
498498
" plt.title(\"Posteriors After %d pull\" % bayesian_strategy.N +\n",
499499
" \"s\" * (bayesian_strategy.N > 1))\n",
500500
" plt.autoscale(tight=True)\n",
501-
" return\n"
501+
" return;"
502502
],
503503
"language": "python",
504504
"metadata": {},
@@ -521,7 +521,7 @@
521521
" plot_priors(bayesian_strat, hidden_prob)\n",
522522
" # plt.legend()\n",
523523
" plt.autoscale(tight=True)\n",
524-
"plt.tight_layout()\n"
524+
"plt.tight_layout();"
525525
],
526526
"language": "python",
527527
"metadata": {},
@@ -555,7 +555,7 @@
555555
"from IPython.core.display import HTML\n",
556556
"\n",
557557
"# try executing the below command twice if the first time doesn't work\n",
558-
"HTML(filename=\"BanditsD3.html\")\n"
558+
"HTML(filename=\"BanditsD3.html\");"
559559
],
560560
"language": "python",
561561
"metadata": {},
@@ -704,6 +704,8 @@
704704
"bandits = Bandits(hidden_prob)\n",
705705
"\n",
706706
"# define regret\n",
707+
"\n",
708+
"\n",
707709
"def regret(probabilities, choices):\n",
708710
" w_opt = probabilities.max()\n",
709711
" return (w_opt - probabilities[choices.astype(int)]).cumsum()\n",
@@ -716,7 +718,7 @@
716718
" random_choice]\n",
717719
"algos = []\n",
718720
"for strat in strategies:\n",
719-
" algos.append(GeneralBanditStrat(bandits, strat))\n"
721+
" algos.append(GeneralBanditStrat(bandits, strat));"
720722
],
721723
"language": "python",
722724
"metadata": {},
@@ -739,7 +741,7 @@
739741
"plt.title(\"Total Regret of Bayesian Bandits Strategy vs. Random guessing\")\n",
740742
"plt.xlabel(\"Number of pulls\")\n",
741743
"plt.ylabel(\"Regret after $n$ pulls\")\n",
742-
"plt.legend(loc=\"upper left\")\n"
744+
"plt.legend(loc=\"upper left\");"
743745
],
744746
"language": "python",
745747
"metadata": {},
@@ -793,7 +795,7 @@
793795
"plt.title(\"Expected Total Regret of Multi-armed Bandit strategies\")\n",
794796
"plt.xlabel(\"Number of pulls\")\n",
795797
"plt.ylabel(\"Exepected Total Regret \\n after $n$ pulls\")\n",
796-
"plt.legend(loc=\"upper left\")\n"
798+
"plt.legend(loc=\"upper left\");"
797799
],
798800
"language": "python",
799801
"metadata": {},
@@ -847,7 +849,7 @@
847849
" loc=\"upper left\")\n",
848850
"plt.ylabel(\"Exepected Total Regret \\n after $\\log{n}$ pulls\")\n",
849851
"plt.title(\"log-scale of above\")\n",
850-
"plt.ylabel(\"Exepected Total Regret \\n after $\\log{n}$ pulls\")\n"
852+
"plt.ylabel(\"Exepected Total Regret \\n after $\\log{n}$ pulls\");"
851853
],
852854
"language": "python",
853855
"metadata": {},
@@ -920,7 +922,7 @@
920922
" bayesian_strat.sample_bandits(i)\n",
921923
" plot_priors(bayesian_strat, hidden_prob, lw=2, alpha=0.0, plt_vlines=False)\n",
922924
" # plt.legend()\n",
923-
" plt.xlim(0, 0.5)\n"
925+
" plt.xlim(0, 0.5);"
924926
],
925927
"language": "python",
926928
"metadata": {},
@@ -1038,7 +1040,7 @@
10381040
" plt.title(name + \" prior\")\n",
10391041
" plt.vlines(0, 0, y.max(), \"k\", \"--\", linewidth=0.5)\n",
10401042
" plt.xlim(-0.15, 0.15)\n",
1041-
"plt.tight_layout()\n"
1043+
"plt.tight_layout();"
10421044
],
10431045
"language": "python",
10441046
"metadata": {},
@@ -1075,7 +1077,7 @@
10751077
"prior_std = np.array([x[1] for x in expert_prior_params.values()])\n",
10761078
"\n",
10771079
"inv_cov_matrix = pm.Wishart(\"inv_cov_matrix\", n_observations, np.diag(prior_std ** 2))\n",
1078-
"mu = pm.Normal(\"returns\", prior_mu, 1, size=4)\n"
1080+
"mu = pm.Normal(\"returns\", prior_mu, 1, size=4);"
10791081
],
10801082
"language": "python",
10811083
"metadata": {},
@@ -1116,7 +1118,7 @@
11161118
" _previous_day = np.roll(stock_closes[stock], -1)\n",
11171119
" stock_returns[stock] = ((stock_closes[stock] - _previous_day) / _previous_day)[:n_observations]\n",
11181120
"\n",
1119-
"dates = map(lambda x: datetime.datetime.strptime(x, \"%Y-%m-%d\"), x[1:n_observations + 1, 0])\n"
1121+
"dates = map(lambda x: datetime.datetime.strptime(x, \"%Y-%m-%d\"), x[1:n_observations + 1, 0]);"
11201122
],
11211123
"language": "python",
11221124
"metadata": {},
@@ -1131,15 +1133,15 @@
11311133
"\n",
11321134
"for _stock, _returns in stock_returns.iteritems():\n",
11331135
" p = plt.plot((1 + _returns)[::-1].cumprod() - 1, '-o', label=\"%s\" % _stock,\n",
1134-
" markersize=4, markeredgecolor=\"none\")\n",
1136+
" markersize=4, markeredgecolor=\"none\")\n",
11351137
"\n",
11361138
"plt.xticks(np.arange(100)[::-8],\n",
11371139
" map(lambda x: datetime.datetime.strftime(x, \"%Y-%m-%d\"), dates[::8]),\n",
11381140
" rotation=60)\n",
11391141
"\n",
11401142
"plt.legend(loc=\"upper left\")\n",
11411143
"plt.title(\"Return space\")\n",
1142-
"plt.ylabel(\"Return of $1 on first date, x100%\")\n"
1144+
"plt.ylabel(\"Return of $1 on first date, x100%\");"
11431145
],
11441146
"language": "python",
11451147
"metadata": {},
@@ -1172,7 +1174,7 @@
11721174
" plt.xlim(-0.15, 0.15)\n",
11731175
"\n",
11741176
"plt.tight_layout()\n",
1175-
"plt.suptitle(\"Histogram of daily returns\", size=14)\n"
1177+
"plt.suptitle(\"Histogram of daily returns\", size=14);"
11761178
],
11771179
"language": "python",
11781180
"metadata": {},
@@ -1204,7 +1206,7 @@
12041206
"model = pm.Model([obs, mu, inv_cov_matrix])\n",
12051207
"mcmc = pm.MCMC()\n",
12061208
"\n",
1207-
"mcmc.sample(150000, 100000, 3)\n"
1209+
"mcmc.sample(150000, 100000, 3);"
12081210
],
12091211
"language": "python",
12101212
"metadata": {},
@@ -1244,7 +1246,7 @@
12441246
"plt.vlines(mu_samples.mean(axis=0), 0, 500, linestyle=\"--\", linewidth=.5)\n",
12451247
"\n",
12461248
"plt.title(\"Posterior distribution of $\\mu$, daily stock returns\")\n",
1247-
"plt.legend()\n"
1249+
"plt.legend();"
12481250
],
12491251
"language": "python",
12501252
"metadata": {},
@@ -1286,7 +1288,7 @@
12861288
" plt.xlim(-0.15, 0.15)\n",
12871289
"\n",
12881290
"plt.suptitle(\"Posterior distribution of daily stock returns\")\n",
1289-
"plt.tight_layout()\n"
1291+
"plt.tight_layout();"
12901292
],
12911293
"language": "python",
12921294
"metadata": {},
@@ -1343,7 +1345,7 @@
13431345
"plt.xticks(np.arange(4) + 0.5, stock_returns.keys())\n",
13441346
"plt.title(\"(mean posterior) variances of daily stock returns\")\n",
13451347
"\n",
1346-
"plt.tight_layout()\n"
1348+
"plt.tight_layout();"
13471349
],
13481350
"language": "python",
13491351
"metadata": {},
@@ -1435,14 +1437,14 @@
14351437
"cell_type": "code",
14361438
"collapsed": false,
14371439
"input": [
1438-
"figsize( 12.5, 5 )\n",
1440+
"figsize(12.5, 5)\n",
14391441
"\n",
1440-
"x = np.linspace( 0.000 ,1, 150 )\n",
1441-
"y = np.linspace( 1.0, 1.0, 150 )\n",
1442-
"lines = plt.plot( x, y, color=\"#A60628\", lw = 3 )\n",
1443-
"plt.fill_between( x, 0, y, alpha = 0.2, color = lines[0].get_color() )\n",
1442+
"x = np.linspace(0.000, 1, 150)\n",
1443+
"y = np.linspace(1.0, 1.0, 150)\n",
1444+
"lines = plt.plot(x, y, color=\"#A60628\", lw=3)\n",
1445+
"plt.fill_between(x, 0, y, alpha=0.2, color=lines[0].get_color())\n",
14441446
"plt.autoscale(tight=True)\n",
1445-
"plt.ylim( 0, 2);"
1447+
"plt.ylim(0, 2);"
14461448
],
14471449
"language": "python",
14481450
"metadata": {},
@@ -1469,14 +1471,14 @@
14691471
"cell_type": "code",
14701472
"collapsed": false,
14711473
"input": [
1472-
"figsize( 12.5, 5 )\n",
1474+
"figsize(12.5, 5)\n",
14731475
"\n",
1474-
"psi = np.linspace( -10 ,10, 150 )\n",
1475-
"y = np.exp(psi) / (1 + np.exp(psi))**2\n",
1476-
"lines = plt.plot( psi, y, color=\"#A60628\", lw = 3 )\n",
1477-
"plt.fill_between( psi, 0, y, alpha = 0.2, color = lines[0].get_color() )\n",
1476+
"psi = np.linspace(-10, 10, 150)\n",
1477+
"y = np.exp(psi) / (1 + np.exp(psi)) ** 2\n",
1478+
"lines = plt.plot(psi, y, color=\"#A60628\", lw=3)\n",
1479+
"plt.fill_between(psi, 0, y, alpha=0.2, color=lines[0].get_color())\n",
14781480
"plt.autoscale(tight=True)\n",
1479-
"plt.ylim( 0, 1);"
1481+
"plt.ylim(0, 1);"
14801482
],
14811483
"language": "python",
14821484
"metadata": {},
@@ -1560,7 +1562,7 @@
15601562
" plt.fill_between(x, 0, y2, color=\"#A60628\", alpha=0.15)\n",
15611563
" plt.legend(title=\"N=%d\" % N)\n",
15621564
" plt.vlines(p, 0.0, 7.5, linestyles=\"--\", linewidth=1)\n",
1563-
" #plt.ylim( 0, 10)#\n"
1565+
" #plt.ylim( 0, 10)#;"
15641566
],
15651567
"language": "python",
15661568
"metadata": {},
@@ -1712,7 +1714,7 @@
17121714
"def css_styling():\n",
17131715
" styles = open(\"../styles/custom.css\", \"r\").read()\n",
17141716
" return HTML(styles)\n",
1715-
"css_styling()\n"
1717+
"css_styling();"
17161718
],
17171719
"language": "python",
17181720
"metadata": {},

0 commit comments

Comments
 (0)