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

Review geometric distribution sampler #2612

Open
szhorvat opened this issue May 16, 2024 · 0 comments
Open

Review geometric distribution sampler #2612

szhorvat opened this issue May 16, 2024 · 0 comments
Labels
sampling Issues related to (unbiased) random sampling theory The math behind the issue needs to be worked out; literature research needed
Milestone

Comments

@szhorvat
Copy link
Member

szhorvat commented May 16, 2024

igraph's geometric sampler, igraph_rng_get_geom() is currently implemented as follows:

igraph_rng_get_pois(rng, igraph_i_exp_rand(rng) * ((1 - p) / p))

Given how complex igraph_rng_get_pois() is, this is likely quite inefficient. Another method that is likely more efficient is floor(log(1-r) / log(1-p)) where r is uniform variate from $[0,1)$. I am not sure why we're not using this, but I suspect that there must be good reasons. The current implementation is lifted from R's source code, which I am inclined to trust.

https://github.com/wch/r-source/blob/trunk/src/nmath/rgeom.c

There may be precision issues with the naive implementation, especially when $p \ll 1$.

The reference they give is:

 *  NOTES
 *
 *    We generate lambda as exponential with scale parameter
 *    p / (1 - p).  Return a Poisson deviate with mean lambda.
 *    See Example 1.5 in Devroye (1986), Chapter 10, pages 488f.
 *
 *  REFERENCE
 *
 *    Devroye, L. (1986).
 *    Non-Uniform Random Variate Generation.
 *    New York: Springer-Verlag.
 *    Pages 488f.

This is a very old reference. There is a much more recent one we should review and possible adopt the ideas from,

https://link.springer.com/chapter/10.1007/978-3-642-39206-1_23

Karl Bringmann & Tobias Friedrich: Exact and Efficient Generation of Geometric Random Variates and Random Graphs https://doi.org/10.1007/978-3-642-39206-1_23

Also useful: https://peteroupc.github.io/randmisc.html#On_Geometric_Samplers

Why is this important? It is critical to efficient sampling fro the $G(n,p)$ model, which is also the motivation for the Bringmann and Friedrich paper. Good precision with very small $p$ is critical for this use case.

@szhorvat szhorvat added this to the 1.0 milestone May 16, 2024
@szhorvat szhorvat added the theory The math behind the issue needs to be worked out; literature research needed label May 16, 2024
@szhorvat szhorvat added the sampling Issues related to (unbiased) random sampling label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sampling Issues related to (unbiased) random sampling theory The math behind the issue needs to be worked out; literature research needed
Projects
None yet
Development

No branches or pull requests

1 participant