BaytesSMC.jl

BaytesSMC.jl is a library to perform SMC proposal steps on `ModelWrapper` structs, see ModelWrappers.jl. Kernels that are defined in BaytesMCMC.jl and BaytesFilters.jl can be used inside this library.
Author paschermayr
Popularity
0 Stars
Updated Last
11 Months Ago
Started In
February 2022

BaytesSMC

Documentation, Stable Build Status Coverage ColPrac: Contributor's Guide on Collaborative Practices for Community Packages

BaytesSMC.jl is a library to perform SMC proposal steps on ModelWrapper structs, see ModelWrappers.jl. Kernels that are defined in BaytesMCMC.jl and BaytesFilters.jl can be used inside this library.

BaytesSMC.jl supports sequential parameter estimation frameworks such as IBIS and SMC2. This can be achieved via data tempering, which is explained in more detail in the upcoming Baytes.jl library. Moreover, a SMC variant for batch data is provided as well, where tempering of the objective function is used until the temperature reaches 1.0.

First steps

All standard Baytes.jl functions call can be used in BaytesSMC.jl. To start with, we have to define parameter and an objective function first. Let us use the model initially defined in the ModelWrappers.jl introduction:

using ModelWrappers, BaytesSMC
using Distributions, Random, UnPack
_rng = Random.GLOBAL_RNG
#Create Model and data
myparameter == Param(Normal(), 0.0, ), σ = Param(Gamma(), 1.0, ))
mymodel = ModelWrapper(myparameter)
data = randn(1000)
#Create objective for both μ and σ and define a target function for it
myobjective = Objective(mymodel, data, (, ))
function (objective::Objective{<:ModelWrapper{BaseModel}})(θ::NamedTuple)
	@unpack data = objective
	lprior = Distributions.logpdf(Distributions.Normal(),θ.μ) + Distributions.logpdf(Distributions.Exponential(), θ.σ)
    llik = sum(Distributions.logpdf( Distributions.Normal.μ, θ.σ), data[iter] ) for iter in eachindex(data))
	return lprior + llik
end

A particle in the SMC framework corresponds to a full model. We will assign assign a NUTS sampler for each particle, and propose new parameter via SMC in the standard Bayes.jl framework:

using BaytesMCMC
smc = SMC(_rng, MCMC(NUTS,(, ,)), myobjective)
propose!(_rng, smc, mymodel, data)

Customization

Construction is highly flexible, and can be tweaked via keyword assignments in the following helper structs:

kerneldefault  = SMCDefault(Ntuning = 50, jittermin = 1, jittermax = 10)
samplingdefault = SampleDefault(chains = 10)
SMC(_rng, MCMC(NUTS,(, ,)), myobjective, kerneldefault, samplingdefault)

kerneldefault consists of tuning parameter that are specific for SMC, samplingdefault consists of tuning parameter that are observed over the whole sampling process. The latter is explained in more detail in Baytes.jl.

Going Forward

This package is still highly experimental - suggestions and comments are always welcome!