Binary Metropolised Gibbs (BMG)¶
Implementation of the binary-state Metropolised Gibbs sampler described by Schafer [81][82] in which components are drawn sequentially from full conditional marginal distributions and accepted together in a single Metropolis-Hastings step. The sampler simulates autocorrelated draws from a distribution that can be specified up to a constant of proportionality.
Model-Based Constructor¶
-
BMG
(params::ElementOrVector{Symbol}; args...)¶ Construct a
Sampler
object for BMG sampling. Parameters are assumed to have binary numerical values (0 or 1).Arguments
params
: stochastic node(s) to be updated with the sampler.args...
: additional keyword arguments to be passed to theBMGVariate
constructor.
Value
Returns aSampler{BMGTune}
type object.Example
Stand-Alone Function¶
-
sample!
(v::BMGVariate)¶ Draw one sample from a target distribution using the BMG sampler. Parameters are assumed to have binary numerical values (0 or 1).
Arguments
v
: current state of parameters to be simulated.
Value
Returnsv
updated with simulated values and associated tuning parameters.Example
################################################################################ ## Linear Regression ## y ~ MvNormal(X * (beta0 .* gamma), 1) ## gamma ~ DiscreteUniform(0, 1) ################################################################################ using Mamba ## Data n, p = 25, 10 X = randn(n, p) beta0 = randn(p) gamma0 = rand(0:1, p) y = X * (beta0 .* gamma0) + randn(n) ## Log-transformed Posterior(gamma) + Constant logf = function(gamma::DenseVector) logpdf(MvNormal(X * (beta0 .* gamma), 1.0), y) end ## MCMC Simulation with Binary Metropolised Gibbs t = 10000 sim = Chains(t, p, names = map(i -> "gamma[$i]", 1:p)) gamma = BMGVariate(zeros(p), logf) for i in 1:t sample!(gamma) sim[i, :, 1] = gamma end describe(sim)
BMGVariate Type¶
Declaration¶
typealias BMGVariate SamplerVariate{BMGTune}
Fields¶
value::Vector{Float64}
: simulated values.tune::BMGTune
: tuning parameters for the sampling algorithm.
Constructor¶
-
BMGVariate
(x::AbstractVector{T<:Real}, logf::Function; k::Integer=1)¶ Construct a
BMGVariate
object that stores simulated values and tuning parameters for BMG sampling.Arguments
x
: initial values.logf
: function that takes a singleDenseVector
argument of parameter values at which to compute the log-transformed density (up to a normalizing constant).k
: number of parameters to select at random for simultaneous updating in each call of the sampler.
Value
Returns aBMGVariate
type object with fields set to the suppliedx
and tuning parameter values.