Upgrade to Pro — share decks privately, control downloads, hide ads and more …

emcee

 emcee

Some intro slides for Python lunch at MPIA.

Dan Foreman-Mackey

July 20, 2012
Tweet

More Decks by Dan Foreman-Mackey

Other Decks in Science

Transcript

  1. emcee danfm.ca/emcee p(⇥) I have a function I can Evaluate

    it I can't Calculate the functional form
  2. emcee danfm.ca/emcee p(⇥) I have a function I can Evaluate

    it I can't Calculate the functional form Markov chain Monte Carlo (MCMC)
  3. emcee danfm.ca/emcee min ✓ 1 , p ( x 0)

    p ( x ) Q ( x ; x 0) Q ( x 0; x ) ◆ Metropolis-Hastings
  4. emcee danfm.ca/emcee min ✓ 1 , p ( x 0)

    p ( x ) Q ( x ; x 0) Q ( x 0; x ) ◆ Metropolis-Hastings Proposal D (D-1) parameters
  5. emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world) min

    ✓ 1, p (x 0 ) p (x ) Q (x ;x 0 ) Q (x 0 ;x ) ◆ ?
  6. emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world) min

    ✓ 1 , p( x 0 ) p( x) Q( x; x 0 ) Q( x 0; x) ◆ ?
  7. x y emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) positive-definite

    symmetric Proposal D (D-1) parameters This is the Dimension of your parameter space!
  8. emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) Scientific Awesomeness how

    hard is MCMC Metropolis Hastings how things Should be (~number of parameters)
  9. emcee danfm.ca/emcee Easy to sample Hard to sample y A

    x + b Affine Transformation easy!
  10. emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y

    with affine invariance this is a walker
  11. emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y

    with affine invariance this is a walker
  12. emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y

    with affine invariance min ✓ 1,Z D 1 p (x 0 ) p (x ) ◆
  13. emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y

    with affine invariance min ✓ 1,Z D 1 p (x 0 ) p (x ) ◆
  14. emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y

    with affine invariance Aside: this looks nice and parallel, eh? * * not quite as trivial as you might hope—but possible!
  15. emcee danfm.ca/emcee import numpy as np import emcee def lnprob(x):

    return -0.5 * np.sum(x ** 2) ndim, nwalkers = 10, 100 p0 = [np.random.rand(ndim) for i in range(nwalkers)] sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob) sampler.run_mcmc(p0, 1000) use it:
  16. emcee danfm.ca/emcee 1.0 0.5 0.0 0.5 1.0 1.0 0.5 0.0

    0.5 1.0 exp ✓ (x1 x2) 2 2 ✏ (x1 + x2) 2 2 ◆
  17. emcee danfm.ca/emcee 1.0 0.5 0.0 0.5 1.0 1.0 0.5 0.0

    0.5 1.0 exp ✓ (x1 x2) 2 2 ✏ (x1 + x2) 2 2 ◆ Metropolis-Hastings Emcee Autocorrelation Function the
  18. emcee danfm.ca/emcee 1.0 0.5 0.0 0.5 1.0 1.0 0.5 0.0

    0.5 1.0 exp ✓ (x1 x2) 2 2 ✏ (x1 + x2) 2 2 ◆ Metropolis-Hastings Emcee Autocorrelation Function the
  19. emcee danfm.ca/emcee 1.0 0.5 0.0 0.5 1.0 1.0 0.5 0.0

    0.5 1.0 exp ✓ (x1 x2) 2 2 ✏ (x1 + x2) 2 2 ◆ Metropolis-Hastings Emcee Autocorrelation Function the
  20. emcee danfm.ca/emcee 4 2 0 2 4 6 0 5

    10 15 20 25 30 exp ✓ 100 (x2 x 2 1) 2 + (1 x1) 2 20 ◆
  21. 4 2 0 2 4 6 0 5 10 15

    20 25 30 exp ✓ 100 (x2 x 2 1) 2 + (1 x1) 2 20 ◆ emcee danfm.ca/emcee Metropolis-Hastings Emcee Autocorrelation Function the
  22. emcee danfm.ca/emcee Mustache courtesy: mustachify.me continuous parameters in a vector

    space emcee needs highly multimodal problems and it is not good at
  23. emcee danfm.ca/emcee Mustache courtesy: mustachify.me continuous parameters in a vector

    space emcee needs highly multimodal problems and it is not good at what is?
  24. emcee danfm.ca/emcee Mustache courtesy: mustachify.me continuous parameters in a vector

    space emcee needs highly multimodal problems and it is not good at what is? maybe Dnest github.com/eggplantbren/DNest3
  25. emcee danfm.ca/emcee Mustache courtesy: mustachify.me continuous parameters in a vector

    space emcee needs highly multimodal problems and it is not good at what is? maybe Dnest github.com/eggplantbren/DNest3 for example
  26. emcee danfm.ca/emcee it's still been pretty useful... Lang & Hogg

    (2011) Bovy et al. (2011) Dorman et al. (2012) Foreman-Mackey & Widrow (in prep) Mustaches courtesy: mustachify.me ... ... ...