Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasCowie committed Apr 30, 2024
2 parents 1a946ec + 38adc5f commit 1a7ff70
Show file tree
Hide file tree
Showing 22 changed files with 7,516 additions and 7,563 deletions.
116 changes: 58 additions & 58 deletions docs/after_mcmc.html

Large diffs are not rendered by default.

116 changes: 58 additions & 58 deletions docs/after_mcmc.ipynb

Large diffs are not rendered by default.

1,518 changes: 754 additions & 764 deletions docs/hierarchical_models.html

Large diffs are not rendered by default.

4,541 changes: 2,272 additions & 2,269 deletions docs/hierarchical_models.ipynb

Large diffs are not rendered by default.

Binary file added docs/img/monod_posteriors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/monod_priors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/monod_simulated_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
"Discussion).” *Bayesian Analysis* 16 (2): 667–718.\n",
"<https://doi.org/10.1214/20-BA1221>."
],
"id": "e17fdecc-1fc7-4380-9ddc-8efa49cdb671"
"id": "3de702ca-c484-4274-b592-38e972460b2a"
}
],
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction_to_bayesian_inference.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/mcmc_and_stan.ipynb

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions docs/metropolis-hastings.html

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions docs/metropolis-hastings.ipynb

Large diffs are not rendered by default.

2,568 changes: 1,275 additions & 1,293 deletions docs/odes.html

Large diffs are not rendered by default.

3,838 changes: 1,916 additions & 1,922 deletions docs/odes.ipynb

Large diffs are not rendered by default.

218 changes: 109 additions & 109 deletions docs/regression.html

Large diffs are not rendered by default.

1,942 changes: 971 additions & 971 deletions docs/regression.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/search.json

Large diffs are not rendered by default.

Binary file modified materials/img/monod_posteriors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified materials/img/monod_priors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified materials/img/monod_simulated_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 32 additions & 48 deletions materials/odes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ true_param_values = {
"t_ks": 0.3,
"t_gamma": 0.13,
"species_zero": [
[np.exp(np.random.normal(-2.1, 0.05)), np.exp(np.random.normal(0.2, 0.05))]
for _ in range(N_tube)
[
np.exp(np.random.normal(-2.1, 0.05)),
np.exp(np.random.normal(0.2, 0.05))
] for _ in range(N_tube)
],
"sigma_y": [0.08, 0.1],
"ln_mu_max_z": np.random.normal(0, 1, size=N_strain).tolist(),
Expand Down Expand Up @@ -424,30 +426,22 @@ idata_prior
We can find the prior intervals for the true abundance and plot them in the graph.

```{python}
prior_abundances = (
idata_prior
.posterior["abundance"]
.to_dataframe()
.reset_index()
.join(timepoints, on="timepoint")
)
prior_abundances = idata_prior.posterior["abundance"]
n_sample = 20
chains_and_draws = rng.choice(prior_abundances[["chain", "draw"]].values, 10)
chains = rng.choice(prior_abundances.coords["chain"].values, n_sample)
draws = rng.choice(prior_abundances.coords["draw"].values, n_sample)
f, axes = plot_sim(true_abundance, fake_measurements, species_to_ax)
for tube_i in tubes:
for species_j in species:
abundance_sample = (
prior_abundances.loc[
lambda df: (df["tube"] == tube_i) & (df["species"] == species_j)
]
.set_index(["chain", "draw"])
.loc[chains_and_draws.tolist()]
.reset_index()
)
axes[species_to_ax[species_j]].plot(
abundance_sample.set_index("time")["abundance"],
alpha=0.5, color="skyblue", zorder=-1
)
for ax, species_i in zip(axes, species):
for tube_j in tubes:
for chain, draw in zip(chains, draws):
timeseries = prior_abundances.sel(chain=chain, draw=draw, tube=tube_j, species=species_i)
ax.plot(
timepoints.values,
timeseries.values,
alpha=0.5, color="skyblue", zorder=-1
)
f.savefig("img/monod_priors.png")
```

Expand Down Expand Up @@ -494,32 +488,22 @@ az.summary(idata_posterior)
Show posterior intervals

```{python}
posterior_abundances = (
idata_posterior
.posterior["abundance"]
.to_dataframe()
.reset_index()
.join(timepoints, on="timepoint")
)
prior_abundances = idata_posterior.posterior["abundance"]
n_sample = 20
chains_and_draws = rng.choice(
posterior_abundances[["chain", "draw"]].values, 10
)
chains = rng.choice(prior_abundances.coords["chain"].values, n_sample)
draws = rng.choice(prior_abundances.coords["draw"].values, n_sample)
f, axes = plot_sim(true_abundance, fake_measurements, species_to_ax)
for tube_i in tubes:
for species_j in species:
abundance_sample = (
posterior_abundances.loc[
lambda df: (df["tube"] == tube_i) & (df["species"] == species_j)
]
.set_index(["chain", "draw"])
.loc[chains_and_draws.tolist()]
.reset_index()
)
axes[species_to_ax[species_j]].plot(
abundance_sample.set_index("time")["abundance"],
alpha=0.5, color="skyblue", zorder=-1
)
for ax, species_i in zip(axes, species):
for tube_j in tubes:
for chain, draw in zip(chains, draws):
timeseries = prior_abundances.sel(chain=chain, draw=draw, tube=tube_j, species=species_i)
ax.plot(
timepoints.values,
timeseries.values,
alpha=0.5, color="skyblue", zorder=-1
)
f.savefig("img/monod_posteriors.png")
```

Expand Down
6 changes: 3 additions & 3 deletions src/stan/monod.stan
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ model {
a_mu_max ~ normal(prior_a_mu_max[1], prior_a_mu_max[2]);
a_ks ~ normal(prior_a_ks[1], prior_a_ks[2]);
a_gamma ~ normal(prior_a_gamma[1], prior_a_gamma[2]);
t_mu_max ~ normal(prior_t_mu_max[1], prior_t_mu_max[2]);
t_ks ~ normal(prior_t_ks[1], prior_t_ks[2]);
t_gamma ~ normal(prior_t_gamma[1], prior_t_gamma[2]);
t_mu_max ~ lognormal(prior_t_mu_max[1], prior_t_mu_max[2]);
t_ks ~ lognormal(prior_t_ks[1], prior_t_ks[2]);
t_gamma ~ lognormal(prior_t_gamma[1], prior_t_gamma[2]);
for (s in 1 : 2) {
sigma_y[s] ~ lognormal(prior_sigma_y[s, 1], prior_sigma_y[s, 2]);
for (t in 1 : N_tube){
Expand Down

0 comments on commit 1a7ff70

Please sign in to comment.