Reference
KissABC.KissABC
KissABC.ABCplan
KissABC.Factored
Base.length
Base.rand
Distributions.pdf
KissABC.ABC
KissABC.ABCDE
KissABC.ABCSMCPR
KissABC.compute_kernel_scales
KissABC.deperturb
KissABC.kernel
KissABC.kerneldensity
KissABC.perturb
KissABC.sample_plan
KissABC.KissABC
— ModuleKissABC
Module to perform approximate bayesian computation,
Simple Example: inferring the mean of a Normal
distribution
using KissABC
using Distributions
prior=Normal(0,1)
data=randn(1000) .+ 1
sim(μ,other)=randn(1000) .+ μ
dist(x,y) = abs(mean(x) - mean(y))
plan=ABCplan(prior, sim, data, dist)
μ_post,Δ = ABCDE(plan, 1e-2)
@show mean(μ_post) ≈ 1.0
for more complicated code examples look at https://github.com/francescoalemanno/KissABC.jl/
KissABC.ABCplan
— TypeABCplan(prior, simulation, data, distance; params=())
Builds a type ABCplan
which holds
Arguments:
prior
: aDistribution
to use for sampling candidate parameterssimulation
: simulation functionsim(prior_sample, constants) -> data
that accepts a prior sample and theparams
constant and returns a simulated datasetdata
: target dataset which must be compared with simulated datasetsdistance
: distance functiondist(x,y)
that return the distance (a scalar value) betweenx
andy
params
: an optional set of constants to be passed as second argument to the simulation function
KissABC.Factored
— TypeFactored{N} <: Distribution{Multivariate, MixedSupport}
a Distribution
type that can be used to combine multiple UnivariateDistribution
's and sample from them.
Example: it can be used as prior = Factored(Normal(0,1), Uniform(-1,1))
KissABC.ABC
— MethodABC(plan, α_target; nparticles = 100, parallel = false)
Classical ABC rejection algorithm.
Arguments:
plan
: a plan built using the function ABCplan.α_target
: target acceptance rate for ABC rejection algorithm,nparticles/α
will be sampled and only the bestnparticles
will be retained.nparticles
: number of samples from the approximate posterior that will be returnedparallel
: when set totrue
multithreaded parallelism is enabled
KissABC.ABCDE
— MethodABCDE(plan, ϵ_target; nparticles=100, generations=500, α=0, parallel=false, verbose=true)
A sequential monte carlo algorithm inspired by differential evolution, very efficient (simpler version of B.M.Turner 2012, https://doi.org/10.1016/j.jmp.2012.06.004)
Arguments:
plan
: a plan built using the function ABCplan.ϵ_target
: maximum acceptable distance between simulated datasets and the target datasetnparticles
: number of samples from the approximate posterior that will be returnedgenerations
: total number of simulations per particleα
: controls the ϵ for each simulation round as ϵ = m+α*(M-m) where m,M = extrema(distances)parallel
: when set totrue
multithreaded parallelism is enabledverbose
: when set totrue
verbosity is enabled
KissABC.ABCSMCPR
— FunctionABCSMCPR(plan, ϵ_target; nparticles = 100, maxsimpp = 1000.0, α = 0.3, c = 0.01, parallel = false, verbose = true)
Sequential Monte Carlo algorithm (Drovandi et al. 2011, https://doi.org/10.1111/j.1541-0420.2010.01410.x).
Arguments:
plan
: a plan built using the function ABCplan.ϵ_target
: maximum acceptable distance between simulated datasets and the target datasetnparticles
: number of samples from the approximate posterior that will be returnedmaxsimpp
: average maximum number of simulations per particleα
: proportion of particles to retain at every iteration of SMC, other particles are resampledc
: probability that a sample will not be updated during one iteration of SMCparallel
: when set totrue
multithreaded parallelism is enabledverbose
: when set totrue
verbosity is enabled
KissABC.sample_plan
— Methodsample_plan(plan::ABCplan, nparticles, parallel)
function to sample the prior distribution of both parameters and distances.
Arguments:
plan
: a plan built using the function ABCplan.nparticles
: number of samples to draw.parallel
: enable or disable threaded parallelism viatrue
orfalse
.
Base.length
— Methodlength(p::Factored) = begin
returns the number of distributions contained in p
.
Base.rand
— Methodrand(rng::AbstractRNG, factoreddist::Factored)
function to sample one element from a Factored
object
Distributions.pdf
— Methodpdf(d::Factored, x) = begin
Function to evaluate the pdf of a Factored
distribution object
KissABC.compute_kernel_scales
— Functioncompute_kernel_scales(prior::Distribution, V)
Function for ABCSMCPR
whose purpose is to compute the characteristic scale of the perturbation kernel appropriate for prior
given the Vector V
of parameters
KissABC.deperturb
— Functiondeperturb(prior::Distribution, sample, r1, r2, γ)
Function for ABCDE
whose purpose is computing sample + γ (r1 - r2) + ϵ
(the perturbation function of differential evolution) in a way suited to the prior.
Arguments:
prior
sample
r1
r2
KissABC.kernel
— Functionkernel(prior::Distribution, c, scale)
Function for ABCSMCPR
whose purpose is returning the appropriate Distribution
to use as a perturbation kernel on sample c
and characteristic scale
Arguments:
prior
: prior distributionc
: sample acting as center of perturbation kernelscale
: characteristic scale of perturbation kernel
KissABC.kerneldensity
— Functionkerneldensity(prior::Distribution, scales, s1, s2)
Function for ABCSMCPR
whose purpose is returning the probability density of observing s2
under the kernel centered on s1
with scales given by scales
and appropriate for prior
.
KissABC.perturb
— Functionperturb(prior::Distribution, scales, sample)
Function for ABCSMCPR
whose purpose is perturbing sample
according to the appropriate kernel
for prior
with characteristic scales
.