BernoulliFactory.expMinusMethod
expMinus(f::F, λ::Float64, rng::RNG=GLOBAL_RNG) where {F<:Function, RNG<:AbstractRNG}

Input:

  • f() simulates Bernoulli(p) random variates (of type Bool)
  • λ >= 0
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(exp(-λ*p)) variate
  • flips is the number of calls of f()
BernoulliFactory.inverseMethod
inverse(f::F, C::Float64, ϵ::Float64, rng::RNG=GLOBAL_RNG) where {F<:Function, RNG<:AbstractRNG}

Input:

  • f() simulates Bernoulli(p) random variates (of type Bool)
  • C ∈ [0,p)
  • ϵ ∈ (0,1) satisfying p > C + ⁠ϵ.
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(C/p) variate
  • flips is the number of calls of f()
BernoulliFactory.linearMethod
linear(f::F, C::Float64, ϵ::Float64, rng::RNG=GLOBAL_RNG) where {F<:Function, RNG<:AbstractRNG}

Input:

  • f() simulates Bernoulli(p) random variates (of type Bool)
  • C >= 0
  • ϵ ∈ (0,1) satisfying C*p < 1-⁠ϵ.
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(C*p) variate
  • flips is the number of calls of f()
BernoulliFactory.logisticMethod
logistic(f::F, C::Float64, rng::RNG=GLOBAL_RNG) where {F<:Function, RNG<:AbstractRNG}

Input:

  • f() simulates Bernoulli(p) random variates (of type Bool)
  • C >= 0
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(Cp/(1.0+Cp)) variate
  • flips is the number of calls of f()
BernoulliFactory.powerMethod
power(f::F, a::Float64, rng::RNG=GLOBAL_RNG) where {F<:Function, RNG<:AbstractRNG}

Input:

  • f() simulates Bernoulli(p) random variates (of type Bool)
  • a >= 0
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(p^a) variate
  • flips is the number of calls of f()
BernoulliFactory.signedEstimateMethod

signedEstimate(μ::F1, φ::F2, a::Float64, b::Float64, δ::Float64, c::Float64, n::Int64, rng::RNG=GLOBAL_RNG) where {F1<:Function, F2<:Function, RNG<:AbstractRNG}

Input:

  • μ() simulates a random variate X
  • φ(X) is real-valued
  • a,b,δ,c satisfy a <= infx φ(x) < b < δ <= μ(φ) < supx φ(x) <= c
  • n specifies a number of X variables to average
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: Y, flips, calls

  • Y is almost surely valued in [b, max{2b-a,c}] with E[Y] = μ(φ)
  • flips is the number of coin tosses by the Bernoulli Factory algorithm
  • calls is the number of calls of μ() in total
BernoulliFactory.signedEstimateMethod

signedEstimate(μ::F1, φ::F2, c::Float64, δ::Float64, n::Int64, rng::RNG=GLOBAL_RNG) where {F1<:Function, F2<:Function, RNG<:AbstractRNG} where {F1<:Function, F2<:Function, RNG<:AbstractRNG}

Input:

  • μ() simulates a random variate X
  • φ(X) is real-valued
  • c satisfies sup_x |φ(x)| <= c
  • δ > 0 satisfies μ(φ) >= δ
  • n specifies a number of X variables to average
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: Y, flips, calls

  • Y is almost surely valued in [0.0,c] with E[Y] = μ(φ)
  • flips is the number of coin tosses by the Bernoulli Factory algorithm
  • calls is the number of calls of μ() in total
BernoulliFactory.sqrtMethod
sqrt(f::F, rng::RNG=GLOBAL_RNG) where {F<:Function, RNG<:AbstractRNG}

Input:

  • f() simulates Bernoulli(p) random variates (of type Bool)
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(sqrt(p)) variate
  • flips is the number of calls of f()
BernoulliFactory.twocoinMethod
twocoin(f1::F1, f2::F2, C1::Float64, C2::Float64, rng::RNG=GLOBAL_RNG) where {F1<:Function, F2<:Function, RNG<:AbstractRNG}

Input:

  • f1() simulates Bernoulli(p1) random variates (of type Bool)
  • f2() simulates Bernoulli(p2) random variates (of type Bool)
  • C1, C2 >= 0
  • [rng] the RNG to used by the algorithm (does not affect f)

Output: X, flips

  • X is a Bernoulli(C1p1/(C1p1+C2*p2)) variate
  • flips is the number of calls of f()