Statistics

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.

Abstract type for all samplers

Interface

  • show(io::IO, sampler): print verbose information for a sampler

  • algorithm(sampler) -> String: print algorithm name

  • state(sampler) -> SamplerState: get sampler state

source

Abstract type for all sampler state

source
QMTK.SamplePlanType.

Sample Plan contains a distribution and a sampler.

Interface

  • state(plan::SamplePlan) -> SamplerState: get sampler's state

  • update!(plan::SamplePlan) -> SamplePlan: update sample plan according to the sampler

  • show(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)).

source
QMTK.stateMethod.
state(plan)

get sampler's state in SamplePlan

source
QMTK.update!Method.
update!(plan)

update plan accroding to certain sampler

source
QMTK.sample!Method.
sample!(plan) -> data

execute your sample plan

source
QMTK.sample!Method.
sample!(pool, plan; nchain=4) -> data

execute your sample plan according to a WorkPool

source
QMTK.sample!Method.
sample!(nchain, plan) -> data

execute your sample plan in parallel, with n chains.

source
QMTK.MHSamplerType.
MHSampler{SampleType} <: AbstractSampler

MHSampler 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 iterations

  • burn: number of burned iterations

  • thin: number of jumps after each measure

source