CurrentModule = Pigeons
Use sample_array()
to convert target chain
samples into a format that can then be consumed by the
third party package
MCMCChains.jl.
We outline some useful features here, read
the MCMCChains.jl documentation for more information.
Make sure to have the third party packages DynamicPPL
and MCMCChains
installed via
using Pkg; Pkg.add("DynamicPPL", "MCMCChains")
Also make sure to record the trace, with record = [traces]
:
using DynamicPPL
using Pigeons
using MCMCChains
# example target: Binomial likelihood with parameter p = p1 * p2
an_unidentifiable_model = Pigeons.toy_turing_unid_target(100, 50)
pt = pigeons(
target = an_unidentifiable_model,
record = [traces; round_trip; record_default()]
)
# collect the statistics and convert to MCMCChains' Chains
# to have axes labels matching variable names in Turing and Stan
samples = Chains(pt)
samples
Computing a mean (but see [online statistics](@ref output-online) for a constant memory alternative):
using Statistics
m = mean(samples)
to access an individual entry in this example and the following ones:
m[:p1, :mean]
Highest posterior density interval:
hpd(samples, alpha = 0.05)
For ESS estimates:
ess(samples)