Add one-sided/two-sided truncated distribution and cdf/icdf method for univariate symmetric distributions#915
Merged
fritzo merged 8 commits intopyro-ppl:masterfrom Feb 17, 2021
Merged
Conversation
Member
Author
|
@fritzo Could you help me review this PR? Pls consider this as a low priority PR. A nice thing is your |
fritzo
reviewed
Feb 16, 2021
Member
fritzo
left a comment
There was a problem hiding this comment.
Interface looks great! I haven't checked math of .cdf(),.icdf() but I would feel more confident if we added some simple algebraic tests independent of SciPy, testing with a large grid of random values.
numpyro/distributions/continuous.py
Outdated
Comment on lines
1117
to
1120
| # if low < loc, returns cdf(high) = 1; otherwise returns 1 - cdf(high) = 0 | ||
| loc = self.base_dist.loc | ||
| sign = jnp.where(loc >= self.low, 1., -1.) | ||
| return 0.5 * (1 + sign) |
Member
There was a problem hiding this comment.
why not simply
return jnp.where(self.low < self.base_dist.loc, 1., 0.)
fehiepsi
commented
Feb 17, 2021
| quantiles = random.uniform(random.PRNGKey(1), (100,) + d.shape()) | ||
| try: | ||
| if d.shape() == (): | ||
| rtol = 1e-3 if jax_dist is dist.StudentT else 1e-5 |
Member
Author
There was a problem hiding this comment.
rtol=1e-5 fails for one StudentT test. I guess the precision of betainc/its grad is not good enough or samples got extreme values.
fritzo
approved these changes
Feb 17, 2021
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #895, #894, #914. The implementation only supports symmetric distributions because we can leverage the symmetry to address numerical issues that are discussed at probtorch for the lower bound > 5. The issue is cdf/icdf suffers from precision errors at the right tail (e.g.
Normal().cdf(6.) = 1.). Thanks to the symmetry, we can transform the right tail to the left tail, which has better precision (e.g.Normal().cdf(-6.) = 9.865896e-10).TODO