From 9fff6d5165e7fbe01d6918bec978530583da5e3f Mon Sep 17 00:00:00 2001 From: ricardoV94 Date: Mon, 12 Aug 2024 17:28:34 +0200 Subject: [PATCH] Add notes on how to sample PyMC models --- doc/sampling_pymc_models.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 doc/sampling_pymc_models.md diff --git a/doc/sampling_pymc_models.md b/doc/sampling_pymc_models.md new file mode 100644 index 00000000..8a91643c --- /dev/null +++ b/doc/sampling_pymc_models.md @@ -0,0 +1,34 @@ +## 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 + +# Extract zipfile containing json data +with zipfile.ZipFile(r"posterior_database/data/data/GLM_Binomial_data.json.zip", 'r') as f: + f.extractall(r"posterior_database/data/data/") + +# Load extracted json data to a Python dictionary +with open(r"posterior_database/data/data/GLM_Binomial_data.json", "r") as file: + data = json.load(file) +``` + +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)) +```