Skip to content

Commit 4b71e0b

Browse files
committed
Update case studies examples in docs
1 parent 9d04aaa commit 4b71e0b

File tree

10 files changed

+174
-116
lines changed

10 files changed

+174
-116
lines changed

docs/run_example_case_studies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ else
1010
fi
1111

1212
jupyter nbconvert --to markdown ${nb_exec} case_studies/lotka_volterra_case_study/scripts/*.ipynb --output-dir=docs/source/examples/lotka_volterra_case_study/
13-
jupyter nbconvert --to markdown ${nb_exec} case_studies/tktd_rna_pulse/scripts/*.ipynb --output-dir=docs/source/examples/tktd_rna_pulse/
13+
# jupyter nbconvert --to markdown ${nb_exec} case_studies/tktd_rna_pulse/scripts/*.ipynb --output-dir=docs/source/examples/tktd_rna_pulse/

docs/source/examples/lotka_volterra_case_study/hierarchical_model.md

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@ from pymob.sim.parameters import Param
1616
from pymob.sim.config import Modelparameters
1717
from pymob.solvers.diffrax import JaxSolver
1818
from pymob.inference.analysis import plot_pair
19+
20+
from lotka_volterra_case_study.sim import HierarchicalSimulation
1921
```
2022

2123

2224
```python
23-
# import case study and simulation
24-
25-
config = Config()
25+
config = Config("../scenarios/test_hierarchical/settings.cfg")
2626
config.case_study.package = "../.."
27-
config.case_study.name = "lotka_volterra_case_study"
2827
config.case_study.scenario = "test_hierarchical"
29-
config.case_study.simulation = "HierarchicalSimulation"
30-
config.import_casestudy_modules(reset_path=True)
31-
32-
from lotka_volterra_case_study.sim import HierarchicalSimulation
3328

3429
sim = HierarchicalSimulation(config)
3530
sim.initialize_from_script()
@@ -237,13 +232,17 @@ except RuntimeError:
237232
value 120 12 |
238233
wolves_obs dist 120 12 |
239234
value 120 12 |
240-
Likelihood is not well defined, there are zeros in the observations, while support excludes zeros.
241235

242236

243237
/home/flo-schu/projects/pymob/pymob/inference/numpyro_backend.py:652: UserWarning: Site rabbits_obs: Out-of-support values provided to log prob method. The value argument should be within the support.
244238
mcmc.run(next(keys))
245239
/home/flo-schu/projects/pymob/pymob/inference/numpyro_backend.py:652: UserWarning: Site wolves_obs: Out-of-support values provided to log prob method. The value argument should be within the support.
246240
mcmc.run(next(keys))
241+
242+
243+
Likelihood is not well defined, there are zeros in the observations, while support excludes zeros.
244+
245+
247246
/home/flo-schu/projects/pymob/pymob/inference/numpyro_backend.py:934: UserWarning: Log-likelihoods ['rabbits_obs', 'wolves_obs'] contained NaN or inf values. The gradient based samplers will not be able to sample from this model. Make sure that all functions are numerically well behaved. Inspect the model with `jax.debug.print('{}',x)` https://jax.readthedocs.io/en/latest/notebooks/external_callbacks.html#exploring-debug-callback Or look at the functions step by step to find the position where jnp.grad(func)(x) evaluates to NaN
248247
warnings.warn(
249248

@@ -296,7 +295,7 @@ scaled_residuals.wolves.plot()
296295

297296

298297

299-
<matplotlib.collections.QuadMesh at 0x7f31eaaa5910>
298+
<matplotlib.collections.QuadMesh at 0x7fbaaeb69e10>
300299

301300

302301

@@ -401,7 +400,7 @@ sim.config.inference_numpyro.init_strategy = "init_to_median"
401400
sim.dispatch_constructor()
402401
sim.set_inferer("numpyro")
403402

404-
sample_nuts = False
403+
sample_nuts = True
405404
if sample_nuts:
406405
sim.config.inference_numpyro.kernel = "nuts"
407406
sim.inferer.run()
@@ -637,7 +636,7 @@ theta["beta"]
637636

638637

639638
```python
640-
posterior = idata_nuts.posterior[["alpha", "beta"]].rename({"alpha_dim_0": "id"})
639+
posterior = idata_nuts.posterior[["alpha", "beta"]]
641640
loglik = idata_nuts.log_likelihood.mean(("time"))
642641
fig = plot_pair(posterior, loglik, parameters=["alpha", "beta"])
643642
fig.savefig(f"{sim.output_path}/posterior.png")
@@ -1727,28 +1726,6 @@ loglik, grad_loglik = sim.inferer.create_log_likelihood(return_type="joint-log-l
17271726
```
17281727

17291728

1730-
```python
1731-
sim.config.model_parameters = parameters
1732-
sim.config.inference_numpyro.kernel = "nuts"
1733-
sim.config.inference_numpyro.nuts_max_tree_depth = 12
1734-
sim.dispatch_constructor()
1735-
sim.set_inferer("numpyro")
1736-
1737-
if False:
1738-
sim.inferer.run()
1739-
idata_nuts_2 = sim.inferer.idata.copy()
1740-
```
1741-
1742-
Jax 64 bit mode: False
1743-
Absolute tolerance: 1e-07
1744-
1745-
1746-
/home/flo-schu/miniconda3/envs/pymob/lib/python3.11/site-packages/pydantic/main.py:308: UserWarning: Pydantic serializer warnings:
1747-
Expected `int` but got `float` - serialized value may not be as expected
1748-
return self.__pydantic_serializer__.to_python(
1749-
1750-
1751-
17521729
```python
17531730
idata_svi_2.posterior.beta.mean(("chain", "draw"))
17541731
```
@@ -2153,7 +2130,7 @@ plt.tight_layout()
21532130

21542131

21552132

2156-
![png](hierarchical_model_files/hierarchical_model_46_0.png)
2133+
![png](hierarchical_model_files/hierarchical_model_45_0.png)
21572134

21582135

21592136

@@ -2165,8 +2142,8 @@ plt.tight_layout()
21652142

21662143
```python
21672144
sim.config.case_study.scenario = "lotka_volterra_hierarchical_hyperpriors"
2168-
sim.config.create_directory("scenario")
2169-
sim.config.save()
2145+
sim.config.create_directory("scenario", force=True)
2146+
sim.config.save(force=True)
21702147
```
21712148

21722149
/home/flo-schu/miniconda3/envs/pymob/lib/python3.11/site-packages/pydantic/main.py:308: UserWarning: Pydantic serializer warnings:
@@ -2176,3 +2153,5 @@ sim.config.save()
21762153

21772154
Scenario directory exists at '/home/flo-schu/projects/pymob/case_studies/lotka_volterra_case_study/scenarios/lotka_volterra_hierarchical_hyperpriors'.
21782155

2156+
2157+
Note that this configuration is not yet complete. It still requires a look at $y_0$ variation!
67.2 KB
Loading

0 commit comments

Comments
 (0)