Skip to content

Accessing samples? #365

Open
Open
@rkube

Description

@rkube

Hi,
Going through the documentation I'm wondering how to access the samples from HMC. In the
first example the samples are just a vector:

julia> samples, stats = sample(hamiltonian, kernel, initial_θ, n_samples, adaptor, n_adapts; progress=true)
julia> samples
100000-element Vector{Vector{Float64}}:

In the AbstractMCMC example the samples are a long vector of some complicated type and I had to dig around to get the actual samples:

julia> samples = AbstractMCMC.sample(
      model,
      sampler,
      n_adapts + n_samples;
      nadapts = n_adapts,
      initial_params = initial_θ,
  )
julia> samples
julia> samples
3000-element Vector{AdvancedHMC.Transition{AdvancedHMC.PhasePoint{Vector{Float64}, AdvancedHMC.DualValue{Float64, Vector{Float64}}}, @NamedTuple{n_steps::Int64, is_accept::Bool, acceptance_rate::Float64, log_density::Float64, hamiltonian_energy::Float64, hamiltonian_energy_error::Float64, max_hamiltonian_energy_error::Float64, tree_depth::Int64, numerical_error::Bool, step_size::Float64, nom_step_size::Float64, is_adapt::Bool}}}:
[...]
julia>reduce(vcat, [s.z.θ for s ∈ samples])
3000-element Vector{Float64}:
 -0.21417892820474493
[...]

Am I missing something or is this the correct way of getting to the samples?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions