Skip to content

Commit

Permalink
Update SMC-ABC_Lotka-Volterra_example.ipynb (#590)
Browse files Browse the repository at this point in the history
* Update SMC-ABC_Lotka-Volterra_example.ipynb

Added the time array to the plots to correctly represent the independent variable in 2 plots.

* Run pre-commit SMC-ABC_Lotka-Volterra_example (#1)

Run pre-commit and run notebook on changes.

Co-authored-by: Dylan Le <[email protected]>

* fix: add time to the plot command in last plot

---------

Co-authored-by: Dylan Le <[email protected]>
Co-authored-by: Dylan Le <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2023
1 parent 27e6481 commit 836a38a
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 51 deletions.
163 changes: 120 additions & 43 deletions examples/samplers/SMC-ABC_Lotka-Volterra_example.ipynb

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions examples/samplers/SMC-ABC_Lotka-Volterra_example.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupytext:
format_name: myst
format_version: 0.13
kernelspec:
display_name: Python 3.9.7 ('base')
display_name: Python 3 (ipykernel)
language: python
name: python3
---
Expand Down Expand Up @@ -166,8 +166,8 @@ def add_noise(a, b):
# plotting observed data.
observed = add_noise(a, b)
_, ax = plt.subplots(figsize=(12, 4))
ax.plot(observed[:, 0], "x", label="prey")
ax.plot(observed[:, 1], "x", label="predator")
ax.plot(t, observed[:, 0], "x", label="prey")
ax.plot(t, observed[:, 1], "x", label="predator")
ax.set_xlabel("time")
ax.set_ylabel("population")
ax.set_title("Observed data")
Expand Down Expand Up @@ -198,13 +198,13 @@ az.plot_posterior(idata_lv);
# plot results
_, ax = plt.subplots(figsize=(14, 6))
posterior = idata_lv.posterior.stack(samples=("draw", "chain"))
ax.plot(observed[:, 0], "o", label="prey", c="C0", mec="k")
ax.plot(observed[:, 1], "o", label="predator", c="C1", mec="k")
ax.plot(competition_model(None, posterior["a"].mean(), posterior["b"].mean()), linewidth=3)
ax.plot(t, observed[:, 0], "o", label="prey", c="C0", mec="k")
ax.plot(t, observed[:, 1], "o", label="predator", c="C1", mec="k")
ax.plot(t, competition_model(None, posterior["a"].mean(), posterior["b"].mean()), linewidth=3)
for i in np.random.randint(0, size, 75):
sim = competition_model(None, posterior["a"][i], posterior["b"][i])
ax.plot(sim[:, 0], alpha=0.1, c="C0")
ax.plot(sim[:, 1], alpha=0.1, c="C1")
ax.plot(t, sim[:, 0], alpha=0.1, c="C0")
ax.plot(t, sim[:, 1], alpha=0.1, c="C1")
ax.set_xlabel("time")
ax.set_ylabel("population")
ax.legend();
Expand All @@ -224,3 +224,7 @@ martin2021bayesian

:::{include} ../page_footer.md
:::

```{code-cell} ipython3
```

0 comments on commit 836a38a

Please sign in to comment.