Skip to content

Commit 78c8671

Browse files
committed
Not adding or removing semicolons, and a fixed a typo
1 parent 6a4c4d5 commit 78c8671

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

Chapter4_TheGreatestTheoremNeverTold/LawOfLargeNumbers.ipynb

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"\n",
108108
"plt.ylim(4.35, 4.65)\n",
109109
"plt.title(\"Convergence of the average of \\n random variables to its \\\n",
110-
"expected value\" )\n",
110+
"expected value\")\n",
111111
"plt.ylabel(\"average of $n$ samples\")\n",
112112
"plt.xlabel(\"# of samples, $n$\")\n",
113113
"plt.legend();"
@@ -156,8 +156,7 @@
156156
"figsize(12.5, 4)\n",
157157
"\n",
158158
"N_Y = 250 # use this many to approximate D(N)\n",
159-
"# use this many samples in the approx. to the variance.\n",
160-
"N_array = np.arange(1000, 50000, 2500)\n",
159+
"N_array = np.arange(1000, 50000, 2500) # use this many samples in the approx. to the variance.\n",
161160
"D_N_results = np.zeros(len(N_array))\n",
162161
"\n",
163162
"lambda_ = 4.5\n",
@@ -244,7 +243,7 @@
244243
"input": [
245244
"import pymc as pm\n",
246245
"N = 10000\n",
247-
"print np.mean([pm.rexponential(0.5) > 10 for i in range(N)]);"
246+
"print np.mean([pm.rexponential(0.5) > 10 for i in range(N)])"
248247
],
249248
"language": "python",
250249
"metadata": {},
@@ -366,7 +365,7 @@
366365
"print population[np.argsort(average_across_county)[:10]]\n",
367366
"print\n",
368367
"print \"Population sizes of 10 'tallest' counties: \"\n",
369-
"print population[np.argsort(-average_across_county)[:10]];"
368+
"print population[np.argsort(-average_across_county)[:10]]"
370369
],
371370
"language": "python",
372371
"metadata": {},
@@ -498,7 +497,7 @@
498497
"# adding a number to the end of the %run call with get the ith top photo.\n",
499498
"%run top_pic_comments.py 2\n",
500499
"\n",
501-
"Image(top_post_url);"
500+
"Image(top_post_url)"
502501
],
503502
"language": "python",
504503
"metadata": {},
@@ -537,7 +536,7 @@
537536
"for i in comments:\n",
538537
" print '\"' + contents[i] + '\"'\n",
539538
" print\"upvotes/downvotes: \", votes[i, :]\n",
540-
" print;"
539+
" print"
541540
],
542541
"language": "python",
543542
"metadata": {},
@@ -581,22 +580,17 @@
581580
"\n",
582581
"def posterior_upvote_ratio(upvotes, downvotes, samples=20000):\n",
583582
" \"\"\"\n",
584-
" This function accepts the number of upvotes and downvotes a particular comment recieved,\n",
583+
" This function accepts the number of upvotes and downvotes a particular comment received, \n",
585584
" and the number of posterior samples to return to the user. Assumes a uniform prior.\n",
586585
" \"\"\"\n",
587586
" N = upvotes + downvotes\n",
588587
" upvote_ratio = pm.Uniform(\"upvote_ratio\", 0, 1)\n",
589-
" observations = pm.Binomial(\n",
590-
" \"obs\",\n",
591-
" N,\n",
592-
" upvote_ratio,\n",
593-
" value=upvotes,\n",
594-
" observed=True)\n",
588+
" observations = pm.Binomial(\"obs\", N, upvote_ratio, value=upvotes, observed=True)\n",
595589
" # do the fitting; first do a MAP as it is cheap and useful.\n",
596590
" map_ = pm.MAP([upvote_ratio, observations]).fit()\n",
597591
" mcmc = pm.MCMC([upvote_ratio, observations])\n",
598592
" mcmc.sample(samples, samples / 4)\n",
599-
" return mcmc.trace(\"upvote_ratio\")[:];"
593+
" return mcmc.trace(\"upvote_ratio\")[:]"
600594
],
601595
"language": "python",
602596
"metadata": {},
@@ -687,15 +681,15 @@
687681
" plt.hist(posteriors[i], bins=20, normed=True, alpha=.2,\n",
688682
" histtype=\"stepfilled\", color=colours[i], lw=3, )\n",
689683
" v = np.sort(posteriors[i])[int(0.05 * N)]\n",
690-
" #plt.vlines(v, 0, 15 , color = \"k\", alpha = 1, linewidths=3 )\n",
684+
" # plt.vlines( v, 0, 15 , color = \"k\", alpha = 1, linewidths=3 )\n",
691685
" plt.vlines(v, 0, 10, color=colours[i], linestyles=\"--\", linewidths=3)\n",
692686
" lower_limits.append(v)\n",
693687
" plt.legend(loc=\"upper left\")\n",
694688
"\n",
695689
"plt.legend(loc=\"upper left\")\n",
696-
"plt.title(\"Posterior distributions of upvote ratios on different comments\")\n",
690+
"plt.title(\"Posterior distributions of upvote ratios on different comments\");\n",
697691
"order = np.argsort(-np.array(lower_limits))\n",
698-
"print order, lower_limits;"
692+
"print order, lower_limits"
699693
],
700694
"language": "python",
701695
"metadata": {},
@@ -767,7 +761,7 @@
767761
"for i in order[:40]:\n",
768762
" ordered_contents.append(contents[i])\n",
769763
" print votes[i, 0], votes[i, 1], contents[i]\n",
770-
" print \"-------------\";"
764+
" print \"-------------\""
771765
],
772766
"language": "python",
773767
"metadata": {},
@@ -905,8 +899,7 @@
905899
" xerr=std_err[r_order], xuplims=True, capsize=0, fmt=\"o\",\n",
906900
" color=\"#7A68A6\")\n",
907901
"plt.xlim(0.3, 1)\n",
908-
"plt.yticks(np.arange(len(r_order) - 1, -1, -1),\n",
909-
" map(lambda x: x[:30].replace(\"\\n\", \"\"), ordered_contents));"
902+
"plt.yticks(np.arange(len(r_order) - 1, -1, -1), map(lambda x: x[:30].replace(\"\\n\", \"\"), ordered_contents));"
910903
],
911904
"language": "python",
912905
"metadata": {},
@@ -1020,7 +1013,7 @@
10201013
"exp = stats.expon(scale=4)\n",
10211014
"N = 1e5\n",
10221015
"X = exp.rvs(N)\n",
1023-
"# ...;"
1016+
"# ..."
10241017
],
10251018
"language": "python",
10261019
"metadata": {},
@@ -1101,7 +1094,7 @@
11011094
"def css_styling():\n",
11021095
" styles = open(\"../styles/custom.css\", \"r\").read()\n",
11031096
" return HTML(styles)\n",
1104-
"css_styling();"
1097+
"css_styling()"
11051098
],
11061099
"language": "python",
11071100
"metadata": {},

0 commit comments

Comments
 (0)