I’m working on a new interface for chains from MCMC sampling:
I’ve copied the README below. I’d love any feedback on the interface, or ideas for making it more useful and/or powerful.
Gratuitous @-ing…
- @Tamas_Papp there’s an interface to DynamicHMC here. More back-ends on the way
- @theogf we should come up with a nice way to incorporate callbacks so this works well with Turkie.jl
- @baggepinnen I think I had been stretching MonteCarloMeasurements.jl beyond its intended use. Now we should be able to load
Particles
into a column and easily compute row-by-row. - @sethaxen, @cpfiffer, and I talked a little bit about moving diagnostics from MCMCChains to a lighter-weight package here
Example Use
Using SampleChainsDynamicHMC.jl
, Soss can sample with very little Soss-specific code. I want to tidy this up more, but here’s how it looks now:
using Soss
using SampleChains
using SampleChainsDynamicHMC
pr = @model k begin
σ ~ Exponential()
α ~ Cauchy()
β ~ Normal() |> iid(k)
end;
ℓ(x) = logdensity(pr(k=5), x);
t = xform(pr(k=5));
chain1 = initialize!(DynamicHMCChain, ℓ, t);
drawsamples!(chain1,1000)
chain2 = initialize!(DynamicHMCChain, ℓ, t);
drawsamples!(chain2,1000)
chain3 = initialize!(DynamicHMCChain, ℓ, t);
drawsamples!(chain3,1000)
chains = MultiChain(chain1, chain2, chain3)
From the README
julia> chains
3003-element MultiChain with 3 chains and schema (σ = Float64, α = Float64, β = Vector{Float64})
(σ = 0.9±0.88, α = -5.1±10.0, β = [-0.0±0.9, 0.04±0.99, 0.04±1.1, 0.02±0.92, 0.06±0.95])
Some features (many still in progress):
- Simple visual representation
- “Samples first”, though diagnostic information is easily available
- Each
Chain
can be indexed as a Vector, or as a NamedTuple - Interrupting (CTRL-C) returns the current chain, including iterator information so work can be resumed
- Built on ElasticArrays to make it easy to add new samples after the fact
- Adaptable to many different sampling algorithms, including with or without (log-)weights
- Easy summarization functions: expectations per-dimension quantiles, etc
In progress:
- More back-ends (currently just DynamicHMC, using SampleChainsDynamicHMC)
- Diagnostic warnings during sampling
- Callbacks for plotting, etc
- Sample count based on desired standard error of a specified expected value
- Summarization by different functions
- Highest posterior density intervals
- R-hat statistics