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

Incorrect results #37

Closed
pevnak opened this issue Jul 23, 2019 · 2 comments
Closed

Incorrect results #37

pevnak opened this issue Jul 23, 2019 · 2 comments

Comments

@pevnak
Copy link

pevnak commented Jul 23, 2019

Hi, I have just tried to integrate a Laplace distribution as

using QuadGK, Distributions
pc = Laplace(0, 1)
quadgk(x -> pdf(pc, x), -1e8, 1e8, rtol=1e-8)
(0.0, 0.0)

I obtain zero, which is obviously wrong as it should be one. The manual says that I should add an explicit point, when the point is non-smooth, which I do

quadgk(x -> pdf(pc, x), -1e8, 0, 1e8, rtol=1e-8)
(0.0, 0.0)

But it does not help either. I think that the method just omit to sample around the zero sufficiently.

@stevengj
Copy link
Member

stevengj commented Jul 27, 2019

The problem is that if you integrate from 1e-8 to 1e8 then the initial points are too spread out and it only samples your function PDF where it is close to zero. This kind of thing is an intrinsic limitation of any numerical quadrature scheme.

Simplest solution: if you want to integrate over the whole real line, integrate over the whole real line.

julia> quadgk(x -> pdf(pc, x), -Inf, Inf, rtol=1e-8)
(0.999999999999772, 8.248719550886085e-9)

quadgk knows how to do something reasonable here (via a coordinate transformation).

Alternatives include increasing the integration order (the order parameter) to increase the number of sample points, breaking the integral into more subintervals to increase the number of initial sample points, or doing a coordinate transform on your interval to emphasize the origin (this is what the -Inf..Inf algorithm does internally).

@pevnak
Copy link
Author

pevnak commented Jul 29, 2019

Thanks a lot for the clarification.

Tomas

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

No branches or pull requests

2 participants