Skip to content

Commit

Permalink
Merge pull request #282 from rodluger/nexsci-patch
Browse files Browse the repository at this point in the history
nexsci patch
  • Loading branch information
rodluger authored May 4, 2021
2 parents 502193d + ff7e7c1 commit 47a745d
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 289 deletions.
12 changes: 6 additions & 6 deletions notebooks/EclipsingBinary_FullSolution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@
],
"source": [
"with model:\n",
" map_soln = xo.optimize()"
" map_soln = pmx.optimize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To see how we did, let's plot the best fit solution. We don't have values for the coefficients (because we marginalized over them), so what we do to get a light curve is we *solve* for the coefficients (using `sys.solve()`), conditioned on the best fit values for the orbital parameters. We then set the map coefficients and compute the light curve model using `sys.flux()`. Note that we need to wrap some things in `xo.eval_in_model()` in order to get numerical values out of the `pymc3` model."
"To see how we did, let's plot the best fit solution. We don't have values for the coefficients (because we marginalized over them), so what we do to get a light curve is we *solve* for the coefficients (using `sys.solve()`), conditioned on the best fit values for the orbital parameters. We then set the map coefficients and compute the light curve model using `sys.flux()`. Note that we need to wrap some things in `pmx.eval_in_model()` in order to get numerical values out of the `pymc3` model."
]
},
{
Expand All @@ -333,12 +333,12 @@
"outputs": [],
"source": [
"with model:\n",
" x = xo.eval_in_model(sys.solve(t=t)[0], point=map_soln)\n",
" x = pmx.eval_in_model(sys.solve(t=t)[0], point=map_soln)\n",
" pri.map.amp = x[0]\n",
" pri.map[1:, :] = x[1 : pri.map.Ny] / pri.map.amp\n",
" sec.map.amp = x[pri.map.Ny]\n",
" sec.map[1:, :] = x[pri.map.Ny + 1 :] / sec.map.amp\n",
" flux_model = xo.eval_in_model(sys.flux(t=t), point=map_soln)"
" flux_model = pmx.eval_in_model(sys.flux(t=t), point=map_soln)"
]
},
{
Expand Down Expand Up @@ -4924,14 +4924,14 @@
" # Solve the linear problem and draw a sample\n",
" sys.solve(t=t)\n",
" sys.draw()\n",
" # Get the numerical values using `xo.eval_in_model`\n",
" # Get the numerical values using `pmx.eval_in_model`\n",
" (\n",
" pri_amp_draw[i],\n",
" pri_y_draw[i],\n",
" sec_amp_draw[i],\n",
" sec_y_draw[i],\n",
" flux_model[i],\n",
" ) = xo.eval_in_model(\n",
" ) = pmx.eval_in_model(\n",
" [pri.map.amp, pri.map[1:, :], sec.map.amp, sec.map[1:, :], sys.flux(t=t)],\n",
" point=point,\n",
" )"
Expand Down
12 changes: 6 additions & 6 deletions notebooks/EclipsingBinary_FullSolution_Painful.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
" pm.Deterministic(\"flux_model\", flux_model)\n",
"\n",
" # Save our initial guess\n",
" flux_model_guess = xo.eval_in_model(flux_model)\n",
" flux_model_guess = pmx.eval_in_model(flux_model)\n",
"\n",
" # The likelihood function assuming known Gaussian uncertainty\n",
" pm.Normal(\"obs\", mu=flux_model, sd=sigma, observed=flux)"
Expand Down Expand Up @@ -299,7 +299,7 @@
],
"source": [
"with model:\n",
" map_soln = xo.optimize(\n",
" map_soln = pmx.optimize(\n",
" vars=[A_inc, A_r, A_m, A_prot, B_inc, B_r, B_m, B_prot, B_porb, B_t0],\n",
" start=model.test_point,\n",
" )"
Expand All @@ -323,7 +323,7 @@
],
"source": [
"with model:\n",
" map_soln = xo.optimize(\n",
" map_soln = pmx.optimize(\n",
" vars=[A_amp, pri.map[1:, :], B_amp, sec.map[1:, :]], start=map_soln\n",
" )"
]
Expand All @@ -346,7 +346,7 @@
],
"source": [
"with model:\n",
" map_soln = xo.optimize(\n",
" map_soln = pmx.optimize(\n",
" vars=[A_inc, A_r, A_m, A_prot, B_inc, B_r, B_m, B_prot, B_porb, B_t0],\n",
" start=map_soln,\n",
" )"
Expand All @@ -370,7 +370,7 @@
],
"source": [
"with model:\n",
" map_soln = xo.optimize(start=map_soln)"
" map_soln = pmx.optimize(start=map_soln)"
]
},
{
Expand Down Expand Up @@ -406,7 +406,7 @@
"plt.plot(t, flux, \"k.\", alpha=0.3, ms=2, label=\"data\")\n",
"plt.plot(t, flux_model_guess, \"C1--\", lw=1, alpha=0.5, label=\"Initial\")\n",
"plt.plot(\n",
" t, xo.eval_in_model(flux_model, map_soln, model=model), \"C1-\", label=\"MAP\", lw=1\n",
" t, pmx.eval_in_model(flux_model, map_soln, model=model), \"C1-\", label=\"MAP\", lw=1\n",
")\n",
"plt.legend(fontsize=10, numpoints=5)\n",
"plt.xlabel(\"time [days]\", fontsize=24)\n",
Expand Down
13 changes: 5 additions & 8 deletions notebooks/EclipsingBinary_PyMC3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@
" pm.Deterministic(\"flux_model\", flux_model)\n",
"\n",
" # Save our initial guess\n",
" # See http://exoplanet.dfm.io/en/stable/user/api/#exoplanet.eval_in_model\n",
" flux_model_guess = xo.eval_in_model(flux_model)\n",
" flux_model_guess = pmx.eval_in_model(flux_model)\n",
"\n",
" # The likelihood function assuming known Gaussian uncertainty\n",
" pm.Normal(\"obs\", mu=flux_model, sd=sigma, observed=flux)"
Expand All @@ -233,7 +232,7 @@
"outputs": [],
"source": [
"with model:\n",
" map_soln = xo.optimize()"
" map_soln = pmx.optimize()"
]
},
{
Expand All @@ -254,7 +253,7 @@
"plt.plot(t, flux, \"k.\", alpha=0.3, ms=2, label=\"data\")\n",
"plt.plot(t, flux_model_guess, \"C1--\", lw=1, alpha=0.5, label=\"Initial\")\n",
"plt.plot(\n",
" t, xo.eval_in_model(flux_model, map_soln, model=model), \"C1-\", label=\"MAP\", lw=1\n",
" t, pmx.eval_in_model(flux_model, map_soln, model=model), \"C1-\", label=\"MAP\", lw=1\n",
")\n",
"plt.legend(fontsize=10, numpoints=5)\n",
"plt.xlabel(\"time [days]\", fontsize=24)\n",
Expand Down Expand Up @@ -300,9 +299,7 @@
"source": [
"## MCMC sampling\n",
"\n",
"We have an optimum solution, but we're really interested in the *posterior* over surface maps (i.e., an understanding of the uncertainty of our solution). We're therefore going to do MCMC sampling with `pymc3`. This is easy: within the `model` context, we just call `pmx.sample`. The number of tuning and draw steps below are quite small since I wanted this notebook to run quickly; try increasing them by a factor of a few to get more faithful posteriors.\n",
"\n",
"You can read about the `get_dense_nuts_step` convenience function (which *really* helps the sampling when degeneracies are present) [here](http://exoplanet.dfm.io/en/stable/user/api/#exoplanet.get_dense_nuts_step)."
"We have an optimum solution, but we're really interested in the *posterior* over surface maps (i.e., an understanding of the uncertainty of our solution). We're therefore going to do MCMC sampling with `pymc3`. This is easy: within the `model` context, we just call `pmx.sample`. The number of tuning and draw steps below are quite small since I wanted this notebook to run quickly; try increasing them by a factor of a few to get more faithful posteriors."
]
},
{
Expand Down Expand Up @@ -516,7 +513,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
11 changes: 2 additions & 9 deletions notebooks/FAQs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,13 @@
"pmx.eval_in_model(expression)\n",
"```\n",
"\n",
"or\n",
"\n",
"```python\n",
"import exoplanet\n",
"exoplanet.eval_in_model(expression)\n",
"```\n",
"\n",
"where `expression` is the `pymc3` expression whose value you want. By default, this will evaluate the expression at the **test point** of each of the inputs. If you've already run the sampler and have access to a `trace`, you can evaluate the expression at index `i` of the `trace` by running\n",
"\n",
"```python\n",
"exoplanet.eval_in_model(expression, point=trace.point(i))\n",
"pmx.eval_in_model(expression, point=trace.point(i))\n",
"```\n",
"\n",
"Check out [pymc3-ext](https://github.com/exoplanet-dev/pymc3-ext) and the [exoplanet docs](https://exoplanet.dfm.io/en/stable/user/api/#exoplanet.eval_in_model) for more information."
"Check out [pymc3-ext docs](https://github.com/exoplanet-dev/pymc3-ext) for more information."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/HotJupiterPhaseCurve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
"outputs": [],
"source": [
"with model:\n",
" map_soln = exoplanet.optimize()"
" map_soln = pmx.optimize()"
]
},
{
Expand Down
26 changes: 13 additions & 13 deletions notebooks/PixelSampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"import matplotlib.pyplot as plt\n",
"from matplotlib import colors\n",
"import pymc3 as pm\n",
"import exoplanet\n",
"import pymc3_ext as pmx\n",
"import theano\n",
"import theano.tensor as tt\n",
"\n",
Expand Down Expand Up @@ -399,7 +399,7 @@
" # Compute the flux\n",
" lc_model = tt.dot(X_inf, x)\n",
" pm.Deterministic(\"lc_model\", lc_model)\n",
" lc_model_guess = exoplanet.eval_in_model(lc_model)\n",
" lc_model_guess = pmx.eval_in_model(lc_model)\n",
"\n",
" # Store the Ylm coeffs. Note that `x` is the\n",
" # *amplitude-weighted* vector of spherical harmonic\n",
Expand All @@ -418,7 +418,7 @@
"outputs": [],
"source": [
"with model:\n",
" soln = exoplanet.optimize(options=dict(maxiter=9999))\n",
" soln = pmx.optimize(options=dict(maxiter=9999))\n",
" y[1] = np.array(soln[\"y\"])\n",
" amp[1] = soln[\"amp\"]\n",
" flux_model[1] = soln[\"lc_model\"]"
Expand Down Expand Up @@ -467,7 +467,7 @@
" # Compute the flux\n",
" lc_model = tt.dot(X_inf, x)\n",
" pm.Deterministic(\"lc_model\", lc_model)\n",
" lc_model_guess = exoplanet.eval_in_model(lc_model)\n",
" lc_model_guess = pmx.eval_in_model(lc_model)\n",
"\n",
" # Store the Ylm coeffs\n",
" pm.Deterministic(\"amp\", x[0])\n",
Expand All @@ -484,7 +484,7 @@
"outputs": [],
"source": [
"with model:\n",
" soln = exoplanet.optimize(options=dict(maxiter=9999))\n",
" soln = pmx.optimize(options=dict(maxiter=9999))\n",
" y[2] = np.array(soln[\"y\"])\n",
" amp[2] = soln[\"amp\"]\n",
" flux_model[2] = soln[\"lc_model\"]"
Expand Down Expand Up @@ -539,7 +539,7 @@
" # Compute the flux\n",
" lc_model = tt.dot(X_inf, x)\n",
" pm.Deterministic(\"lc_model\", lc_model)\n",
" lc_model_guess = exoplanet.eval_in_model(lc_model)\n",
" lc_model_guess = pmx.eval_in_model(lc_model)\n",
"\n",
" # Store the Ylm coeffs\n",
" pm.Deterministic(\"amp\", x[0])\n",
Expand All @@ -556,7 +556,7 @@
"outputs": [],
"source": [
"with model:\n",
" soln = exoplanet.optimize(options=dict(maxiter=9999))\n",
" soln = pmx.optimize(options=dict(maxiter=9999))\n",
" y[3] = np.array(soln[\"y\"])\n",
" amp[3] = soln[\"amp\"]\n",
" flux_model[3] = soln[\"lc_model\"]"
Expand Down Expand Up @@ -610,7 +610,7 @@
" # Compute the flux\n",
" lc_model = tt.dot(X_inf, x)\n",
" pm.Deterministic(\"lc_model\", lc_model)\n",
" lc_model_guess = exoplanet.eval_in_model(lc_model)\n",
" lc_model_guess = pmx.eval_in_model(lc_model)\n",
"\n",
" # Store the Ylm coeffs\n",
" pm.Deterministic(\"amp\", x[0])\n",
Expand All @@ -627,7 +627,7 @@
"outputs": [],
"source": [
"with model:\n",
" soln = exoplanet.optimize(options=dict(maxiter=9999))\n",
" soln = pmx.optimize(options=dict(maxiter=9999))\n",
" y[4] = np.array(soln[\"y\"])\n",
" amp[4] = soln[\"amp\"]\n",
" flux_model[4] = soln[\"lc_model\"]"
Expand Down Expand Up @@ -682,7 +682,7 @@
" # Compute the flux\n",
" lc_model = tt.dot(X_inf, x)\n",
" pm.Deterministic(\"lc_model\", lc_model)\n",
" lc_model_guess = exoplanet.eval_in_model(lc_model)\n",
" lc_model_guess = pmx.eval_in_model(lc_model)\n",
"\n",
" # Store the Ylm coeffs\n",
" pm.Deterministic(\"amp\", x[0])\n",
Expand All @@ -699,7 +699,7 @@
"outputs": [],
"source": [
"with model:\n",
" soln = exoplanet.optimize(options=dict(maxiter=9999))\n",
" soln = pmx.optimize(options=dict(maxiter=9999))\n",
" y[5] = np.array(soln[\"y\"])\n",
" amp[5] = soln[\"amp\"]\n",
" flux_model[5] = soln[\"lc_model\"]"
Expand Down Expand Up @@ -755,7 +755,7 @@
" # Compute the flux\n",
" lc_model = tt.dot(X_inf, x)\n",
" pm.Deterministic(\"lc_model\", lc_model)\n",
" lc_model_guess = exoplanet.eval_in_model(lc_model)\n",
" lc_model_guess = pmx.eval_in_model(lc_model)\n",
"\n",
" # Store the Ylm coeffs\n",
" pm.Deterministic(\"amp\", x[0])\n",
Expand All @@ -772,7 +772,7 @@
"outputs": [],
"source": [
"with model:\n",
" soln = exoplanet.optimize(options=dict(maxiter=9999))\n",
" soln = pmx.optimize(options=dict(maxiter=9999))\n",
" y[6] = np.array(soln[\"y\"])\n",
" amp[6] = soln[\"amp\"]\n",
" flux_model[6] = soln[\"lc_model\"]"
Expand Down
6 changes: 3 additions & 3 deletions notebooks/SpotSolve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
" pm.Deterministic(\"flux_model\", flux_model)\n",
"\n",
" # Save our initial guess\n",
" flux_model_guess = xo.eval_in_model(flux_model)\n",
" flux_model_guess = pmx.eval_in_model(flux_model)\n",
"\n",
" # The likelihood function assuming known Gaussian uncertainty\n",
" pm.Normal(\"obs\", mu=flux_model, sd=flux_err, observed=flux)"
Expand Down Expand Up @@ -228,7 +228,7 @@
"outputs": [],
"source": [
"with model:\n",
" map_soln = xo.optimize(start=model.test_point)"
" map_soln = pmx.optimize(start=model.test_point)"
]
},
{
Expand All @@ -248,7 +248,7 @@
"plt.plot(t, flux, \"k.\", alpha=0.3, ms=2, label=\"data\")\n",
"plt.plot(t, flux_model_guess, \"C1--\", lw=1, alpha=0.5, label=\"Initial\")\n",
"plt.plot(\n",
" t, xo.eval_in_model(flux_model, map_soln, model=model), \"C1-\", label=\"MAP\", lw=1\n",
" t, pmx.eval_in_model(flux_model, map_soln, model=model), \"C1-\", label=\"MAP\", lw=1\n",
")\n",
"plt.legend(fontsize=10, numpoints=5)\n",
"plt.xlabel(\"time [days]\", fontsize=24)\n",
Expand Down
Loading

0 comments on commit 47a745d

Please sign in to comment.