Reference

KissABC.KissABCModule
KissABC

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/

source
KissABC.ABCplanType
ABCplan(prior, simulation, data, distance; params=())

Builds a type ABCplan which holds

Arguments:

  • prior: a Distribution to use for sampling candidate parameters
  • simulation: simulation function sim(prior_sample, constants) -> data that accepts a prior sample and the params constant and returns a simulated dataset
  • data: target dataset which must be compared with simulated datasets
  • distance: distance function dist(x,y) that return the distance (a scalar value) between x and y
  • params: an optional set of constants to be passed as second argument to the simulation function
source
KissABC.FactoredType
Factored{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))

source
KissABC.ABCMethod
ABC(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 best nparticles will be retained.
  • nparticles: number of samples from the approximate posterior that will be returned
  • parallel: when set to true multithreaded parallelism is enabled
source
KissABC.ABCDEMethod
ABCDE(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 dataset
  • nparticles: number of samples from the approximate posterior that will be returned
  • generations: total number of simulations per particle
  • α: controls the ϵ for each simulation round as ϵ = m+α*(M-m) where m,M = extrema(distances)
  • parallel: when set to true multithreaded parallelism is enabled
  • verbose: when set to true verbosity is enabled
source
KissABC.ABCSMCPRFunction
ABCSMCPR(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 dataset
  • nparticles: number of samples from the approximate posterior that will be returned
  • maxsimpp: average maximum number of simulations per particle
  • α: proportion of particles to retain at every iteration of SMC, other particles are resampled
  • c: probability that a sample will not be updated during one iteration of SMC
  • parallel: when set to true multithreaded parallelism is enabled
  • verbose: when set to true verbosity is enabled
source
KissABC.sample_planMethod
sample_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 via true or false.
source
Base.lengthMethod
length(p::Factored) = begin

returns the number of distributions contained in p.

source
Base.randMethod
rand(rng::AbstractRNG, factoreddist::Factored)

function to sample one element from a Factored object

source
Distributions.pdfMethod
pdf(d::Factored, x) = begin

Function to evaluate the pdf of a Factored distribution object

source
KissABC.compute_kernel_scalesFunction
compute_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

source
KissABC.deperturbFunction
deperturb(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
source
KissABC.kernelFunction
kernel(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 distribution
  • c: sample acting as center of perturbation kernel
  • scale: characteristic scale of perturbation kernel
source
KissABC.kerneldensityFunction
kerneldensity(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.

source
KissABC.perturbFunction
perturb(prior::Distribution, scales, sample)

Function for ABCSMCPR whose purpose is perturbing sample according to the appropriate kernel for prior with characteristic scales.

source