-
Notifications
You must be signed in to change notification settings - Fork 72
Add docs on justifying instruments in the IV approach #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fcf2626
b92b606
b4722b6
a1d5e8a
aecb24f
85dbd74
b81d878
cc0dfa9
9b40b07
3bf51cf
bbefa9d
8b95a0b
70d4430
47b1a06
729f414
8bdf46b
9be8622
1ad5774
7f87402
fe7107d
5323acb
a22b4ef
bff8260
f4ca088
4a56262
5ed005b
9eb41f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,8 +303,8 @@ | |
... "mus": [[-2,4], [0.5, 3]], | ||
... "sigmas": [1, 1], | ||
... "eta": 2, | ||
... "lkj_sd": 2, | ||
... }) | ||
... "lkj_sd": 1, | ||
... }, None) | ||
Inference data... | ||
""" | ||
|
||
|
@@ -340,7 +340,7 @@ | |
sigma=priors["sigmas"][1], | ||
dims="covariates", | ||
) | ||
sd_dist = pm.HalfCauchy.dist(beta=priors["lkj_sd"], shape=2) | ||
sd_dist = pm.Exponential.dist(priors["lkj_sd"], shape=2) | ||
drbenvincent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
chol, corr, sigmas = pm.LKJCholeskyCov( | ||
name="chol_cov", | ||
eta=priors["eta"], | ||
|
@@ -366,24 +366,52 @@ | |
shape=(X.shape[0], 2), | ||
) | ||
|
||
def fit(self, X, Z, y, t, coords, priors): | ||
"""Draw samples from posterior, prior predictive, and posterior predictive | ||
distributions. | ||
def sample_predictive_distribution(self, ppc_sampler="jax"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking you still want the default to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so. It's not going to be invoked in the fit method. But in the notebook i want to suggest jax is the strongly recommended route to sampling the ppc on the instrumental var class. |
||
"""Function to sample the Multivariate Normal posterior predictive | ||
Likelihood term in the IV class. This can be slow without | ||
using the JAX sampler compilation method. If using the | ||
JAX sampler it will sample only the posterior predictive distribution. | ||
If using the PYMC sampler if will sample both the prior | ||
and posterior predictive distributions.""" | ||
random_seed = self.sample_kwargs.get("random_seed", None) | ||
|
||
if ppc_sampler == "jax": | ||
with self: | ||
self.idata.extend( | ||
pm.sample_posterior_predictive( | ||
self.idata, | ||
random_seed=random_seed, | ||
compile_kwargs={"mode": "JAX"}, | ||
) | ||
) | ||
elif ppc_sampler == "pymc": | ||
with self: | ||
self.idata.extend(pm.sample_prior_predictive(random_seed=random_seed)) | ||
self.idata.extend( | ||
pm.sample_posterior_predictive( | ||
self.idata, | ||
random_seed=random_seed, | ||
) | ||
) | ||
|
||
def fit(self, X, Z, y, t, coords, priors, ppc_sampler=None): | ||
"""Draw samples from posterior distribution and potentially | ||
from the prior and posterior predictive distributions. The | ||
fit call can take values for the | ||
ppc_sampler = ['jax', 'pymc', None] | ||
We default to None, so the user can determine if they wish | ||
to spend time sampling the posterior predictive distribution | ||
independently. | ||
""" | ||
|
||
# Ensure random_seed is used in sample_prior_predictive() and | ||
# sample_posterior_predictive() if provided in sample_kwargs. | ||
random_seed = self.sample_kwargs.get("random_seed", None) | ||
# Use JAX for ppc sampling of multivariate likelihood | ||
|
||
self.build_model(X, Z, y, t, coords, priors) | ||
with self: | ||
self.idata = pm.sample(**self.sample_kwargs) | ||
self.idata.extend(pm.sample_prior_predictive(random_seed=random_seed)) | ||
self.idata.extend( | ||
pm.sample_posterior_predictive( | ||
self.idata, progressbar=False, random_seed=random_seed | ||
) | ||
) | ||
self.sample_predictive_distribution(ppc_sampler=ppc_sampler) | ||
return self.idata | ||
|
||
|
||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I seeing right that the use of
rasterize
hasn't actually impacted the filesize of the notebook?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it dropped it from 6.5 to 3.5 but not enough to avoid the large file check so i had this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, well I'll certainly take that drop in filesize 👍🏻