Skip to content
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

Add batch_ndims argument in Predictive and log_likelihood #660

Merged
merged 5 commits into from
Jul 7, 2020

Conversation

fehiepsi
Copy link
Member

@fehiepsi fehiepsi commented Jul 2, 2020

Addresses #645 and #639.

This PR also adds a utility soft_vmap to avoid duplicated code in Predictive and log_likelihood. It might also be useful for other purposes. @martinjankowiak you might find soft_vmap, which is adapted from your code, useful for your experiment. :D

numpyro/util.py Outdated Show resolved Hide resolved
numpyro/infer/util.py Outdated Show resolved Hide resolved
numpyro/infer/util.py Show resolved Hide resolved
numpyro/util.py Outdated Show resolved Hide resolved
model, data, _ = beta_bernoulli()
samples = Predictive(model, return_sites=["beta"], num_samples=100)(random.PRNGKey(1))
loglik = log_likelihood(model, samples, data)
samples = Predictive(model, return_sites=["beta"], num_samples=200)(random.PRNGKey(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if we provide batch_ndims=2 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the output will have shape (1, 200, ...) but let me test it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I just add a test for that in test_prior_predictive.

warnings.warn(DeprecationWarning,
"MultivariateAffineTransform is renamed to LowerCholeskyAffine.")
warnings.warn("MultivariateAffineTransform is renamed to LowerCholeskyAffine.",
DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I might have missed this earlier.DeprecationgWarning will be swallowed by application code. We should use FutureWarning instead. See https://docs.python.org/3/library/warnings.html#warning-categories.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This explains why I didn't see the warnings when I used predictive.get_samples(...). :D

@@ -32,8 +32,8 @@ def init_to_median(site=None, num_samples=15):


def init_to_prior(site=None):
warnings.warn(DeprecationWarning,
"`init_to_prior` strategy is renamed to `init_to_sample`.")
warnings.warn("`init_to_prior` strategy is renamed to `init_to_sample`.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here about DeprecationWarning.

@neerajprad neerajprad merged commit bfc8a57 into pyro-ppl:master Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants