Shrinkage Slice (Slice)¶
Implementation of the shrinkage slice sampler of Neal [63] 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}, ::Type{F<:SliceForm}=Multivariate; transform::Bool=false)¶ Construct a
Sampler
object for 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 nodesparams
, defining initial widths of a hyperrectangle from which to simulate values.F
: sampler type. Options areUnivariate
: sequential univariate sampling of parameters .Multivariate
: joint multivariate sampling.
transform
: whether to sample parameters on the link-transformed scale (unconstrained parameter space). Iftrue
, then constrained parameters are mapped to unconstrained space according to transformations defined by the Stochasticunlist()
function, andwidth
is interpreted as being relative to the unconstrained parameter space. Otherwise, sampling is relative to the untransformed space.
Value
Returns aSampler{SliceTune{Univariate}}
orSampler{SliceTune{Multivariate}}
type object if sampling univariately or multivariately, respectively.Example
Stand-Alone Functions¶
-
sample!
(v::SliceUnivariate)¶ -
sample!
(v::SliceMultivariate) Draw one sample from a target distribution using the Slice univariate or multivariate sampler. Parameters are assumed to be continuous, but may be constrained or unconstrained.
Arguments
v
: current state of parameters to be simulated.
Value
Returnsv
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"]) width = [1.0, 1.0, 2.0] theta1 = SliceUnivariate([0.0, 0.0, 0.0], width, logf) theta2 = SliceMultivariate([0.0, 0.0, 0.0], width, logf) for i in 1:n sample!(theta1) sample!(theta2) sim1[i, :, 1] = [theta1[1:2]; exp(theta1[3])] sim2[i, :, 1] = [theta2[1:2]; exp(theta2[3])] end describe(sim1) describe(sim2)
Slice Variate Types¶
Declaration¶
typealias SliceUnivariate SamplerVariate{SliceTune{Univariate}}
typealias SliceMultivariate SamplerVariate{SliceTune{Multivariate}}
Fields¶
value::Vector{Float64}
: simulated values.tune::SliceTune{F<:SliceForm}
: tuning parameters for the sampling algorithm.
Constructors¶
-
SliceUnivariate
(x::AbstractVector{T<:Real}, width::ElementOrVector{U<:Real}, logf::Function)¶ -
SliceMultivariate
(x::AbstractVector{T<:Real}, width::ElementOrVector{U<:Real}, logf::Function)¶ Construct an object that stores simulated values and tuning parameters for Slice sampling.
Arguments
x
: initial values.width
: scaling value or vector of the same length as the combined elements of nodesparams
, defining initial widths of a hyperrectangle from which to simulate values.logf
: function that takes a singleDenseVector
argument of parameter values at which to compute the log-transformed density (up to a normalizing constant).
Value
Returns an object of the same type as the constructor name for univariate or multivariate sampling, respectively, with fields set to the suppliedx
and tuning parameter values.
SliceTune Type¶
Declaration¶
typealias SliceForm Union{Univariate, Multivariate}
type SliceTune{F<:SliceForm} <: SamplerTune
Fields¶
logf::Nullable{Function}
: function supplied to the constructor to compute the log-transformed density, or null if not supplied.width::Union{Float64, Vector{Float64}}
: initial widths of hyperrectangles from which to simulate values.