|
457 | 457 | "\n", |
458 | 458 | " self.bb_score = np.r_[self.bb_score, bb_score]\n", |
459 | 459 | " self.choices = np.r_[self.choices, choices]\n", |
460 | | - " return;" |
| 460 | + " return" |
461 | 461 | ], |
462 | 462 | "language": "python", |
463 | 463 | "metadata": {}, |
|
498 | 498 | " plt.title(\"Posteriors After %d pull\" % bayesian_strategy.N +\n", |
499 | 499 | " \"s\" * (bayesian_strategy.N > 1))\n", |
500 | 500 | " plt.autoscale(tight=True)\n", |
501 | | - " return;" |
| 501 | + " return" |
502 | 502 | ], |
503 | 503 | "language": "python", |
504 | 504 | "metadata": {}, |
|
521 | 521 | " plot_priors(bayesian_strat, hidden_prob)\n", |
522 | 522 | " # plt.legend()\n", |
523 | 523 | " plt.autoscale(tight=True)\n", |
524 | | - "plt.tight_layout();" |
| 524 | + "plt.tight_layout()" |
525 | 525 | ], |
526 | 526 | "language": "python", |
527 | 527 | "metadata": {}, |
|
555 | 555 | "from IPython.core.display import HTML\n", |
556 | 556 | "\n", |
557 | 557 | "# try executing the below command twice if the first time doesn't work\n", |
558 | | - "HTML(filename=\"BanditsD3.html\");" |
| 558 | + "HTML(filename=\"BanditsD3.html\")" |
559 | 559 | ], |
560 | 560 | "language": "python", |
561 | 561 | "metadata": {}, |
|
719 | 719 | " random_choice]\n", |
720 | 720 | "algos = []\n", |
721 | 721 | "for strat in strategies:\n", |
722 | | - " algos.append(GeneralBanditStrat(bandits, strat));" |
| 722 | + " algos.append(GeneralBanditStrat(bandits, strat))" |
723 | 723 | ], |
724 | 724 | "language": "python", |
725 | 725 | "metadata": {}, |
|
741 | 741 | "\n", |
742 | 742 | "plt.title(\"Total Regret of Bayesian Bandits Strategy vs. Random guessing\")\n", |
743 | 743 | "plt.xlabel(\"Number of pulls\")\n", |
744 | | - "plt.ylabel(\"Regret after $n$ pulls\")\n", |
| 744 | + "plt.ylabel(\"Regret after $n$ pulls\");\n", |
745 | 745 | "plt.legend(loc=\"upper left\");" |
746 | 746 | ], |
747 | 747 | "language": "python", |
|
795 | 795 | "\n", |
796 | 796 | "plt.title(\"Expected Total Regret of Multi-armed Bandit strategies\")\n", |
797 | 797 | "plt.xlabel(\"Number of pulls\")\n", |
798 | | - "plt.ylabel(\"Exepected Total Regret \\n after $n$ pulls\")\n", |
| 798 | + "plt.ylabel(\"Exepected Total Regret \\n after $n$ pulls\");\n", |
799 | 799 | "plt.legend(loc=\"upper left\");" |
800 | 800 | ], |
801 | 801 | "language": "python", |
|
850 | 850 | "plt.legend([pl1, pl2, pl3],\n", |
851 | 851 | " [\"Upper Credible Bound\", \"Bayesian Bandit\", \"UCB-Bayes\"],\n", |
852 | 852 | " loc=\"upper left\")\n", |
853 | | - "plt.ylabel(\"Exepected Total Regret \\n after $\\log{n}$ pulls\")\n", |
854 | | - "plt.title(\"log-scale of above\")\n", |
| 853 | + "plt.ylabel(\"Exepected Total Regret \\n after $\\log{n}$ pulls\");\n", |
| 854 | + "plt.title(\"log-scale of above\");\n", |
855 | 855 | "plt.ylabel(\"Exepected Total Regret \\n after $\\log{n}$ pulls\");" |
856 | 856 | ], |
857 | 857 | "language": "python", |
|
926 | 926 | " bayesian_strat.sample_bandits(i)\n", |
927 | 927 | " plot_priors(bayesian_strat, hidden_prob, lw=2, alpha=0.0, plt_vlines=False)\n", |
928 | 928 | " # plt.legend()\n", |
929 | | - " plt.xlim(0, 0.5);" |
| 929 | + " plt.xlim(0, 0.5)" |
930 | 930 | ], |
931 | 931 | "language": "python", |
932 | 932 | "metadata": {}, |
|
1044 | 1044 | " plt.title(name + \" prior\")\n", |
1045 | 1045 | " plt.vlines(0, 0, y.max(), \"k\", \"--\", linewidth=0.5)\n", |
1046 | 1046 | " plt.xlim(-0.15, 0.15)\n", |
1047 | | - "plt.tight_layout();" |
| 1047 | + "plt.tight_layout()" |
1048 | 1048 | ], |
1049 | 1049 | "language": "python", |
1050 | 1050 | "metadata": {}, |
|
1081 | 1081 | "prior_std = np.array([x[1] for x in expert_prior_params.values()])\n", |
1082 | 1082 | "\n", |
1083 | 1083 | "inv_cov_matrix = pm.Wishart(\"inv_cov_matrix\", n_observations, np.diag(prior_std ** 2))\n", |
1084 | | - "mu = pm.Normal(\"returns\", prior_mu, 1, size=4);" |
| 1084 | + "mu = pm.Normal(\"returns\", prior_mu, 1, size=4)" |
1085 | 1085 | ], |
1086 | 1086 | "language": "python", |
1087 | 1087 | "metadata": {}, |
|
1122 | 1122 | " _previous_day = np.roll(stock_closes[stock], -1)\n", |
1123 | 1123 | " stock_returns[stock] = ((stock_closes[stock] - _previous_day) / _previous_day)[:n_observations]\n", |
1124 | 1124 | "\n", |
1125 | | - "dates = map(lambda x: datetime.datetime.strptime(x, \"%Y-%m-%d\"), x[1:n_observations + 1, 0]);" |
| 1125 | + "dates = map(lambda x: datetime.datetime.strptime(x, \"%Y-%m-%d\"), x[1:n_observations + 1, 0])" |
1126 | 1126 | ], |
1127 | 1127 | "language": "python", |
1128 | 1128 | "metadata": {}, |
|
1141 | 1141 | "\n", |
1142 | 1142 | "plt.xticks(np.arange(100)[::-8],\n", |
1143 | 1143 | " map(lambda x: datetime.datetime.strftime(x, \"%Y-%m-%d\"), dates[::8]),\n", |
1144 | | - " rotation=60)\n", |
| 1144 | + " rotation=60);\n", |
1145 | 1145 | "\n", |
1146 | 1146 | "plt.legend(loc=\"upper left\")\n", |
1147 | 1147 | "plt.title(\"Return space\")\n", |
|
1210 | 1210 | "model = pm.Model([obs, mu, inv_cov_matrix])\n", |
1211 | 1211 | "mcmc = pm.MCMC()\n", |
1212 | 1212 | "\n", |
1213 | | - "mcmc.sample(150000, 100000, 3);" |
| 1213 | + "mcmc.sample(150000, 100000, 3)" |
1214 | 1214 | ], |
1215 | 1215 | "language": "python", |
1216 | 1216 | "metadata": {}, |
|
1292 | 1292 | " plt.xlim(-0.15, 0.15)\n", |
1293 | 1293 | "\n", |
1294 | 1294 | "plt.suptitle(\"Posterior distribution of daily stock returns\")\n", |
1295 | | - "plt.tight_layout();" |
| 1295 | + "plt.tight_layout()" |
1296 | 1296 | ], |
1297 | 1297 | "language": "python", |
1298 | 1298 | "metadata": {}, |
|
1346 | 1346 | "plt.subplot(1, 2, 2)\n", |
1347 | 1347 | "plt.bar(np.arange(4), np.sqrt(np.diag(mean_covariance_matrix)),\n", |
1348 | 1348 | " color=\"#348ABD\", alpha=0.7)\n", |
1349 | | - "plt.xticks(np.arange(4) + 0.5, stock_returns.keys())\n", |
| 1349 | + "plt.xticks(np.arange(4) + 0.5, stock_returns.keys());\n", |
1350 | 1350 | "plt.title(\"(mean posterior) variances of daily stock returns\")\n", |
1351 | 1351 | "\n", |
1352 | 1352 | "plt.tight_layout();" |
|
1566 | 1566 | " plt.fill_between(x, 0, y2, color=\"#A60628\", alpha=0.15)\n", |
1567 | 1567 | " plt.legend(title=\"N=%d\" % N)\n", |
1568 | 1568 | " plt.vlines(p, 0.0, 7.5, linestyles=\"--\", linewidth=1)\n", |
1569 | | - " #plt.ylim( 0, 10)#;" |
| 1569 | + " #plt.ylim( 0, 10)#" |
1570 | 1570 | ], |
1571 | 1571 | "language": "python", |
1572 | 1572 | "metadata": {}, |
|
1718 | 1718 | "def css_styling():\n", |
1719 | 1719 | " styles = open(\"../styles/custom.css\", \"r\").read()\n", |
1720 | 1720 | " return HTML(styles)\n", |
1721 | | - "css_styling();" |
| 1721 | + "css_styling()" |
1722 | 1722 | ], |
1723 | 1723 | "language": "python", |
1724 | 1724 | "metadata": {}, |
|
0 commit comments