|
194 | 194 | "\n", |
195 | 195 | "# For the already prepared, I'm using Binomial's conj. prior.\n", |
196 | 196 | "for k, N in enumerate(n_trials):\n", |
197 | | - " sx = plt.subplot(len(n_trials)/2, 2, k+1)\n", |
| 197 | + " sx = plt.subplot(len(n_trials) / 2, 2, k + 1)\n", |
198 | 198 | " plt.xlabel(\"$p$, probability of heads\") \\\n", |
199 | | - " if k in [0, len(n_trials)-1] else None\n", |
| 199 | + " if k in [0, len(n_trials) - 1] else None\n", |
200 | 200 | " plt.setp(sx.get_yticklabels(), visible=False)\n", |
201 | 201 | " heads = data[:N].sum()\n", |
202 | 202 | " y = dist.pdf(x, 1 + heads, 1 + N - heads)\n", |
|
286 | 286 | "input": [ |
287 | 287 | "figsize(12.5, 4)\n", |
288 | 288 | "p = np.linspace(0, 1, 50)\n", |
289 | | - "plt.plot(p, 2*p/(1+p), color=\"#348ABD\", lw=3)\n", |
290 | | - "#plt.fill_between(p, 2*p/(1+p), alpha=.5, facecolor=[\"#A60628\"])\n", |
291 | | - "plt.scatter(0.2, 2*(0.2)/1.2, s=140, c=\"#348ABD\")\n", |
| 289 | + "plt.plot(p, 2 * p / (1 + p), color=\"#348ABD\", lw=3)\n", |
| 290 | + "# plt.fill_between(p, 2*p/(1+p), alpha=.5, facecolor=[\"#A60628\"])\n", |
| 291 | + "plt.scatter(0.2, 2 * (0.2) / 1.2, s=140, c=\"#348ABD\")\n", |
292 | 292 | "plt.xlim(0, 1)\n", |
293 | 293 | "plt.ylim(0, 1)\n", |
294 | 294 | "plt.xlabel(\"Prior, $P(A) = p$\")\n", |
|
336 | 336 | "colours = [\"#348ABD\", \"#A60628\"]\n", |
337 | 337 | "\n", |
338 | 338 | "prior = [0.20, 0.80]\n", |
339 | | - "posterior = [1./3, 2./3]\n", |
| 339 | + "posterior = [1. / 3, 2. / 3]\n", |
340 | 340 | "plt.bar([0, .7], prior, alpha=0.70, width=0.25,\n", |
341 | 341 | " color=colours[0], label=\"prior distribution\",\n", |
342 | 342 | " lw=\"3\", edgecolor=colours[0])\n", |
343 | 343 | "\n", |
344 | | - "plt.bar([0+0.25, .7+0.25], posterior, alpha=0.7,\n", |
| 344 | + "plt.bar([0 + 0.25, .7 + 0.25], posterior, alpha=0.7,\n", |
345 | 345 | " width=0.25, color=colours[1],\n", |
346 | 346 | " label=\"posterior distribution\",\n", |
347 | 347 | " lw=\"3\", edgecolor=colours[1])\n", |
|
491 | 491 | "lambda_ = [0.5, 1]\n", |
492 | 492 | "\n", |
493 | 493 | "for l, c in zip(lambda_, colours):\n", |
494 | | - " plt.plot(a, expo.pdf(a, scale=1./l), lw=3,\n", |
| 494 | + " plt.plot(a, expo.pdf(a, scale=1. / l), lw=3,\n", |
495 | 495 | " color=c, label=\"$\\lambda = %.1f$\" % l)\n", |
496 | | - " plt.fill_between(a, expo.pdf(a, scale=1./l), color=c, alpha=.33)\n", |
| 496 | + " plt.fill_between(a, expo.pdf(a, scale=1. / l), color=c, alpha=.33)\n", |
497 | 497 | "\n", |
498 | 498 | "plt.legend()\n", |
499 | 499 | "plt.ylabel(\"PDF at $z$\")\n", |
500 | 500 | "plt.xlabel(\"$z$\")\n", |
501 | | - "plt.ylim(0,1.2)\n", |
| 501 | + "plt.ylim(0, 1.2)\n", |
502 | 502 | "plt.title(\"Probability density function of an Exponential random variable;\\\n", |
503 | 503 | " differing $\\lambda$\");" |
504 | 504 | ], |
|
642 | 642 | "input": [ |
643 | 643 | "import pymc as pm\n", |
644 | 644 | "\n", |
645 | | - "alpha = 1.0/count_data.mean() # Recall count_data is the\n", |
| 645 | + "alpha = 1.0 / count_data.mean() # Recall count_data is the\n", |
646 | 646 | " # variable that holds our txt counts\n", |
647 | 647 | "lambda_1 = pm.Exponential(\"lambda_1\", alpha)\n", |
648 | 648 | "lambda_2 = pm.Exponential(\"lambda_2\", alpha)\n", |
|
731 | 731 | "cell_type": "code", |
732 | 732 | "collapsed": false, |
733 | 733 | "input": [ |
734 | | - "### Mysterious code to be explained in Chapter 3.\n", |
| 734 | + "# Mysterious code to be explained in Chapter 3.\n", |
735 | 735 | "mcmc = pm.MCMC(model)\n", |
736 | 736 | "mcmc.sample(40000, 10000, 1)" |
737 | 737 | ], |
|
774 | 774 | "collapsed": false, |
775 | 775 | "input": [ |
776 | 776 | "figsize(12.5, 10)\n", |
777 | | - "#histogram of the samples:\n", |
| 777 | + "# histogram of the samples:\n", |
778 | 778 | "\n", |
779 | 779 | "ax = plt.subplot(311)\n", |
780 | 780 | "ax.set_autoscaley_on(False)\n", |
|
804 | 804 | "\n", |
805 | 805 | "plt.legend(loc=\"upper left\")\n", |
806 | 806 | "plt.ylim([0, .75])\n", |
807 | | - "plt.xlim([35, len(count_data)-20])\n", |
| 807 | + "plt.xlim([35, len(count_data) - 20])\n", |
808 | 808 | "plt.xlabel(r\"$\\tau$ (in days)\")\n", |
809 | 809 | "plt.ylabel(\"probability\");" |
810 | 810 | ], |
|
923 | 923 | "cell_type": "code", |
924 | 924 | "collapsed": false, |
925 | 925 | "input": [ |
926 | | - "#type your code here." |
| 926 | + "# type your code here." |
927 | 927 | ], |
928 | 928 | "language": "python", |
929 | 929 | "metadata": {}, |
|
941 | 941 | "cell_type": "code", |
942 | 942 | "collapsed": false, |
943 | 943 | "input": [ |
944 | | - "#type your code here." |
| 944 | + "# type your code here." |
945 | 945 | ], |
946 | 946 | "language": "python", |
947 | 947 | "metadata": {}, |
|
959 | 959 | "cell_type": "code", |
960 | 960 | "collapsed": false, |
961 | 961 | "input": [ |
962 | | - "#type your code here." |
| 962 | + "# type your code here." |
963 | 963 | ], |
964 | 964 | "language": "python", |
965 | 965 | "metadata": {}, |
|
987 | 987 | "collapsed": false, |
988 | 988 | "input": [ |
989 | 989 | "from IPython.core.display import HTML\n", |
| 990 | + "\n", |
| 991 | + "\n", |
990 | 992 | "def css_styling():\n", |
991 | 993 | " styles = open(\"../styles/custom.css\", \"r\").read()\n", |
992 | 994 | " return HTML(styles)\n", |
|
0 commit comments