Shrinkage Slice (Slice)

Implementation of the shrinkage slice sampler of Neal [61] for simulating autocorrelated draws from a distribution that can be specified up to a constant of proportionality.

Model-Based Constructor

Slice(params::ElementOrVector{Symbol}, width::ElementOrVector{T<:Real}, stype::Symbol=:multivar; transform::Bool=false)

Construct a Sampler object for shrinkage slice sampling. Parameters are assumed to be continuous, but may be constrained or unconstrained.

Arguments

  • params : stochastic node(s) to be updated with the sampler.

  • width : scaling value or vector of the same length as the combined elements of nodes params, defining initial widths of a hyperrectangle from which to simulate values.

  • stype : sampler type. Options are
    • :multivar : Joint multivariate sampling of parameters.
    • :univar : Sequential univariate sampling.
  • transform : whether to sample parameters on the link-transformed scale (unconstrained parameter space). If true, then constrained parameters are mapped to unconstrained space according to transformations defined by the Stochastic unlist() function, and width is interpreted as being relative to the unconstrained parameter space. Otherwise, sampling is relative to the untransformed space.

Value

Returns a Sampler{SliceTune} type object.

Example

See the Birats, Rats, and other Examples.

Stand-Alone Function

slice!(v::SliceVariate, width::ElementOrVector{T<:Real}, logf::Function, stype::Symbol=:multivar)

Simulate one draw from a target distribution using a shrinkage slice sampler. Parameters are assumed to be continuous, but may be constrained or unconstrained.

Arguments

  • v : current state of parameters to be simulated.

  • width : scalar or vector of the same length as v, defining initial widths of a hyperrectangle from which to simulate values.

  • logf : function that takes a single DenseVector argument of parameter values at which to compute the log-transformed density (up to a normalizing constant).

  • stype : sampler type. Options are
    • :multivar : Joint multivariate sampling of parameters.
    • :univar : Sequential univariate sampling.

Value

Returns v updated with simulated values and associated tuning parameters.

Example

The following example samples parameters in a simple linear regression model. Details of the model specification and posterior distribution can be found in the Supplement. Also, see the Line: Block-Specific Sampling with AMWG and Slice example.

################################################################################
## Linear Regression
##   y ~ N(b0 + b1 * x, s2)
##   b0, b1 ~ N(0, 1000)
##   s2 ~ invgamma(0.001, 0.001)
################################################################################

using Mamba

## Data
data = Dict(
  :x => [1, 2, 3, 4, 5],
  :y => [1, 3, 3, 3, 5]
)

## Log-transformed Posterior(b0, b1, log(s2)) + Constant
logf = function(x::DenseVector)
   b0 = x[1]
   b1 = x[2]
   logs2 = x[3]
   r = data[:y] - b0 - b1 * data[:x]
   (-0.5 * length(data[:y]) - 0.001) * logs2 -
     (0.5 * dot(r, r) + 0.001) / exp(logs2) -
     0.5 * b0^2 / 1000 - 0.5 * b1^2 / 1000
end

## MCMC Simulation with Slice Sampling
## With multivariate (1) and univariate (2) updating
n = 5000
sim1 = Chains(n, 3, names = ["b0", "b1", "s2"])
sim2 = Chains(n, 3, names = ["b0", "b1", "s2"])
theta1 = SliceVariate([0.0, 0.0, 0.0])
theta2 = SliceVariate([0.0, 0.0, 0.0])
width = [1.0, 1.0, 2.0]
for i in 1:n
  slice!(theta1, width, logf, :multivar)
  slice!(theta2, width, logf, :univar)
  sim1[i, :, 1] = [theta1[1:2]; exp(theta1[3])]
  sim2[i, :, 1] = [theta2[1:2]; exp(theta2[3])]
end
describe(sim1)
describe(sim2)

SliceVariate Type

Declaration

typealias SliceVariate SamplerVariate{SliceTune}

Fields

  • value::Vector{Float64} : simulated values.
  • tune::SliceTune : tuning parameters for the sampling algorithm.

Constructors

SliceVariate(x::AbstractVector{T<:Real})
SliceVariate(x::AbstractVector{T<:Real}, tune::SliceTune)

Construct a SliceVariate object that stores simulated values and tuning parameters for slice sampling.

Arguments

  • x : simulated values.
  • tune : tuning parameters for the sampling algorithm. If not supplied, parameters are set to their defaults.

Value

Returns a SliceVariate type object with fields set to the values supplied to arguments x and tune.

SliceTune Type

Declaration

type SliceTune <: SamplerTune

Fields

  • width::Union{Real, Vector} : initial widths defining hyperrectangles from which to simulate values.