PolyaGammaHybridSamplers
Documentation for PolyaGammaHybridSamplers.
PolyaGammaHybridSamplers.PolyaGammaHybridSampler
PolyaGammaHybridSamplers.rand_pgdevroye
PolyaGammaHybridSamplers.rand_pggammasum
PolyaGammaHybridSamplers.rand_pgnormalapprox
PolyaGammaHybridSamplers.rand_pgsaddlepoint
PolyaGammaHybridSamplers.PolyaGammaHybridSampler
— TypePolyaGammaHybridSampler(b::Real, z::Real, [method::PGSamplingMethod])
A sampler for the Polya-Gamma distribution using a hybrid of the saddlepoint approximation, the Devroye method, the normal approximation, and the sum of gammas approximation, each of which are discussed in Windle et al. (2014) – see README.md for details.
Arguments
b::Real
: The shape parameter of the Polya-Gamma distribution. Must be positive.z::Real
: The exponential tilting parameter of the Polya-Gamma distribution.method::PGSamplingMethod : An Enum object specifying the method used to sample from the Polya-Gamma distribution. Must be one of
DEVROYE,
SADDLEPOINT,
NORMALAPPROX,
GAMMASUM, or
DEVROYEPLUSGAMMASUM. If omitted, the method is chosen automatically based on the value of
b`.
Returns
- A
PolyaGammaHybridSampler
object which can be sampled usingrand
orrand!
.
Examples
julia> using PolyaGammaHybridSamplers
julia> s = PolyaGammaHybridSampler(1, 1.0)
julia> rand(s)
Notes
- Automatic selection criteria:
b > 170
->NORMALAPPROX
b >= 13
->SADDLEPOINT
b >= 1 && isinteger(b)
->DEVROYE
b > 1 && !isinteger(b)
->DEVROYEPLUSGAMMASUM
b >= 0
->GAMMASUM
b = 0
-> degenerate distribution at 0
PolyaGammaHybridSamplers.rand_pgdevroye
— Methodrand_pgdevroye(b::Integer, z::Real, [rng::AbstractRNG = Random.default_rng()]])
Sample from a Polya-Gamma distribution using the Devroye method.
Arguments
b::Integer
: the shape parameterz::Real
: the exponential tilting parameterrng::AbstractRNG
: optional random number generator object forrand
Returns
- A sample from the Polya-Gamma distribution with shape parameter
b
and exponential tilting parameterz
.
Notes
- This method is exact, but is increasingly slower as
b
increases. - This sampler requires integer
b
. - Automatically selects the method when
b < 13
and is an integer.
PolyaGammaHybridSamplers.rand_pggammasum
— Methodrand_pggammasum(b::Real, z::Real, [rng::AbstractRNG = Random.default_rng()])
Sample from a Polya-Gamma distribution using the truncated sum of gammas representation.
Arguments
b::Real
: the shape parameterz::Real
: the exponential tilting parameterrng::AbstractRNG
: random number generator object forrand
Returns
- A sample from the Polya-Gamma distribution with shape parameter
b
and exponential tilting parameterz
.
Notes
- This method supports non-integer
b
but is only an approximation, meant only for b < 1 - No warning is given if
b
is too large. - The sum is truncated to 200 terms according to the paper's recommendation.
- Automatically selects this method when
b < 1
or when used in combination with the devroye method for non-integerb
.
PolyaGammaHybridSamplers.rand_pgnormalapprox
— Methodrand_pgnormalapprox(b::Real, z::Real, [rng::AbstractRNG = Random.default_rng()])
Sample from a Polya-Gamma distribution using the normal approximation method.
Arguments
b::Real
: the shape parameterz::Real
: the exponential tilting parameterrng::AbstractRNG
: random number generator object forrand
Returns
- A sample from the Polya-Gamma distribution with shape parameter
b
and exponential tilting parameterz
.
Notes
- This method is an approximation that supports non-integer
b
and is very efficient for largeb
. - Automatically selects this method when
b >= 170
.
PolyaGammaHybridSamplers.rand_pgsaddlepoint
— Methodrand_pgsaddlepoint(b::Real, z::Real, [rng::AbstractRNG = Random.default_rng()])
Sample from a Polya-Gamma distribution using the saddlepoint approximation method.
Arguments
b::Real
: the shape parameterz::Real
: the exponential tilting parameterrng::AbstractRNG
: random number generator object forrand
Returns
- A sample from the Polya-Gamma distribution with shape parameter
b
and exponential tilting parameterz
.
Notes
- This method is an approximation that supports non-integer
b
and is quite efficient for largeb
. - Automatically selects this method when
b >= 13
.