tokamaster / TransitionalMCMC.jl

Implementation of Transitional Markov Chain Monte Carlo (TMCMC) in Julia.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TransitionalMCMC.jl

Implementation of Transitional Markov Chain Monte Carlo (TMCMC) in Julia. This implementation is heavily inspired by the implemntation of TMCMC in OpenCOSSAN.

The TMCMC alorgithm can be used to sample from un-normalised probability density function (i.e. posterior distributions in Bayesian Updating). The TMCMC alorgithm overcomes some of the issues with Metropolis Hastings:

  • Can efficiently sample multimodal distributions
  • Works well in high dimensions (within reason)
  • Computes the evidence
  • Proposal distribution selected by algorithm
  • Easy to parallelise

Instead of atempting to directly sample from the posterior, TMCMC samples from easy-to-sample "transitional" distributions. Defined by:

where 0 <= Bj <= 1, is iterated in the algorithm starting from Bj = 0 (prior) to Bj = 1 (posterior).

Installation

This is not yet a registered julia package. However this package may be installed using the Julia package manager:

julia> ]
pkg> add https://github.com/AnderGray/TransitionalMCMC.jl

Usage

Sampling Himmelblau's Function:

using StatsBase, Distributions, PyPlot
using TransitionalMCMC

# Prior Bounds
lb  = -5        
ub  = 5

# Prior Density and sampler
priorDen(x) = pdf(Uniform(lb,ub), x[1,:]) .* pdf(Uniform(lb,ub), x[2,:])
priorRnd(Nsamples) = rand(Uniform(lb,ub), Nsamples, 2)

# Log Likelihood
logLik(x) = -1 .* ((x[1,:].^2 .+ x[2,:] .- 11).^2 .+ (x[1,:] .+ x[2,:].^2 .- 7).^2)

samps, Log_ev = tmcmc(logLik, priorDen, priorRnd, 2000)

plt.scatter(samps[:,1], samps[:,2])

For parallel excution

using Distributed, StatsBase, Distributions, PyPlot

addprocs(4; exeflags="--project")
@everywhere begin
    using TransitionalMCMC

    # Prior Bounds
    lb, ub  = -5, 5

    # Prior Density and sampler
    priorDen(x) = pdf(Uniform(lb, ub), x[1,:]) .* pdf(Uniform(lb, ub), x[2,:])
    priorRnd(Nsamples) = rand(Uniform(lb, ub), Nsamples, 2)

    # Log Likelihood
    function logLik(x)
        return -1 .* ((x[1,:].^2 .+ x[2,:] .- 11).^2 .+ (x[1,:] .+ x[2,:].^2 .- 7).^2)
    end

end

Nsamples = 200

samps, Log_ev = tmcmc(logLik, priorDen, priorRnd, Nsamples, 5, 2)

Todo

  • Plotting functions
  • Storing samples across iterations

Bibiography

About

Implementation of Transitional Markov Chain Monte Carlo (TMCMC) in Julia.

License:MIT License


Languages

Language:Julia 100.0%