Skip to content

Commit 836a38a

Browse files
PRKramerMacroLens
andauthored
Update SMC-ABC_Lotka-Volterra_example.ipynb (#590)
* 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]>
1 parent 27e6481 commit 836a38a

File tree

2 files changed

+132
-51
lines changed

2 files changed

+132
-51
lines changed

examples/samplers/SMC-ABC_Lotka-Volterra_example.ipynb

+120-43
Large diffs are not rendered by default.

examples/samplers/SMC-ABC_Lotka-Volterra_example.myst.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
format_name: myst
66
format_version: 0.13
77
kernelspec:
8-
display_name: Python 3.9.7 ('base')
8+
display_name: Python 3 (ipykernel)
99
language: python
1010
name: python3
1111
---
@@ -166,8 +166,8 @@ def add_noise(a, b):
166166
# plotting observed data.
167167
observed = add_noise(a, b)
168168
_, ax = plt.subplots(figsize=(12, 4))
169-
ax.plot(observed[:, 0], "x", label="prey")
170-
ax.plot(observed[:, 1], "x", label="predator")
169+
ax.plot(t, observed[:, 0], "x", label="prey")
170+
ax.plot(t, observed[:, 1], "x", label="predator")
171171
ax.set_xlabel("time")
172172
ax.set_ylabel("population")
173173
ax.set_title("Observed data")
@@ -198,13 +198,13 @@ az.plot_posterior(idata_lv);
198198
# plot results
199199
_, ax = plt.subplots(figsize=(14, 6))
200200
posterior = idata_lv.posterior.stack(samples=("draw", "chain"))
201-
ax.plot(observed[:, 0], "o", label="prey", c="C0", mec="k")
202-
ax.plot(observed[:, 1], "o", label="predator", c="C1", mec="k")
203-
ax.plot(competition_model(None, posterior["a"].mean(), posterior["b"].mean()), linewidth=3)
201+
ax.plot(t, observed[:, 0], "o", label="prey", c="C0", mec="k")
202+
ax.plot(t, observed[:, 1], "o", label="predator", c="C1", mec="k")
203+
ax.plot(t, competition_model(None, posterior["a"].mean(), posterior["b"].mean()), linewidth=3)
204204
for i in np.random.randint(0, size, 75):
205205
sim = competition_model(None, posterior["a"][i], posterior["b"][i])
206-
ax.plot(sim[:, 0], alpha=0.1, c="C0")
207-
ax.plot(sim[:, 1], alpha=0.1, c="C1")
206+
ax.plot(t, sim[:, 0], alpha=0.1, c="C0")
207+
ax.plot(t, sim[:, 1], alpha=0.1, c="C1")
208208
ax.set_xlabel("time")
209209
ax.set_ylabel("population")
210210
ax.legend();
@@ -224,3 +224,7 @@ martin2021bayesian
224224

225225
:::{include} ../page_footer.md
226226
:::
227+
228+
```{code-cell} ipython3
229+
230+
```

0 commit comments

Comments
 (0)