| 
215 | 215 |       "                       label=\"Trip price guess\")\n",  | 
216 | 216 |       "plt.autoscale(tight=True)\n",  | 
217 | 217 |       "p3 = plt.Rectangle((0, 0), 1, 1, fc=sp3.get_facecolor()[0])\n",  | 
218 |  | -      "plt.legend([p3], [sp3.get_label()])\n"  | 
 | 218 | +      "plt.legend([p3], [sp3.get_label()]);"  | 
219 | 219 |      ],  | 
220 | 220 |      "language": "python",  | 
221 | 221 |      "metadata": {},  | 
 | 
260 | 260 |       "mcmc = pm.MCMC([true_price, prize_1, prize_2, price_estimate, error])\n",  | 
261 | 261 |       "mcmc.sample(50000, 10000)\n",  | 
262 | 262 |       "\n",  | 
263 |  | -      "price_trace = mcmc.trace(\"true_price\")[:]\n"  | 
 | 263 | +      "price_trace = mcmc.trace(\"true_price\")[:];"  | 
264 | 264 |      ],  | 
265 | 265 |      "language": "python",  | 
266 | 266 |      "metadata": {},  | 
 | 
300 | 300 |       "plt.vlines(mu_prior, 0, 1.1 * np.max(_hist[0]), label=\"prior's mean\",\n",  | 
301 | 301 |       "           linestyles=\"--\")\n",  | 
302 | 302 |       "plt.vlines(price_trace.mean(), 0, 1.1 * np.max(_hist[0]), label=\"posterior's mean\", linestyles=\"-.\")\n",  | 
303 |  | -      "plt.legend(loc=\"upper left\")\n"  | 
 | 303 | +      "plt.legend(loc=\"upper left\");"  | 
304 | 304 |      ],  | 
305 | 305 |      "language": "python",  | 
306 | 306 |      "metadata": {},  | 
 | 
381 | 381 |       "plt.legend(loc=\"upper left\", title=\"Risk parameter\")\n",  | 
382 | 382 |       "plt.xlabel(\"price bid\")\n",  | 
383 | 383 |       "plt.ylabel(\"expected loss\")\n",  | 
384 |  | -      "plt.xlim(5000, 30000)\n"  | 
 | 384 | +      "plt.xlim(5000, 30000);"  | 
385 | 385 |      ],  | 
386 | 386 |      "language": "python",  | 
387 | 387 |      "metadata": {},  | 
 | 
434 | 434 |       "plt.xlabel(\"price guess\")\n",  | 
435 | 435 |       "plt.ylabel(\"expected loss\")\n",  | 
436 | 436 |       "plt.xlim(7000, 30000)\n",  | 
437 |  | -      "plt.ylim(-1000, 80000)\n"  | 
 | 437 | +      "plt.ylim(-1000, 80000);"  | 
438 | 438 |      ],  | 
439 | 439 |      "language": "python",  | 
440 | 440 |      "metadata": {},  | 
 | 
594 | 594 |       "true_value = -.02\n",  | 
595 | 595 |       "plt.plot(pred, [stock_loss(true_value, _p) for _p in pred], alpha=0.6, label=\"Loss associated with\\n prediction if true value=-0.02\", lw=3)\n",  | 
596 | 596 |       "plt.legend()\n",  | 
597 |  | -      "plt.title(\"Stock returns loss if true value=0.05, -0.02\")\n"  | 
 | 597 | +      "plt.title(\"Stock returns loss if true value=0.05, -0.02\");"  | 
598 | 598 |      ],  | 
599 | 599 |      "language": "python",  | 
600 | 600 |      "metadata": {},  | 
 | 
642 | 642 |       "plt.plot(X, ls_coef_ * X + ls_intercept, label=\"Least-squares line\")\n",  | 
643 | 643 |       "plt.xlim(X.min(), X.max())\n",  | 
644 | 644 |       "plt.ylim(Y.min(), Y.max())\n",  | 
645 |  | -      "plt.legend(loc=\"upper left\")\n"  | 
 | 645 | +      "plt.legend(loc=\"upper left\");"  | 
646 | 646 |      ],  | 
647 | 647 |      "language": "python",  | 
648 | 648 |      "metadata": {},  | 
 | 
695 | 695 |       "mcmc = pm.MCMC([obs, beta, alpha, std, prec])\n",  | 
696 | 696 |       "\n",  | 
697 | 697 |       "mcmc.sample(100000, 80000)\n",  | 
698 |  | -      "mcplot(mcmc)\n"  | 
 | 698 | +      "mcplot(mcmc);"  | 
699 | 699 |      ],  | 
700 | 700 |      "language": "python",  | 
701 | 701 |      "metadata": {},  | 
 | 
783 | 783 |       "figsize(12.5, 6)\n",  | 
784 | 784 |       "from scipy.optimize import fmin\n",  | 
785 | 785 |       "\n",  | 
 | 786 | +      "\n",  | 
786 | 787 |       "def stock_loss(price, pred, coef=500):\n",  | 
787 | 788 |       "    \"\"\"vectorized for numpy\"\"\"\n",  | 
788 | 789 |       "    sol = np.zeros_like(price)\n",  | 
 | 
816 | 817 |       "plt.plot(X, ls_coef_ * X + ls_intercept, label=\"Least-squares prediction\")\n",  | 
817 | 818 |       "plt.xlim(X.min(), X.max())\n",  | 
818 | 819 |       "plt.plot(trading_signals, opt_predictions, label=\"Bayes action prediction\")\n",  | 
819 |  | -      "plt.legend(loc=\"upper left\")\n"  | 
 | 820 | +      "plt.legend(loc=\"upper left\");"  | 
820 | 821 |      ],  | 
821 | 822 |      "language": "python",  | 
822 | 823 |      "metadata": {},  | 
 | 
905 | 906 |       "fig = draw_sky(data)\n",  | 
906 | 907 |       "plt.title(\"Galaxy positions and ellipcities of sky %d.\" % n_sky)\n",  | 
907 | 908 |       "plt.xlabel(\"x-position\")\n",  | 
908 |  | -      "plt.ylabel(\"y-position\")\n"  | 
 | 909 | +      "plt.ylabel(\"y-position\");"  | 
909 | 910 |      ],  | 
910 | 911 |      "language": "python",  | 
911 | 912 |      "metadata": {},  | 
 | 
1012 | 1013 |       "\n",  | 
1013 | 1014 |       "@pm.deterministic\n",  | 
1014 | 1015 |       "def mean(mass=mass_large, h_pos=halo_position, glx_pos=data[:, :2]):\n",  | 
1015 |  | -      "    return mass / f_distance(glx_pos, h_pos, 240) * tangential_distance(glx_pos, h_pos)\n"  | 
 | 1016 | +      "    return mass / f_distance(glx_pos, h_pos, 240) * tangential_distance(glx_pos, h_pos);"  | 
1016 | 1017 |      ],  | 
1017 | 1018 |      "language": "python",  | 
1018 | 1019 |      "metadata": {},  | 
 | 
1028 | 1029 |       "mcmc = pm.MCMC([ellpty, mean, halo_position, mass_large])\n",  | 
1029 | 1030 |       "map_ = pm.MAP([ellpty, mean, halo_position, mass_large])\n",  | 
1030 | 1031 |       "map_.fit()\n",  | 
1031 |  | -      "mcmc.sample(200000, 140000, 3)\n"  | 
 | 1032 | +      "mcmc.sample(200000, 140000, 3);"  | 
1032 | 1033 |      ],  | 
1033 | 1034 |      "language": "python",  | 
1034 | 1035 |      "metadata": {},  | 
 | 
1070 | 1071 |       "plt.ylabel(\"y-position\")\n",  | 
1071 | 1072 |       "scatter(t[:, 0], t[:, 1], alpha=0.015, c=\"r\")\n",  | 
1072 | 1073 |       "plt.xlim(0, 4200)\n",  | 
1073 |  | -      "plt.ylim(0, 4200)\n"  | 
 | 1074 | +      "plt.ylim(0, 4200);"  | 
1074 | 1075 |      ],  | 
1075 | 1076 |      "language": "python",  | 
1076 | 1077 |      "metadata": {},  | 
 | 
1099 | 1100 |       "                          delimiter=\",\",\n",  | 
1100 | 1101 |       "                          usecols=[1, 2, 3, 4, 5, 6, 7, 8, 9],\n",  | 
1101 | 1102 |       "                          skip_header=1)\n",  | 
1102 |  | -      "print halo_data[n_sky]\n"  | 
 | 1103 | +      "print halo_data[n_sky];"  | 
1103 | 1104 |      ],  | 
1104 | 1105 |      "language": "python",  | 
1105 | 1106 |      "metadata": {},  | 
 | 
1139 | 1140 |       "plt.xlim(0, 4200)\n",  | 
1140 | 1141 |       "plt.ylim(0, 4200)\n",  | 
1141 | 1142 |       "\n",  | 
1142 |  | -      "print \"True halo location:\", halo_data[n_sky][3], halo_data[n_sky][4]\n"  | 
 | 1143 | +      "print \"True halo location:\", halo_data[n_sky][3], halo_data[n_sky][4];"  | 
1143 | 1144 |      ],  | 
1144 | 1145 |      "language": "python",  | 
1145 | 1146 |      "metadata": {},  | 
 | 
1170 | 1171 |      "collapsed": false,  | 
1171 | 1172 |      "input": [  | 
1172 | 1173 |       "mean_posterior = t.mean(axis=0).reshape(1, 2)\n",  | 
1173 |  | -      "print mean_posterior\n"  | 
 | 1174 | +      "print mean_posterior;"  | 
1174 | 1175 |      ],  | 
1175 | 1176 |      "language": "python",  | 
1176 | 1177 |      "metadata": {},  | 
 | 
1208 | 1209 |       "random_guess = np.random.randint(0, 4200, size=(1, 2))\n",  | 
1209 | 1210 |       "print \"Using a random location:\", random_guess\n",  | 
1210 | 1211 |       "main_score(nhalo_all, x_true_all, y_true_all, x_ref_all, y_ref_all, random_guess)\n",  | 
1211 |  | -      "print\n"  | 
 | 1212 | +      "print;"  | 
1212 | 1213 |      ],  | 
1213 | 1214 |      "language": "python",  | 
1214 | 1215 |      "metadata": {},  | 
 | 
1307 | 1308 |       "\n",  | 
1308 | 1309 |       "    mcmc = pm.MCMC([ellpty, mean, halo_positions, mass_large])\n",  | 
1309 | 1310 |       "    mcmc.sample(samples, burn_in, thin)\n",  | 
1310 |  | -      "    return mcmc.trace(\"halo_positions\")[:]\n"  | 
 | 1311 | +      "    return mcmc.trace(\"halo_positions\")[:];"  | 
1311 | 1312 |      ],  | 
1312 | 1313 |      "language": "python",  | 
1313 | 1314 |      "metadata": {},  | 
 | 
1323 | 1324 |       "                     dtype=None,\n",  | 
1324 | 1325 |       "                     skip_header=1,\n",  | 
1325 | 1326 |       "                     delimiter=\",\",\n",  | 
1326 |  | -      "                     usecols=[1, 2, 3, 4])\n"  | 
 | 1327 | +      "                     usecols=[1, 2, 3, 4]);"  | 
1327 | 1328 |      ],  | 
1328 | 1329 |      "language": "python",  | 
1329 | 1330 |      "metadata": {},  | 
 | 
1338 | 1339 |       "samples = 10.5e5\n",  | 
1339 | 1340 |       "traces = halo_posteriors(3, data, samples=samples,\n",  | 
1340 | 1341 |       "                         burn_in=9.5e5,\n",  | 
1341 |  | -      "                         thin=10)\n"  | 
 | 1342 | +      "                         thin=10);"  | 
1342 | 1343 |      ],  | 
1343 | 1344 |      "language": "python",  | 
1344 | 1345 |      "metadata": {},  | 
 | 
1383 | 1384 |       "\n",  | 
1384 | 1385 |       "# plt.legend(scatterpoints=1)\n",  | 
1385 | 1386 |       "plt.xlim(0, 4200)\n",  | 
1386 |  | -      "plt.ylim(0, 4200)\n"  | 
 | 1387 | +      "plt.ylim(0, 4200);"  | 
1387 | 1388 |      ],  | 
1388 | 1389 |      "language": "python",  | 
1389 | 1390 |      "metadata": {},  | 
 | 
1434 | 1435 |       "random_guess = np.random.randint(0, 4200, size=(1, 2))\n",  | 
1435 | 1436 |       "print \"Using a random location:\", random_guess\n",  | 
1436 | 1437 |       "main_score([1], x_true_all, y_true_all, x_ref_all, y_ref_all, random_guess)\n",  | 
1437 |  | -      "print\n"  | 
 | 1438 | +      "print;"  | 
1438 | 1439 |      ],  | 
1439 | 1440 |      "language": "python",  | 
1440 | 1441 |      "metadata": {},  | 
 | 
1514 | 1515 |       "def css_styling():\n",  | 
1515 | 1516 |       "    styles = open(\"../styles/custom.css\", \"r\").read()\n",  | 
1516 | 1517 |       "    return HTML(styles)\n",  | 
1517 |  | -      "css_styling()\n"  | 
 | 1518 | +      "css_styling();"  | 
1518 | 1519 |      ],  | 
1519 | 1520 |      "language": "python",  | 
1520 | 1521 |      "metadata": {},  | 
 | 
0 commit comments