Sampler¶
The Sampler
type stores model-based Sampling Functions for use in the Mamba Gibbs sampling scheme. Developers can use it as a wrapper for calling stand-alone samplers or as a structure for implementing self-contained samplers.
Declaration¶
type Sampler{T}
Fields¶
params::Vector{Symbol}
: stochastic nodes in the block being updated by the sampler.eval::Function
: sampling function that updates values of theparams
nodes.tune::T
: tuning parameters needed by the sampling function.targets::Vector{Symbol}
:Dependent
nodes that depend on and whose states must be updated afterparams
. Elements oftargets
are topologically sorted so that a given node in the vector is conditionally independent of subsequent nodes, given the previous ones.
Constructors¶
-
Sampler
(param::Symbol, f::Function, tune::Any=Dict())¶ -
Sampler
(params::Vector{Symbol}, f::Function, tune::Any=Dict()) Construct a
Sampler
object that defines a sampling function for a block of stochastic nodes.Arguments
param/params
: node(s) being block-updated by the sampler.f
: function for theeval
field of the constructed sampler and whose arguments are the other model nodes upon which the sampler depends, typed argumentmodel::Model
that contains all model nodes, and/or typed argumentblock::Integer
that is an index identifying the corresponding sampling function in a vector of all samplers for the associated model. Through the arguments, all model nodes and fields can be accessed in the body of the function. The function may return an updated sample for the nodes identified in itsparams
field. Such a return value can be a structure of the same type as the node if the block consists of only one node, or a dictionary of node structures with keys equal to the block node symbols if one or more. Alternatively, a value ofnothing
may be returned. Return values that are notnothing
will be used to automatically update the node values and propagate them to dependent nodes. No automatic updating will be done ifnothing
is returned.tune
: tuning parameters needed by the sampling function.
Value
Returns aSampler{typeof(tune)}
type object.Example
See the Sampling Schemes section of the tutorial.
SamplerVariate¶
The SamplerVariate
type is designed to store simulated values from and tuning parameters for stand-alone Sampling Functions. It is a parametric type whose parameter can be any subtype of the abstract SamplerTune
type and serves to identify the family of sampling functions to which the variate belongs.
Declaration¶
abstract type SamplerTune
type SamplerVariate{T<:SamplerTune} <: VectorVariate
Fields¶
value::Vector{Float64}
: simulated values.tune::T
: tuning parameters.
Constructors¶
-
SamplerVariate
(x::AbstractVector{U<:Real}, tune::SamplerTune)¶ -
SamplerVariate{T<:SamplerTune}
(x::AbstractVector{U<:Real}, tune::T)¶ -
SamplerVariate{T<:SamplerTune}
(x::AbstractVector{U<:Real}, pargs...; kargs...) Construct a
SamplerVariate
object for storing simulated values and tuning parameters.Arguments
x
: simulated values.tune
: tuning parameters. If not specified, the tuning parameter constructor is called with thevalue
field of the variate to instantiate the parameters.T
: explicit tuning parameter type for the variate. If not specified, the type is inferred from thetune
argument.pargs...
,kargs...
: variable positional and keyword arguments that are passed, along with thevalue
field of the variate, to the tuning parameter constructor asT(value, pargs...; kargs...)
. Accordingly, the arguments that this version of theSamplerVariate{T}
constructor accepts are defined by theT
constructors implemented for it.
Value
Returns a
SamplerVariate{T}
type object with fields set to the suppliedx
and tuning parameter values.