Skip to content

Commit

Permalink
Add notes on how to sample PyMC models
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoV94 committed Aug 12, 2024
1 parent 66b5949 commit f1f6416
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions doc/sampling_pymc_models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Sampling PyMC models

Steps to sample PyMC models:

1. load the model json data from the respctive zipfile as a Python dictionary.

For example, for the GLM binomial model:

```python
import json
import zipfile

# Load zipfile
zfile = zipfile.ZipFile(r"posterior_database/data/data/GLM_Binomial_data.json.zip", 'r')
data = json.loads(zfile.read("GLM_Binomial_data.json"))
```

2. Call the model defining function, with the data dictionary and, in a `with` context, call `pm.sample`:

```python
import pymc as pm

from posterior_database.models.pymc.GLM_Binomial_model import model

# Call the function that creates the PyMC model and sample it
with model(data):
trace = pm.sample()

print(pm.stats.summary(trace))
```

0 comments on commit f1f6416

Please sign in to comment.