Stan
FlexiChains has a function to read in chains stored in Stan CSV format:
FlexiChains.from_stan_csv Function
FlexiChains.from_stan_csv(
base_path::AbstractString, num_chains::Integer
)::FlexiChain{Symbol}Reads the Stan CSV files from {base_path}_1.csv through to {base_path}_{num_chains}.csv. This is a convenience method that recognises the fact that CmdStan saves its outputs in this format.
Note
You do not need to provide the underscore before the chain number in the filename! That is, if your files are example_1.csv etc., then base_path should just be "example".
FlexiChains.from_stan_csv(
csv_paths::AbstractVector{<:AbstractString}
)::FlexiChain{Symbol}Parse a set of Stan CSV files at the given paths.
These files must correspond to a set of compatible chains, i.e., their parameter names, lengths (i.e., number of iterations), and other data should be consistent. This will be the case if they were all drawn from the same call to Stan's sampling. However, note that FlexiChains does only a rudimentary set of checks to ensure consistency: the user should be responsible for ensuring that the CSVs read in are valid.
Columns that end in double-underscores (__) are treated as Extras (the underscores will be stripped), and all other columns as Parameters.
This of course assumes that you already have the CSV files on disk somewhere, e.g. if you have run Stan externally.
If you are using StanSample.jl you can also read data directly from a SampleModel once you have sampled with it.
Note
This code block is not run, as running it would necessitate setting up CmdStan on GitHub runners.
using StanSample, FlexiChains
sm = SampleModel(args...)
# Note: this mutates `sm` -- StanSample has a rather unconventional interface
stan_sample(sm; data)
# The key type has to be `Symbol`.
chn = FlexiChain{Symbol}(sm)If you are using BridgeStan.jl and/or StanLogDensityProblems.jl plus a native Julia sampler, you should check whether there is an integration for the sampler in question. For example if you use AdvancedHMC.jl then you can pass the chain_type=FlexiChain{Symbol} keyword argument (see above).
(If the sampler in question does not have an integration with FlexiChains, please feel free to open an issue!)