Code Monkey home page Code Monkey logo

mcmcdebugging.jl's Introduction

MCMCDebugging.jl: debugging utilities for MCMC samplers

This package implements a few utilities for debugging MCMC samplers, which includes

  • Geweke test
    • See the references [1,2] or this blog for details
  • Central limit theorem test

See the notebook for an example.

Usage

The example notebook covers most of the usages. Some details on the model definition via DynamicPPL is explained below.

Defining test models via DynamicPPL.jl

MCMCDebugging.jl allows using DynamicPPL.jl to define test models. In the example notebook, the test model is defined as

@model function BetaBinomial=missing, x=missing)
    θ ~ Beta(2, 3)
    x ~ Binomial(3, θ)
    return θ, x
end

There are a few requirements from MCMCDebugging.jl to use the defined model.

  1. The model should take θ and x as inputs (in order) and optionally being missing.
  • So that the model can be used to generate the marginal sampler as e.g. BetaBinomial() and conditional sampler as e.g. BetaBinomial(θ)
  1. The model should return the parameter θ and the data x as a tuple.

With these two points, MCMCDebugging.jl can generate several functions used by lower-level APIs.

  1. rand_marginal(): drawing θ and x as a tuple
  2. rand_x_given(θ): drawing x conditioned on θ
  3. logjoint(θ, x): computing the log-joint probability of θ and x

1 and 2 are used to perform the Geweke test and 3 is used to make the Q-Q plot.

Lower-level APIs

Geweke test

Defining the Geweke test

cfg = GewekeTest(n_samples::Int)

where n_samples is the number of samples used for testing.

Performing the Geweke test

res = perform(cfg::GewekeTest, rand_marginal, rand_x_given, rand_θ_given; g=nothing, progress=true)

where

  • rand_marginal() draws θ and x as a tuple
  • rand_x_given(θ) draws x conditioned on θ
  • rand_θ_given(x) draws θ conditioned on x
  • g(θ, x) is the test function

Making the Q-Q plot

plot(res::GewekeTestResult, logjoint)

where

  • logjoint(θ, x) computes the log-joint probability of θ and x

In case models are defined by DynamicPPL.jl, you can use

plot(res::GewekeTestResult, model)

For example, plot(res, BetaBinomial()). Note we have to pass an instantiated model (i.e. BetaBinomial()) here, for now, to make Julia correctly dispatch the plot recipe.

References

[1] Geweke J. Getting it right: Joint distribution tests of posterior simulators. Journal of the American Statistical Association. 2004 Sep 1;99(467):799-804.

[2] Grosse RB, Duvenaud DK. Testing mcmc code. arXiv preprint arXiv:1412.5218. 2014 Dec 16.

mcmcdebugging.jl's People

Contributors

xukai92 avatar

Watchers

 avatar  avatar

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.