ArviZ.jl
FlexiChains contains an extension that allows you to convert a FlexiChain into an InferenceObjects.InferenceData (InferenceObjects.jl is one of the sublibraries of ArviZ.jl, and is re-exported by ArviZ).
InferenceObjects.convert_to_inference_data Function
InferenceObjects.convert_to_inference_data(
chain::FlexiChain{<:TKey}; group::Symbol = posterior, kwargs...
) where {TKey}Convert a FlexiChain to an InferenceObjects.InferenceData object.
The group keyword argument specifies the group name for the chain's parameters. The chain's extras are assigned to :sample_stats if group is :posterior, and to :sample_stats_<group> otherwise.
Other keyword arguments are passed to InferenceObjects.convert_to_dataset.
For example:
using InferenceObjects, FlexiChains, DynamicPPL, Distributions
@model function f(y)
x ~ Normal()
y ~ Normal(x)
end
model = f(1.0)
chn = FlexiChains._make_prior_chain(model, 100, 2)
idata = InferenceObjects.convert_to_inference_data(chn)posterior
┌ 100×2 Dataset ┐ ├───────────────┴─────────────────────────────────────── dims ┐ ↓ draw Sampled{Int64} 1:100 ForwardOrdered Regular Points, → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points ├───────────────────────────────────────────────────── layers ┤ :x eltype: Float64 dims: draw, chain size: 100×2 ├─────────────────────────────────────────────────── metadata ┤ Dict{String, Any} with 1 entry: "created_at" => "2026-09-01T08:11:20.339" └─────────────────────────────────────────────────────────────┘
sample_stats
┌ 100×2 Dataset ┐ ├───────────────┴───────────────────────────────────────── dims ┐ ↓ draw Sampled{Int64} 1:100 ForwardOrdered Regular Points, → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points ├─────────────────────────────────────────────────────── layers ┤ :logprior eltype: Float64 dims: draw, chain size: 100×2 :loglikelihood eltype: Float64 dims: draw, chain size: 100×2 :logjoint eltype: Float64 dims: draw, chain size: 100×2 ├───────────────────────────────────────────────────── metadata ┤ Dict{String, Any} with 1 entry: "created_at" => "2026-09-01T08:11:20.934" └───────────────────────────────────────────────────────────────┘
You can combine multiple InferenceData objects with merge:
llike_chn = DynamicPPL.pointwise_loglikelihoods(model, chn)
idata2 = InferenceObjects.convert_to_inference_data(llike_chn; group=:log_likelihood)
idata_merged = merge(idata, idata2)posterior
┌ 100×2 Dataset ┐ ├───────────────┴─────────────────────────────────────── dims ┐ ↓ draw Sampled{Int64} 1:100 ForwardOrdered Regular Points, → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points ├───────────────────────────────────────────────────── layers ┤ :x eltype: Float64 dims: draw, chain size: 100×2 ├─────────────────────────────────────────────────── metadata ┤ Dict{String, Any} with 1 entry: "created_at" => "2026-09-01T08:11:20.339" └─────────────────────────────────────────────────────────────┘
log_likelihood
┌ 100×2 Dataset ┐ ├───────────────┴─────────────────────────────────────── dims ┐ ↓ draw Sampled{Int64} 1:100 ForwardOrdered Regular Points, → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points ├───────────────────────────────────────────────────── layers ┤ :y eltype: Float64 dims: draw, chain size: 100×2 ├─────────────────────────────────────────────────── metadata ┤ Dict{String, Any} with 1 entry: "created_at" => "2026-09-01T08:11:23.294" └─────────────────────────────────────────────────────────────┘
sample_stats
┌ 100×2 Dataset ┐ ├───────────────┴───────────────────────────────────────── dims ┐ ↓ draw Sampled{Int64} 1:100 ForwardOrdered Regular Points, → chain Sampled{Int64} 1:2 ForwardOrdered Regular Points ├─────────────────────────────────────────────────────── layers ┤ :logprior eltype: Float64 dims: draw, chain size: 100×2 :loglikelihood eltype: Float64 dims: draw, chain size: 100×2 :logjoint eltype: Float64 dims: draw, chain size: 100×2 ├───────────────────────────────────────────────────── metadata ┤ Dict{String, Any} with 1 entry: "created_at" => "2026-09-01T08:11:20.934" └───────────────────────────────────────────────────────────────┘
From here you can use the full functionality of ArviZ.jl, which includes various plotting and analysis tools: please see the ArviZ.jl documentation for more info.