-
Notifications
You must be signed in to change notification settings - Fork 248
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 one-sided/two-sided truncated distribution and cdf/icdf method for univariate symmetric distributions #915
Conversation
@fritzo Could you help me review this PR? Pls consider this as a low priority PR. A nice thing is your |
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.
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
# 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) |
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.
why not simply
return jnp.where(self.low < self.base_dist.loc, 1., 0.)
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.
yeah, thanks
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 |
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.
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.
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