Skip to content

Commit a21f659

Browse files
committed
make results fully reproducible
1 parent 4772b34 commit a21f659

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

causalpy/pymc_experiments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class PrePostFit(ExperimentalDesign):
143143
Formula: actual ~ 0 + a + g
144144
Model coefficients:
145145
a 0.6, 94% HDI [0.6, 0.6]
146-
g 0.3, 94% HDI [0.3, 0.3]
147-
sigma 0.7, 94% HDI [0.6, 0.9]
146+
g 0.4, 94% HDI [0.4, 0.4]
147+
sigma 0.8, 94% HDI [0.6, 0.9]
148148
"""
149149

150150
def __init__(

causalpy/pymc_models.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,22 @@ def fit(self, X, y, coords: Optional[Dict[str, Any]] = None) -> None:
9696
"""Draw samples fromposterior, prior predictive, and posterior predictive
9797
distributions, placing them in the model's idata attribute.
9898
"""
99+
100+
# Ensure random_seed is used in sample_prior_predictive() and
101+
# sample_posterior_predictive() if provided in sample_kwargs.
102+
if "random_seed" in self.sample_kwargs:
103+
random_seed = self.sample_kwargs["random_seed"]
104+
else:
105+
random_seed = None
106+
99107
self.build_model(X, y, coords)
100108
with self.model:
101109
self.idata = pm.sample(**self.sample_kwargs)
102-
self.idata.extend(pm.sample_prior_predictive())
110+
self.idata.extend(pm.sample_prior_predictive(random_seed=random_seed))
103111
self.idata.extend(
104-
pm.sample_posterior_predictive(self.idata, progressbar=False)
112+
pm.sample_posterior_predictive(
113+
self.idata, progressbar=False, random_seed=random_seed
114+
)
105115
)
106116
return self.idata
107117

0 commit comments

Comments
 (0)