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

feat: add Levy distribution #317

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Qazalbash
Copy link

This PR adds the implementation of Levy distribution. There is some numerical error in checking PDF integrate to be equal to cdf. I revisited the implementation several times and found no ambiguity. Therefore, I am pushing to seek some guidance.

@YeungOnion
Copy link
Contributor

Hmm, while our check for consistency being an integrator is likely susceptible to the usual nuance of general forward integrators.

The error message, below, indicates that two steps into the integration it's already off by 20%. Since it checks at each step this is pretty significant.

failures:

---- distribution::levy::tests::test_continuous stdout ----
Integral of pdf doesn't equal cdf!
Integration from 1 by 0.003182932192553111 to 1.0063658643851063 = 0.006119699097797403
cdf = 0.005069737329462489

I'm not certain this is the case, but the implementations appear correct to me as well.

Options I expect could be

  • inappropriate step size for that part of the function, which I don't think is the case considering it's not terribly steep near the mean
  • the erfc implementation isn't sufficiently accurate, but we use that elsewhere, so we would have expected to see it elsewhere
  • my first thought, the integrator is insufficient. The current one integrates a linear approximation to the function, and perhaps we need better (but again the function isn't very steep here, so I'm unsure this is the case).

We may need to update the check for continuous distributions to be more robust integration or rely on other constraints. I can open this part as a different issue.

@Qazalbash
Copy link
Author

Hi, I am also contributing a little bit to NumPyro, a Python-based PPL. Their test suites are big and quite good. Looking at them may help.

@YeungOnion
Copy link
Contributor

YeungOnion commented Jan 19, 2025

That's a very cool project, along with JAX. I think I may have seen JAX before and forgot about it.

I took a pass through by skimming, searching, and with an LLM. Couldn't find one in that test suite.


I've also been thinking, perhaps this is a little unnecessary: testing values for the function will isolate precision effects to and precision checking (done by approx).

Perhaps if we had a default impl of PDF for a CDF then this may have been a stronger requirement. But instead, an alternative sanity check might be going the other way and verifying a finite difference in the derivative over some "well-chosen" interval.

@Qazalbash would you be willing to write an internal function analogous to the integrator for this and use that test instead? You could use it standalone in the test and for later development we could see if it works replacing the integrator within internal::check_continuous_distribution

@Qazalbash
Copy link
Author

Perhaps if we had a default impl of PDF for a CDF then this may have been a stronger requirement. But instead, an alternative sanity check might be going the other way and verifying a finite difference in the derivative over some "well-chosen" interval.

I am in favor of checking whether the gradient of a CDF equals a PDF. Is there any good autograd we can use?

Qazalbash would you be willing to write an internal function analogous to the integrator for this and use that test instead? You could use it standalone in the test and for later development we could see if it works replacing the integrator within internal::check_continuous_distribution

I will experiment with some, Just to let you know it will not be soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants