Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing samples? #365

Open
rkube opened this issue Mar 6, 2024 · 0 comments
Open

Accessing samples? #365

rkube opened this issue Mar 6, 2024 · 0 comments

Comments

@rkube
Copy link

rkube commented Mar 6, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant