Ziggurats.jl -- High performance non-uniform random number generators for user defined distributions

Announcing the recently registered Ziggurats.jl. Make very high performance random number generators for whatever distributions you like! (with some modest limitations)

The ziggurat algorithm uses a carefully constructed table of precomputed values to sample random numbers distributed according to a PDF with very high efficiency. It is widely used for high performance generation of normally distributed and exponentially distributed random numbers, including in Julia’s own Random.jl. The new package, Ziggurats.jl, automates the process of constructing the ziggurat tables so you can get the same high performance sampling from a very wide variety of distributions. The main requirements are that the PDF must be univariate, piecewise monotonic, and must not diverge to infinite density. Even discontinuous functions should work.

Example:

julia> using Ziggurats, Plots, BenchmarkTools
julia> z = ziggurat(x->10 - x + sin(x), (0, 9.7));
julia> histogram(rand(z, 10^5))

julia> @btime rand($z)
  3.920 ns (0 allocations: 0 bytes)

Check out the README on GitHub for more information: Ziggurats.jl

16 Likes

Ziggurats.jl v0.2.0 is out now. It’s more robust, and faster than ever!

There have been a lot of bug fixes, mainly making it much more robust against issues caused by floating point round off and type instabilities.

Performance is improved for batch sampling using rand(z, dims) or rand!(a, z). These methods should be preferred over repeated calls to rand(z). In addition, a specialized/optimized sampler is now available for distributions that are symmetric and unimodal (bell-shaped); use the BellZiggurat constructor to get the best possible performance on this special class of distributions.

The package has all the features I want for a v1.0 release. The to-do list for v1.0 is mostly documentation, systematic benchmarking, and testing (the test suite is decent already, but I want it to be very thorough).

I’m interested to hear if anyone is using it, or considering using it? I originally had the idea while working on seeding particle-based plasma physics simulations, but obviously there’s a wide variety of possible applications. Tell me about yours.

3 Likes