PolyaGammaHybridSamplers

Documentation for PolyaGammaHybridSamplers.

PolyaGammaHybridSamplers.PolyaGammaHybridSamplerType
PolyaGammaHybridSampler(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 ofDEVROYE,SADDLEPOINT,NORMALAPPROX,GAMMASUM, orDEVROYEPLUSGAMMASUM. If omitted, the method is chosen automatically based on the value ofb`.

Returns

  • A PolyaGammaHybridSampler object which can be sampled using rand or rand!.

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
source
PolyaGammaHybridSamplers.rand_pgdevroyeMethod
rand_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 parameter
  • z::Real: the exponential tilting parameter
  • rng::AbstractRNG: optional random number generator object for rand

Returns

  • A sample from the Polya-Gamma distribution with shape parameter b and exponential tilting parameter z.

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.
source
PolyaGammaHybridSamplers.rand_pggammasumMethod
rand_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 parameter
  • z::Real: the exponential tilting parameter
  • rng::AbstractRNG: random number generator object for rand

Returns

  • A sample from the Polya-Gamma distribution with shape parameter b and exponential tilting parameter z.

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-integer b.
source
PolyaGammaHybridSamplers.rand_pgnormalapproxMethod
rand_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 parameter
  • z::Real: the exponential tilting parameter
  • rng::AbstractRNG: random number generator object for rand

Returns

  • A sample from the Polya-Gamma distribution with shape parameter b and exponential tilting parameter z.

Notes

  • This method is an approximation that supports non-integer b and is very efficient for large b.
  • Automatically selects this method when b >= 170.
source
PolyaGammaHybridSamplers.rand_pgsaddlepointMethod
rand_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 parameter
  • z::Real: the exponential tilting parameter
  • rng::AbstractRNG: random number generator object for rand

Returns

  • A sample from the Polya-Gamma distribution with shape parameter b and exponential tilting parameter z.

Notes

  • This method is an approximation that supports non-integer b and is quite efficient for large b.
  • Automatically selects this method when b >= 13.
source