Skip to content

Commit 8f0e05f

Browse files
committed
Merge branch 'cam-master' into examples-style
Conflicts: ExamplesFromChapters/Chapter3/ClusteringWithGaussians.py
2 parents 9b230ff + 1e55d2d commit 8f0e05f

File tree

8 files changed

+1037
-946
lines changed

8 files changed

+1037
-946
lines changed

Chapter1_Introduction/Chapter1_Introduction.ipynb

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@
194194
"\n",
195195
"# For the already prepared, I'm using Binomial's conj. prior.\n",
196196
"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",
198198
" 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",
200200
" plt.setp(sx.get_yticklabels(), visible=False)\n",
201201
" heads = data[:N].sum()\n",
202202
" y = dist.pdf(x, 1 + heads, 1 + N - heads)\n",
@@ -213,7 +213,7 @@
213213
" y=1.02,\n",
214214
" fontsize=14)\n",
215215
"\n",
216-
"plt.tight_layout();"
216+
"plt.tight_layout()"
217217
],
218218
"language": "python",
219219
"metadata": {},
@@ -286,14 +286,14 @@
286286
"input": [
287287
"figsize(12.5, 4)\n",
288288
"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",
292292
"plt.xlim(0, 1)\n",
293293
"plt.ylim(0, 1)\n",
294294
"plt.xlabel(\"Prior, $P(A) = p$\")\n",
295295
"plt.ylabel(\"Posterior, $P(A|X)$, with $P(A) = p$\")\n",
296-
"plt.title(\"Are there bugs in my code?\");"
296+
"plt.title(\"Are there bugs in my code?\")"
297297
],
298298
"language": "python",
299299
"metadata": {},
@@ -336,12 +336,12 @@
336336
"colours = [\"#348ABD\", \"#A60628\"]\n",
337337
"\n",
338338
"prior = [0.20, 0.80]\n",
339-
"posterior = [1. / 3, 2. / 3]\n",
339+
"posterior = [1./3, 2./3]\n",
340340
"plt.bar([0, .7], prior, alpha=0.70, width=0.25,\n",
341341
" color=colours[0], label=\"prior distribution\",\n",
342342
" lw=\"3\", edgecolor=colours[0])\n",
343343
"\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",
345345
" width=0.25, color=colours[1],\n",
346346
" label=\"posterior distribution\",\n",
347347
" lw=\"3\", edgecolor=colours[1])\n",
@@ -438,7 +438,7 @@
438438
"plt.ylabel(\"probability of $k$\")\n",
439439
"plt.xlabel(\"$k$\")\n",
440440
"plt.title(\"Probability mass function of a Poisson random variable; differing \\\n",
441-
"$\\lambda$ values\");"
441+
"$\\lambda$ values\")"
442442
],
443443
"language": "python",
444444
"metadata": {},
@@ -491,14 +491,14 @@
491491
"lambda_ = [0.5, 1]\n",
492492
"\n",
493493
"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",
495495
" 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",
497497
"\n",
498498
"plt.legend()\n",
499499
"plt.ylabel(\"PDF at $z$\")\n",
500500
"plt.xlabel(\"$z$\")\n",
501-
"plt.ylim(0, 1.2)\n",
501+
"plt.ylim(0,1.2)\n",
502502
"plt.title(\"Probability density function of an Exponential random variable;\\\n",
503503
" differing $\\lambda$\");"
504504
],
@@ -642,12 +642,12 @@
642642
"input": [
643643
"import pymc as pm\n",
644644
"\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",
646646
" # variable that holds our txt counts\n",
647647
"lambda_1 = pm.Exponential(\"lambda_1\", alpha)\n",
648648
"lambda_2 = pm.Exponential(\"lambda_2\", alpha)\n",
649649
"\n",
650-
"tau = pm.DiscreteUniform(\"tau\", lower=0, upper=n_count_data);"
650+
"tau = pm.DiscreteUniform(\"tau\", lower=0, upper=n_count_data)"
651651
],
652652
"language": "python",
653653
"metadata": {},
@@ -665,7 +665,7 @@
665665
"cell_type": "code",
666666
"collapsed": false,
667667
"input": [
668-
"print \"Random output:\", tau.random(), tau.random(), tau.random();"
668+
"print \"Random output:\", tau.random(), tau.random(), tau.random()"
669669
],
670670
"language": "python",
671671
"metadata": {},
@@ -689,7 +689,7 @@
689689
" out = np.zeros(n_count_data)\n",
690690
" out[:tau] = lambda_1 # lambda before tau is lambda1\n",
691691
" out[tau:] = lambda_2 # lambda after (and including) tau is lambda2\n",
692-
" return out;"
692+
" return out"
693693
],
694694
"language": "python",
695695
"metadata": {},
@@ -711,7 +711,7 @@
711711
"input": [
712712
"observation = pm.Poisson(\"obs\", lambda_, value=count_data, observed=True)\n",
713713
"\n",
714-
"model = pm.Model([observation, lambda_1, lambda_2, tau]);"
714+
"model = pm.Model([observation, lambda_1, lambda_2, tau])"
715715
],
716716
"language": "python",
717717
"metadata": {},
@@ -731,9 +731,9 @@
731731
"cell_type": "code",
732732
"collapsed": false,
733733
"input": [
734-
"# Mysterious code to be explained in Chapter 3.\n",
734+
"### Mysterious code to be explained in Chapter 3.\n",
735735
"mcmc = pm.MCMC(model)\n",
736-
"mcmc.sample(40000, 10000, 1);"
736+
"mcmc.sample(40000, 10000, 1)"
737737
],
738738
"language": "python",
739739
"metadata": {},
@@ -762,7 +762,7 @@
762762
"input": [
763763
"lambda_1_samples = mcmc.trace('lambda_1')[:]\n",
764764
"lambda_2_samples = mcmc.trace('lambda_2')[:]\n",
765-
"tau_samples = mcmc.trace('tau')[:];"
765+
"tau_samples = mcmc.trace('tau')[:]"
766766
],
767767
"language": "python",
768768
"metadata": {},
@@ -774,7 +774,7 @@
774774
"collapsed": false,
775775
"input": [
776776
"figsize(12.5, 10)\n",
777-
"# histogram of the samples:\n",
777+
"#histogram of the samples:\n",
778778
"\n",
779779
"ax = plt.subplot(311)\n",
780780
"ax.set_autoscaley_on(False)\n",
@@ -804,7 +804,7 @@
804804
"\n",
805805
"plt.legend(loc=\"upper left\")\n",
806806
"plt.ylim([0, .75])\n",
807-
"plt.xlim([35, len(count_data) - 20])\n",
807+
"plt.xlim([35, len(count_data)-20])\n",
808808
"plt.xlabel(r\"$\\tau$ (in days)\")\n",
809809
"plt.ylabel(\"probability\");"
810810
],
@@ -923,7 +923,7 @@
923923
"cell_type": "code",
924924
"collapsed": false,
925925
"input": [
926-
"# type your code here.;"
926+
"#type your code here."
927927
],
928928
"language": "python",
929929
"metadata": {},
@@ -941,7 +941,7 @@
941941
"cell_type": "code",
942942
"collapsed": false,
943943
"input": [
944-
"# type your code here.;"
944+
"#type your code here."
945945
],
946946
"language": "python",
947947
"metadata": {},
@@ -959,7 +959,7 @@
959959
"cell_type": "code",
960960
"collapsed": false,
961961
"input": [
962-
"# type your code here.;"
962+
"#type your code here."
963963
],
964964
"language": "python",
965965
"metadata": {},
@@ -973,7 +973,7 @@
973973
"### References\n",
974974
"\n",
975975
"\n",
976-
"- [1] Gelman, Andrew. N.p.. Web. 22 Jan 2013. [N is never large enough](http://andrewgelman.com/2005/07/n_is_never_large).\n",
976+
"- [1] Gelman, Andrew. N.p.. Web. 22 Jan 2013. [N is never large enough](http://andrewgelman.com/2005/07/31/n_is_never_larg/).\n",
977977
"- [2] Norvig, Peter. 2009. [The Unreasonable Effectiveness of Data](http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/35179.pdf).\n",
978978
"- [3] Patil, A., D. Huard and C.J. Fonnesbeck. 2010. \n",
979979
"PyMC: Bayesian Stochastic Modelling in Python. Journal of Statistical \n",
@@ -987,12 +987,10 @@
987987
"collapsed": false,
988988
"input": [
989989
"from IPython.core.display import HTML\n",
990-
"\n",
991-
"\n",
992990
"def css_styling():\n",
993991
" styles = open(\"../styles/custom.css\", \"r\").read()\n",
994992
" return HTML(styles)\n",
995-
"css_styling();"
993+
"css_styling()"
996994
],
997995
"language": "python",
998996
"metadata": {},
@@ -1004,6 +1002,22 @@
10041002
" font-family: \"Computer Modern\";\n",
10051003
" src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunss.otf');\n",
10061004
" }\n",
1005+
" @font-face {\n",
1006+
" font-family: \"Computer Modern\";\n",
1007+
" font-weight: bold;\n",
1008+
" src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsx.otf');\n",
1009+
" }\n",
1010+
" @font-face {\n",
1011+
" font-family: \"Computer Modern\";\n",
1012+
" font-style: oblique;\n",
1013+
" src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsi.otf');\n",
1014+
" }\n",
1015+
" @font-face {\n",
1016+
" font-family: \"Computer Modern\";\n",
1017+
" font-weight: bold;\n",
1018+
" font-style: oblique;\n",
1019+
" src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunso.otf');\n",
1020+
" }\n",
10071021
" div.cell{\n",
10081022
" width:800px;\n",
10091023
" margin-left:16% !important;\n",
@@ -1043,13 +1057,28 @@
10431057
" .warning{\n",
10441058
" color: rgb( 240, 20, 20 )\n",
10451059
" } \n",
1046-
"</style>\n"
1060+
"</style>\n",
1061+
"<script>\n",
1062+
" MathJax.Hub.Config({\n",
1063+
" TeX: {\n",
1064+
" extensions: [\"AMSmath.js\"]\n",
1065+
" },\n",
1066+
" tex2jax: {\n",
1067+
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
1068+
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
1069+
" },\n",
1070+
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
1071+
" \"HTML-CSS\": {\n",
1072+
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
1073+
" }\n",
1074+
" });\n",
1075+
"</script>\n"
10471076
],
10481077
"metadata": {},
10491078
"output_type": "pyout",
10501079
"prompt_number": 1,
10511080
"text": [
1052-
"<IPython.core.display.HTML at 0x10f034850>"
1081+
"<IPython.core.display.HTML at 0x103dff550>"
10531082
]
10541083
}
10551084
],

0 commit comments

Comments
 (0)