-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notes on how to sample PyMC models
- Loading branch information
1 parent
66b5949
commit f1f6416
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
``` |