Code Monkey home page Code Monkey logo

mjhmc's Introduction

Markov Jump Hamiltonian Monte Carlo

Python implementation of Markov Jump HMC

Markov Jump HMC is described in the paper

A. Berger, M. Mudigonda, M. R. DeWeese and J. Sohl-Dickstein
A Markov Jump Process for More Efficient Hamiltonian Monte Carlo
arXiv preprint arXiv:1509.03808, 2015

Example Python Code

from mjhmc.samplers.markov_jump_hmc import MarkovJumpHMC
from mjhmc.misc.distributions import LambdaDistribution
import numpy as np

# Define the energy function and gradient
def E(X, sigma=1.):
    """ Energy function for isotropic Gaussian """
    return np.sum(X**2, axis=0).reshape((1,-1))/2./sigma**2

def dEdX(X, sigma=1.):
    """ Energy function gradient for isotropic Gaussian """
    return X/sigma**2

# Create a good initalization for the sampling particle locations -- 2 dimensions, 100 indepedent sampling particles
Xinit = np.random.randn(2,100)

# Initialize an anonymous distribution object
anonymous_gaussian = LambdaDistribution(energy_func=E, energy_grad_func=dEdX, init=Xinit, name='IsotropicGaussian')

# Initialize the sampler
mjhmc = MarkovJumpHMC(distribution=anonymous_gaussian)
# Perform 10 sampling steps for all 100 particles
# Returns an array of samples with shape (ndims, num_steps * num_particles), in this case (2, 1000)
X = mjhmc.sample(num_steps = 10)

Dependencies

Required

  • numpy
  • scipy

Optional

  • matplotlib
  • nosetests
  • seaborn (for making pretty plots)
  • spearmint (for hyperparameter optimization)
  • pandas (needed for some plots)

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.