Coder Social home page Coder Social logo

Comments (1)

torfjelde avatar torfjelde commented on June 20, 2024

This is possible using the AbstractMCMC interface with a different callback keyword argument.

To do it propertly, one should just implement a callback similar to

"""
HMCProgressCallback
A callback to be used with AbstractMCMC.jl's interface, replicating the
logging behavior of the non-AbstractMCMC [`sample`](@ref).
# Fields
$(FIELDS)
"""
struct HMCProgressCallback{P}
"`Progress` meter from ProgressMeters.jl."
pm::P
"Specifies whether or not to use display a progress bar."
progress::Bool
"If `progress` is not specified and this is `true` some information will be logged upon completion of adaptation."
verbose::Bool
"Number of divergent transitions fo far."
num_divergent_transitions::Ref{Int}
num_divergent_transitions_during_adaption::Ref{Int}
end

function (cb::HMCProgressCallback)(rng, model, spl, t, state, i; nadapts = 0, kwargs...)

which only shows the progressbar without all the extra information.

Buuut because in the AbstractMCMC-interface impl we only use the HMCProgressCallback if no callback is manually specified, e.g.

if callback === nothing
callback = HMCProgressCallback(N, progress = progress, verbose = verbose)
progress = false # don't use AMCMC's progress-funtionality
end

we can just provide a callback that does nothing and set progress=true, which then hits the default progress meter in AbstractMCMC.sample, which is exactly what you want.

In short, try the following:

# HACK: a callback that does nothing to avoid hitting `HMCProgressCallback`
callback(rng, model, sampler, transition, state, i) = nothing

samples = AbstractMCMC.sample(
    model,
    sampler,
    n_adapts + n_samples;
    nadapts = n_adapts,
    initial_params = initial_θ,
    callback=callback,
    progress=true,  # will use default progress meter i `AbstractMCMC`
)

from advancedhmc.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.