Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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)

Slide 5

Slide 5 text

emcee danfm.ca/emcee Metropolis-Hastings

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

emcee danfm.ca/emcee Metropolis-Hastings x y

Slide 9

Slide 9 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 10

Slide 10 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 11

Slide 11 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 12

Slide 12 text

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 ) ◆ ?

Slide 13

Slide 13 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 14

Slide 14 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 15

Slide 15 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 16

Slide 16 text

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) ◆ ?

Slide 17

Slide 17 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 18

Slide 18 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 19

Slide 19 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 20

Slide 20 text

emcee danfm.ca/emcee Metropolis-Hastings x y (in an ideal world)

Slide 21

Slide 21 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y

Slide 22

Slide 22 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y

Slide 23

Slide 23 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y

Slide 24

Slide 24 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y

Slide 25

Slide 25 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y

Slide 26

Slide 26 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y SMALL ACCEPTANCE FRACTION the problem

Slide 27

Slide 27 text

emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) x y LARGE ACCEPTANCE FRACTION the problem

Slide 28

Slide 28 text

x y emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world)

Slide 29

Slide 29 text

x y emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world)

Slide 30

Slide 30 text

x y emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world)

Slide 31

Slide 31 text

x y emcee danfm.ca/emcee Metropolis-Hastings (in the REAL world) positive-definite symmetric Proposal D (D-1) parameters

Slide 32

Slide 32 text

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!

Slide 33

Slide 33 text

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)

Slide 34

Slide 34 text

emcee danfm.ca/emcee Why does all this matter?

Slide 35

Slide 35 text

emcee danfm.ca/emcee How do you calculate the optimal proposal?

Slide 36

Slide 36 text

emcee danfm.ca/emcee Temperature

Slide 37

Slide 37 text

emcee danfm.ca/emcee Temperature

Slide 38

Slide 38 text

emcee danfm.ca/emcee Temperature

Slide 39

Slide 39 text

emcee danfm.ca/emcee Temperature

Slide 40

Slide 40 text

emcee danfm.ca/emcee Temperature

Slide 41

Slide 41 text

emcee danfm.ca/emcee Temperature

Slide 42

Slide 42 text

emcee danfm.ca/emcee Temperature

Slide 43

Slide 43 text

emcee danfm.ca/emcee Temperature

Slide 44

Slide 44 text

emcee danfm.ca/emcee Temperature

Slide 45

Slide 45 text

emcee danfm.ca/emcee Temperature time

Slide 46

Slide 46 text

emcee danfm.ca/emcee Temperature that should be spent interpreting your results writing papers finding bugs in your code time

Slide 47

Slide 47 text

emcee danfm.ca/emcee Luckily I have a solution!

Slide 48

Slide 48 text

emcee danfm.ca/emcee Luckily I have a solution! HINT: it's up here...

Slide 49

Slide 49 text

emcee danfm.ca/emcee bit.ly/mcmc-gw10 "Ensemble samplers with affine invariance" Jonathan Goodman Jonathan Weare Mustaches courtesy: mustachify.me

Slide 50

Slide 50 text

emcee danfm.ca/emcee bit.ly/mcmc-gw10 "Ensemble samplers with affine invariance" Jonathan Goodman Jonathan Weare Mustaches courtesy: mustachify.me

Slide 51

Slide 51 text

emcee danfm.ca/emcee bit.ly/mcmc-gw10 "Ensemble samplers with affine invariance" Jonathan Goodman Jonathan Weare Mustaches courtesy: mustachify.me

Slide 52

Slide 52 text

emcee danfm.ca/emcee affine invariance

Slide 53

Slide 53 text

emcee danfm.ca/emcee affine invariance y A x + b Affine Transformation

Slide 54

Slide 54 text

emcee danfm.ca/emcee affine invariance The sampler performs Equally well on X and Y y A x + b Affine Transformation

Slide 55

Slide 55 text

emcee danfm.ca/emcee Easy to sample Hard to sample

Slide 56

Slide 56 text

emcee danfm.ca/emcee Easy to sample Hard to sample y A x + b Affine Transformation

Slide 57

Slide 57 text

emcee danfm.ca/emcee Easy to sample Hard to sample y A x + b Affine Transformation easy!

Slide 58

Slide 58 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 59

Slide 59 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 60

Slide 60 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 64

Slide 64 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 65

Slide 65 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 66

Slide 66 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 67

Slide 67 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 68

Slide 68 text

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 ) ◆

Slide 69

Slide 69 text

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 ) ◆

Slide 70

Slide 70 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 71

Slide 71 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 72

Slide 72 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 73

Slide 73 text

emcee danfm.ca/emcee Ensemble Samplers (in the REAL world) x y with affine invariance

Slide 74

Slide 74 text

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!

Slide 75

Slide 75 text

emcee danfm.ca/emcee +

Slide 76

Slide 76 text

emcee danfm.ca/emcee it's hammer time! emceethe MCMC Hammer introducing arxiv.org/abs/1202.3665

Slide 77

Slide 77 text

emcee danfm.ca/emcee pip install emcee get it:

Slide 78

Slide 78 text

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:

Slide 79

Slide 79 text

emcee danfm.ca/emcee DOES IT WORK? obviously it does.

Slide 80

Slide 80 text

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 ◆

Slide 81

Slide 81 text

emcee danfm.ca/emcee github.com/dfm/acor Autocorrelation Function the (covariance)

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

emcee danfm.ca/emcee Metropolis-Hastings Boom!

Slide 86

Slide 86 text

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 ◆

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

emcee isn't always The Right Choice™ emcee danfm.ca/emcee Mustache courtesy: mustachify.me Brendon Brewer Remember:

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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?

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

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 ... ... ...

Slide 94

Slide 94 text

emceethe MCMC Hammer arxiv.org/abs/1202.3665 danfm.ca/emcee github.com/dfm/emcee paper documentation issues/contributions Check it out: Dustin Lang (Princeton) David W. Hogg (NYU) Jonathan Goodman (NYU)