Skip to content

Commit

Permalink
fix typos in notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jakevdp committed Jan 5, 2016
1 parent e02b458 commit 7c22fbc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
10 changes: 5 additions & 5 deletions 02-Simple-Bayesian-Modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"source": [
"def make_data(intercept, slope, N=20, dy=5, rseed=42):\n",
" rand = np.random.RandomState(rseed)\n",
" x = 100 * rand.rand(20)\n",
" x = 100 * rand.rand(N)\n",
" y = intercept + slope * x\n",
" y += dy * rand.randn(20)\n",
" y += dy * rand.randn(N)\n",
" return x, y, dy * np.ones_like(x)\n",
"\n",
"theta_true = [25, 0.5]\n",
Expand Down Expand Up @@ -225,9 +225,9 @@
},
"outputs": [],
"source": [
"x = np.linspace(-1, 1)\n",
"xx = np.linspace(-1, 1)\n",
"for slope in np.linspace(0, 20, 100):\n",
" plt.plot(x, slope * x, '-k', linewidth=1)\n",
" plt.plot(xx, slope * xx, '-k', linewidth=1)\n",
"plt.axis([-1, 1, -1, 1], aspect='equal');"
]
},
Expand Down Expand Up @@ -329,7 +329,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": []
Expand Down
9 changes: 5 additions & 4 deletions 03-Bayesian-Modeling-With-MCMC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"\n",
"There are several good Python approaches to Bayesian computation with MCMC. You can read about some of them in this blog post: [How to Be a Bayesian in Python](http://jakevdp.github.io/blog/2014/06/14/frequentism-and-bayesianism-4-bayesian-in-python/).\n",
"\n",
"Here we'll focus on [``emcee``](http://dan.iel.fm/emcee/), a lightweight Python package developed by Dan Foreman-Mackey and collaborators."
"Here we'll focus on [``emcee``](http://dan.iel.fm/emcee/), a lightweight Python package developed by Dan Foreman-Mackey and collaborators.\n",
"One benefit of ``emcee`` is that it uses an *ensemble sampler* which automatically tunes the shape and size of the proposal distribution (you can read more details in the ``emcee`` documentation)."
]
},
{
Expand Down Expand Up @@ -138,9 +139,9 @@
"source": [
"def make_data(intercept, slope, N=20, dy=5, rseed=42):\n",
" rand = np.random.RandomState(rseed)\n",
" x = 100 * rand.rand(20)\n",
" x = 100 * rand.rand(N)\n",
" y = intercept + slope * x\n",
" y += dy * rand.randn(20)\n",
" y += dy * rand.randn(N)\n",
" return x, y, dy * np.ones_like(x)\n",
"\n",
"theta_true = (25, 0.5)\n",
Expand Down Expand Up @@ -402,7 +403,7 @@
" # fill this in\n",
" pass\n",
"\n",
"def log_posterior(theta, x, y, sigma):\n",
"def log_posterior(theta, x, y, dy):\n",
" # fill this in\n",
" pass"
]
Expand Down
4 changes: 2 additions & 2 deletions 05-Radial-Velocity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"It seems like we have a reasonable model!"
"The model seems to be working as expected!"
]
},
{
Expand Down Expand Up @@ -392,7 +392,7 @@
"from gatspy.periodic import LombScargleFast\n",
"model = LombScargleFast()\n",
"\n",
"model.fit(t, rv, rv_err)\n",
"model.fit(t_sim, rv_sim, err_sim)\n",
"periods, power = model.periodogram_auto()\n",
"plt.semilogx(periods, power)\n",
"plt.xlim(0, 10000);"
Expand Down
12 changes: 11 additions & 1 deletion Solutions-02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,17 @@
"outputs": [],
"source": [
"x2, y2, dy2 = make_data(*theta_true, N=3, dy=40)\n",
"plt.errorbar(x2, y2, dy2, fmt='o');\n",
"plt.errorbar(x2, y2, dy2, fmt='o');"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot_results(x2, y2, dy2,\n",
" slope_limits=(-2, 5),\n",
" intercept_limits=(-300, 200))"
Expand Down
6 changes: 3 additions & 3 deletions Solutions-03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@
" return -np.inf # log(0)\n",
" else:\n",
" # Jeffreys Prior\n",
" return -theta[2]\n",
" return -np.log(theta[2])\n",
" \n",
"def log_likelihood(theta, x, y, dy):\n",
" y_model = theta[0] + theta[1] * x\n",
" S = dy ** 2 + theta[2] ** 2\n",
" return -0.5 * np.sum(np.log(2 * np.pi * S) +\n",
" (y - y_model) ** 2 / S)\n",
"\n",
"def log_posterior(theta, x, y, sigma):\n",
" return log_prior(theta) + log_likelihood(theta, x, y, sigma)"
"def log_posterior(theta, x, y, dy):\n",
" return log_prior(theta) + log_likelihood(theta, x, y, dy)"
]
},
{
Expand Down

0 comments on commit 7c22fbc

Please sign in to comment.