Skip to content

Commit

Permalink
Initial AbstractMCMC.step should not sample (#366)
Browse files Browse the repository at this point in the history
* initial step should just construct the initial transitio and step; it
should not perform any sampling of the parameters.

* bump patch version

* Update src/abstractmcmc.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fixed issue in callback for first iteration

* attempt at fixing callback issues

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hong Ge <[email protected]>
  • Loading branch information
3 people authored Jan 13, 2025
1 parent 646202c commit 32d0446
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/abstractmcmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ function AbstractMCMC.step(

# Compute next transition and state.
state = HMCState(0, t, metric, κ, adaptor)
# Take actual first step.
return AbstractMCMC.step(rng, model, spl, state; kwargs...)
# Return the initial transition and state.
return Transition(t.z, merge(stat(t), (is_adapt = false,))), state
end

function AbstractMCMC.step(
Expand Down Expand Up @@ -260,10 +260,13 @@ function (cb::HMCProgressCallback)(
κ = state.κ
tstat = t.stat
isadapted = tstat.is_adapt
if isadapted
cb.num_divergent_transitions_during_adaption[] += tstat.numerical_error
else
cb.num_divergent_transitions[] += tstat.numerical_error
# The initial transition will not much information beyond the `is_adapt` field.
if haskey(tstat, :numerical_error)
if isadapted
cb.num_divergent_transitions_during_adaption[] += tstat.numerical_error
else
cb.num_divergent_transitions[] += tstat.numerical_error
end
end

# Update progress meter
Expand Down

0 comments on commit 32d0446

Please sign in to comment.