PolyaGammaHybridSamplers.jl
is a Julia package that implements a hybrid sampling approach for the Pólya-Gamma distribution. The Pólya-Gamma distribution is a continuous distribution on the positive real number line and is most often used for latent variable augmentation in models like logistic regression or logit stick-breaking processes. It is parameterized by two values,
The class of Pólya-Gamma distributions was first presented in a paper by Polson et al. (2013). There is no closed-form expression for the
This can be derived from an alternative definition where the
In order to develop an effecient yet exact sampling method, the authors drew connections to a subclass of
The following year, a technical report written by Windle et al. (2014) was published on arXiv detailing an alternative sampling technique and an approximate technique. The alternative technique requires
Sampler | Ideal Circumstances |
---|---|
Devroye Method | |
Alternative Technique |
|
Saddle-point Sampler | |
Normal Approximation |
The authors of Polson et al. (2013) published the BayesLogit R package with C++ code implementing the Devroye sampling method, later expanding it to include the techniques presented in Windle et al. (2014). The source code is available at the BayesLogit GitHub site. However, it is important to note that, as of version 2.1, inline comments for the main sampling function, rpg_hybrid
, state that the alternative technique code needs further review and/or development (source, lines 138-141) and instead the naive gamma mixture is used for small, non-integer
Interest in the Pólya-Gamma distribution within the Julia community appears first in a GitHub issues thread started by a user called currymj
under the main Distributions.jl repository. Ultimately, currymj
developed a separate package called PolyaGammaDistribution.jl that was essentially a direct translation of the BayesLogit Devroye method code for integer
However, Julia would eventually update to v1.0 and begin requiring a different package structure. When asked about future compatibility, a collaborator, user maximerischard
, indicated in a GitHub issues thread that there were no plans to upgrade the package. The user, igutierrezm
, who started the thread would then go on to develop a Julia v1.0 compatible package, PolyaGammaSamplers.jl. This new package implemented the Devroye method similar to its predecessor, but using the new sampler framework, which is a more limited implementation compared to the full distribution requirements of Distributions.jl, but is also more fitting for the Pólya-Gamma distribution.
Over time, a handful of variations came about, including a PolyaGammaDistribution.jl fork by user yunzli
(link) and a rewritten Devroye method sampler in AugmentedGaussianProcesses.jl by user theogf
. Perhaps the most recent discourse comes from another GitHub issues thread, where user theogf
asked whether their Devroye method code should be merged into Distributions.jl. The issue was ultimately never resolved due to conflicts between the MIT and GPL-3.0 licenses.
As the name suggests, the PolyaGammaHybridSamplers.jl
package attempts to fill a hole present in previously developed Julia packages by implementing other sampling techniques for the Pólya-Gamma distribution beyond the Devroye method. It centers around a hybrid sampler which selects the most appropriate sampling technique based on the value of
Sampler | Condition |
---|---|
Normal Approximation | |
Saddle-point Sampler | |
Devroye Method | |
Gamma Mixture | |
Devroye + Gamma Mixture |
|
To generate a random variate, create a sampler object and then use rand
(vectorized versions of rand
and rand!
are also available):
pg = PolyaGammaHybridSampler(4, 1.5)
data = rand(pg)
The type of sampler can controlled by including, for example, SADDLEPOINT
as an argument:
pg = PolyaGammaHybridSampler(4, 1.5, SADDLEPOINT)
data = rand(pg)
Other valid options include DEVROYE
, NORMALAPPROX
, GAMMAMIXTURE
, and DEVROYEGAMMAMIXTURE
. But be careful as no warning about the approximation quality or efficiency will be given if the sampler is forced to use a technique that is not appropriate for the given parameters.
This package is largly a translation of the original Polson et al. (2013) C++ code in the package BayesLogit, including the later developments described in Windle et al. (2014). Some structural inspiration is also taken from the Julia packages PolyaGammaDistribution.jl (currymj
), PolyaGammaSamplers.jl (igutierrezm
), and AugmentedGaussianProcesses.jl (theogf
). All of these packages are licensed under the GPL-3.0 license, except for AugmentedGaussianProcesses.jl which is licensed under the MIT "Expat" license. Therefore, the PolyaGammaHybridSamplers.jl
package is necessarily licensed under GPL-3.0. The question of whether this code can merged into Distributions.jl has likely been answered in this GitHub issues thread started by theogf
: the MIT license of Julia's base environment conflicts with the GPL-3.0 requirements, so probably not.