Statistics
Sampler
Samplers are certain type contains a sample space of AbstractSpace and some other parameters (like the number of iterations and etc.). For a given sampler on certain space, you can specify the sampling task by make a SamplePlan. A sample plan is a type contains the desired distribution and the sampler. To execute a SamplePlan, just simply use sample!, or you could call update! to run only one iteration.
A possible example could be
space = RealSpace(min=-4, max=4)
sampler = MHSampler(space)
@everywhere function normal(x::T) where T <: Real
factor = 1 / sqrt(2 * pi)
return factor * exp(- x^2/2)
end
plan = SamplePlan(normal, sampler)
data = sample!(plan)
# run parallel
# data = sample!(4, plan)
# or run with customed workerpool
# data = sample!(pool, plan)the macro @everywhere here is used to declare this function on different process, you won't need it if there is only one process.
QMTK.AbstractSampler — Type.Abstract type for all samplers
Interface
show(io::IO, sampler): print verbose information for a sampleralgorithm(sampler) -> String: print algorithm namestate(sampler) -> SamplerState: get sampler state
QMTK.SamplerState — Type.Abstract type for all sampler state
QMTK.SamplePlan — Type.Sample Plan contains a distribution and a sampler.
Interface
state(plan::SamplePlan) -> SamplerState: get sampler's stateupdate!(plan::SamplePlan) -> SamplePlan: update sample plan according to the samplershow(plan::SamplePlan): print verbose information
Note
using a list of distribution (probability) is also allowed. This means you have to define your list type as a subtype of AbstractVector and it has to support getindex method at least.
using a Function as your distribution is more common. And you can define your custom type of distribution function by define a subtype of Function with its call method (AKA function (f::YourFunctionType)(x)).
QMTK.state — Method.state(plan)get sampler's state in SamplePlan
QMTK.update! — Method.update!(plan)update plan accroding to certain sampler
QMTK.sample! — Method.sample!(plan) -> dataexecute your sample plan
QMTK.sample! — Method.sample!(pool, plan; nchain=4) -> dataexecute your sample plan according to a WorkPool
QMTK.sample! — Method.sample!(nchain, plan) -> dataexecute your sample plan in parallel, with n chains.
QMTK.MHSampler — Type.MHSampler{SampleType} <: AbstractSamplerMHSampler uses Metropolis-Hasting algorithm to sample a proposal distribution for sample type ST
MHSampler(space; itr=1000, burn=300, thin=1)Construct a MH sampler
itr: number of iterationsburn: number of burned iterationsthin: number of jumps after each measure