Public API

ARSampling.ARSamplerType
ARSampler(
    obj::Objective{F, G},
    domain::Tuple{T, T},
    initial_points::Vector{T}
) where {T <: AbstractFloat, F <: Function, G <: Function}

ARSampler(
    obj::Objective{F, G},
    domain::Tuple{T, T},
    search_range::Tuple{T, T} = (-10.0, 10.0),
    search_step = 0.1
) where {T <: AbstractFloat, F <: Function, G <: Function}

Initialize an adaptive rejection sampler over an objective function from obj (ARSampling.Objective). initial_points should be a vector defining the abscissae of the initial segments of the sampler. At least 2 of the points should be on opposite sides of the objective function's maximum.

If no initial_points an attempt to find suitable ones will be made by searching for the first negative/positive slope of obj. The default search range is -10:10 with a step of 0.1.

Warning

As it currently stands, finding inital points will fail for distributions bounded to the left/right of their maximum. In these cases the initial point(s) need to be provided manually (however, only a single initial point has to be provided).

ARSampler(objective, upper_hull, lower_hull)

defined at /home/runner/work/ARSampling.jl/ARSampling.jl/src/ARSampling.jl:320.

ARSampler(obj, domain, initial_points)

defined at /home/runner/work/ARSampling.jl/ARSampling.jl/src/ARSampling.jl:356.

ARSampler(obj, domain; ...)
ARSampler(obj, domain, search_range; search_step)

defined at /home/runner/work/ARSampling.jl/ARSampling.jl/src/ARSampling.jl:369.

ARSampling.ObjectiveType
Objective(f; ...)
Objective(f, init; adbackend)

Create an Objective for a function automatically generating its gradient. Gradients are calculated using DifferentiationInterface.jl using the backend of choice with ForwardDiff.jl being the default. In order to prepare the gradient an initial value is required. By default this is one(Float64). If a gradient for a different type is desired, it should be specified through this initial value.

If a custom/manual gradient is available it may instead be provided.

Warning

Observe that f should be in its log-concave form and that no checks are performed in order to verify this.

Example

# Create an objective using `Mooncake.jl` autodiff and Float32 as its type.
ARS.Objective(somefun, one(Float32); adbackend = AutoMooncake(; config=nothing))
# Create an objective using the defaults `AutoDiff.jl` autodiff and Float64 as its type.
ARS.Objective(somefun)
ARSampling.ObjectiveMethod
Objective(
    f::Function,
    grad::Function
) -> ARSampling.Objective{<:Function, <:Function, Float64}
Objective(
    f::Function,
    grad::Function,
    ::Type{T<:Number}
) -> ARSampling.Objective

Create an Objective directly defined by its function f and custom gradient grad. The parameter T represents the type of the expected input and is utilized when preparing gradients using autodiff. By default T = Float64.

Warning

Observe that f should be in its log-concave form and that no checks are performed in order to verify this.

ARSampling.sample!Function
sample!([rng=default_rng()], s::ARSampler, n::Integer, add_segments::Bool=true)
sample!([rng=default_rng()], v::AbstractVector, s::ARSampler, add_segments::Bool=true)

Draw samples from s. If supplied, a vector v will be filled with samples. Otherwise the number of samples is specified with n.