Reference

Contents

Index

RejectionSamplers.AbstractProposalDistributionType
AbstractProposalDistribution{Ts, Tw, F <: ProposalVariateForm}

Abstract supertype for all proposal distributions.

Type parameters:

  • Ts: sample type
  • Tw: weight type
  • F: variate form (Univariate or CoordinateVariate)
source
RejectionSamplers.CoordinateVariateType
CoordinateVariate <: Distributions.VariateForm

Variate form where arguments are SVectors of scalars representing coordinates.

Note

For univariate proposals, use Distributions.Univariate

source
RejectionSamplers._computeFunction
_compute(dist::AbstractUnivariatTargetDistribution,x::Real)::Real
_compute(dist::AbstractMultivariateTarget,x::SVector{2,Real})::Real

Return value of dist computed at x.

source
RejectionSamplers._findmaxFunction
_findmax(method::AbstractSampleBasedMaxFinder, weights::AbstractVector{T})::T where {T<:Real}

Interface function for sample based max-finder. Return the maximum weight of a given vector weights according to method.

source
RejectionSamplers._gpu_proposeMethod
_gpu_propose(proposal::AbstractTransformProposal{TT}, threadid, randstate)
    -> (sample, weight)

Thread-local GPU version of proposal sampling.

source
RejectionSamplers._nsamplesFunction
_nsamples(method::AbstractSampleBasedMaxFinder)

Interface function for sample-based max-finder. Returns the number of samples to be generated for max-finding.

source
RejectionSamplers._propose!Method
_propose!(
    rng::AbstractRNG,
    proposal::AbstractProposalDistribution,
    samples::AbstractVector,
    weights::AbstractVector;
    backend = KernelAbstractions.CPU(),
)

Propose samples and weights for the given backend.

For CPU backends, falls back to _propose_single. For GPU backends, must be specialized explicitly.

source
RejectionSamplers._propose_on_deviceFunction

proposeon_device!( rng::GPUArrays.RNG, proposal::AbstractProposalDistribution, samples::AbstractVector, weights::AbstractVector, backend::KernelAbstractions.Backend, )

The on-device version of _propose!. This should be extended, if device specific implementations for _propose! are needed.

source
RejectionSamplers._transformFunction
_transform(proposal::AbstractTransformProposal{T}, unit_coord::T)
    -> (sample, weight)

Transform unit random coordinates into the target sample space. Return the transformed sample and its associated proposal weight.

source
RejectionSamplers.default_rngFunction
default_rng(v::AbstractVector)

Return default rng to randomize given vector. Uses fallbacks on Random.default_rng and GPUArrays.default_rng.

source
RejectionSamplers.filter_scanMethod
filter_scan(payload, weights, randoms, out_payload, out_weights, out_size)

KernelAbstractions kernel. Filters the payload array by comparing the respective elements of weights < randoms. Fills the indices out_size - out_size + N of the given buffers out_payload and out_weights with all accepted values, where N is the number of accepted values. Also assigns out_size += N.

Parameters

  • input payload: array of the payload
  • input weights: array of weights (normalized to [0,1]; outliers allowed, see out_weights; "probabilities")
  • input randoms: array of uniform random independent scalar values [0,1]
  • output out_payload: buffer for accepted payload to be written
  • output out_weights: buffer for accepted weights to be written; every accepted weight will be 1.0, or the original weight if it was larger than 1.0
  • input/output out_size: a global memory variable (array of length 1) containing the current number of elements in out_payload and out_weights
Warn

No inbounds checks are performed anywhere! Take care that payload, weights and randoms are all of the same length M, and that out_payload and out_weights have at least M+out_size length.

Warn

out_size must be set correctly (to the number of set elements in out_payload and out_weights) before calling the kernel. Also note that Int64 is not supported on some backends (Metal.jl and oneAPI.jl).

source
RejectionSamplers.maximum_valueFunction
maximum_value(dist::AbstractTargetDistribution)

Interface function: return the (approximate) maximum_value of a given target distribution.

source
RejectionSamplers.propose!Method
propose!(
    proposal::AbstractProposalDistribution,
    samples::AbstractVector,
    weights::AbstractVector;
    rng = default_rng(typeof(samples)),
    backend = get_backend(samples)
) -> Nothing

Convenience wrapper that infers both the RNG and backend from the destination arrays.

source
RejectionSamplers.propose!Method
propose!(
    rng::AbstractRNG,
    proposal::AbstractProposalDistribution,
    samples::AbstractVector,
    weights::AbstractVector;
    backend = get_backend(samples)
) -> Nothing

Fill samples and weights with proposals generated by proposal.

The backend is inferred from the array type of samples by default, but can be overridden via the backend keyword.

Throws an ArgumentError if samples and weights have mismatched lengths.

source
RejectionSamplers.propose_singleMethod
propose_single(proposal::AbstractProposalDistribution) -> (sample, weight)

Draw a single (sample, weight) pair from proposal using the global default RNG.

Warning

This only works on CPU.

source