Chains
The methods listed below are defined in src/chains.jl.
MCMCChains.Chains — MethodChains(c::Chains, section::Union{Symbol,String})
Chains(c::Chains, sections)Return a new chain with only a specific section or multiple sections pulled out.
Examples
julia> chn = Chains(rand(100, 2, 1), [:a, :b], Dict(:internals => [:a]));
julia> names(chn)
2-element Vector{Symbol}:
:a
:b
julia> chn2 = Chains(chn, :internals);
julia> names(chn2)
1-element Vector{Symbol}:
:aBase.get — MethodBase.get(c::Chains, v::Symbol; flatten=false)
Base.get(c::Chains, vs::Vector{Symbol}; flatten=false)Return a NamedTuple with v as the key, and matching paramter names as the values.
Passing flatten=true will return a NamedTuple with keys ungrouped.
Example
julia> chn = Chains([1:2 3:4]);
julia> get(chn, :param_1)
(param_1 = [1; 2],)
julia> get(chn, [:param_2])
(param_2 = [3; 4],)
julia> get(chn, :param_1; flatten=true)
(param_1 = 1,)Base.get — Methodget(c::Chains; section::Union{Vector{Symbol}, Symbol; flatten=false}Return all parameters in a given section(s) as a NamedTuple.
Passing flatten=true will return a NamedTuple with keys ungrouped.
Example
julia> chn = Chains([1:2 3:4], [:a, :b], Dict(:internals => [:a]));
julia> get(chn; section=:parameters)
(b = [3; 4],)
julia> get(chn; section=[:internals])
(a = [1; 2],)Base.names — Methodnames(chains::Chains, sections)Return the parameter names of the sections in the chains.
Base.names — Methodnames(chains::Chains, section::Symbol)Return the parameter names of a section in the chains.
Base.names — Methodnames(chains::Chains)Return the parameter names in the chains.
Base.range — Methodrange(chains::Chains)Return the range of iteration indices of the chains.
Base.sort — Methodsort(c::Chains[; lt=NaturalSort.natural])Return a new column-sorted version of c.
By default the columns are sorted in natural sort order.
MCMCChains.chains — Methodchains(c::Chains)Return the names or symbols of each chain in a Chains object.
MCMCChains.get_params — Methodget_params(c::Chains; flatten=false)Return all parameters packaged as a NamedTuple. Variables with a bracket in their name (as in "P[1]") will be grouped into the returned value as P.
Passing flatten=true will return a NamedTuple with keys ungrouped.
Example
julia> chn = Chains(1:5);
julia> x = get_params(chn);
julia> x.param_1
2-dimensional AxisArray{Int64,2,...} with axes:
:iter, 1:1:5
:chain, 1:1
And data, a 5×1 Matrix{Int64}:
1
2
3
4
5MCMCChains.get_sections — Functionget_sections(chains[, sections])Return multiple Chains objects, each containing only a single section.
MCMCChains.group — Methodgroup(chains::Chains, name::Union{String,Symbol})Return a subset of the chain chain with all parameters in the group Symbol(name).
MCMCChains.header — Methodheader(c::Chains; section=missing)Return a string containing summary information for a Chains object. If the section keyword is used, this function prints only the relevant section header.
Example
# Printing the whole header.
header(chn)
# Print only one section's header.
header(chn, section = :parameter)MCMCChains.namesingroup — Methodnamesingroup(chains::Chains, sym::Union{String,Symbol})Return the names of all parameters in a chain that belong to the group sym.
This is based on the MCMCChains convention that parameters with names of the form :sym[index] belong to one group of parameters called :sym.
If the chain contains a parameter of name :sym it will be returned as well.
Example
julia> chn = Chains(rand(100, 2, 2), ["A[1]", "A[2]"]);
julia> namesingroup(chn, :A)
2-element Vector{Symbol}:
Symbol("A[1]")
Symbol("A[2]")MCMCChains.replacenames — Methodreplacenames(chains::Chains, dict::AbstractDict)Replace parameter names by creating a new Chains object that shares the same underlying data.
Examples
julia> chn = Chains(rand(100, 2, 2), ["one", "two"]);
julia> chn2 = replacenames(chn, "one" => "A");
julia> names(chn2)
2-element Vector{Symbol}:
:A
:two
julia> chn3 = replacenames(chn2, Dict("A" => "one", "two" => "B"));
julia> names(chn3)
2-element Vector{Symbol}:
:one
:BMCMCChains.resetrange — Methodresetrange(chains::Chains)Generate a new chain from chains with iterations indexed by 1:n, where n is the number of samples per chain.
The new chain and chains share the same data in memory.
MCMCChains.sections — Methodsections(c::Chains)Retrieve a list of the sections in a chain.
MCMCChains.set_section — Methodset_section(chains::Chains, namemap)Create a new Chains object from chains with the provided namemap mapping of parameter names.
Both chains share the same underlying data. Any parameters in the chain that are unassigned will be placed into the :parameters section.
MCMCChains.setinfo — Methodsetinfo(c::Chains, n::NamedTuple)Return a new Chains object with a NamedTuple type n placed in the info field.
Example
new_chn = setinfo(chn, NamedTuple{(:a, :b)}((1, 2)))MCMCChains.setrange — Methodsetrange(chains::Chains, range)Generate a new chain from chains with iterations indexed by range.
The new chain and chains share the same data in memory.