• No results found

Big Data need Big Model 1/44

N/A
N/A
Protected

Academic year: 2021

Share "Big Data need Big Model 1/44"

Copied!
107
0
0

Loading.... (view fulltext now)

Full text

(1)

Big Data need Big Model

(2)

2/44

Stan: A platform for Bayesian inference

Andrew Gelman, Bob Carpenter, Matt Hoffman, Daniel Lee, Ben Goodrich, Michael Betancourt, Marcus Brubaker,

Jiqiang Guo, Peter Li, Allen Riddell,. . .

Department of Statistics, Columbia University, New York (and other places)

10 Nov 2014

(3)

3/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(4)

4/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(5)

5/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(6)

6/44

Ordered probit

data { int<lower=2> K; int<lower=0> N; int<lower=1> D; int<lower=1,upper=K> y[N]; row_vector[D] x[N]; } parameters { vector[D] beta; ordered[K-1] c; } model { vector[K] theta; for (n in 1:N) { real eta; eta <- x[n] * beta; theta[1] <- 1 - Phi(eta - c[1]); for (k in 2:(K-1))

theta[k] <- Phi(eta - c[k-1]) - Phi(eta - c[k]); theta[K] <- Phi(eta - c[K-1]);

y[n] ~ categorical(theta); } }

(7)

7/44

Measurement error model

data { ...

real x_meas[N]; // measurement of x real<lower=0> tau; // measurement noise }

parameters {

real x[N]; // unknown true value real mu_x; // prior location real sigma_x; // prior scale ...

} model {

x ~ normal(mu_x, sigma_x); // prior

x_meas ~ normal(x, tau); // measurement model y ~ normal(alpha + beta * x, sigma);

... }

(8)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(9)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(10)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(11)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(12)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(13)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(14)

8/44

Stan overview

I Fit open-ended Bayesian models

I Specify log posterior density in C++

I Code a distribution once, then use it everywhere

I Hamiltonian No-U-Turn sampler

I Autodiff

I Runs from R, Python, Matlab, Julia; postprocessing

(15)

9/44

People

I Stan core (15) I Research collaborators (30) I Developers (100) I User community (1000) I Users (10000)

(16)

9/44

People

I Stan core (15) I Research collaborators (30) I Developers (100) I User community (1000) I Users (10000)

(17)

9/44

People

I Stan core (15) I Research collaborators (30) I Developers (100) I User community (1000) I Users (10000)

(18)

9/44

People

I Stan core (15) I Research collaborators (30) I Developers (100) I User community (1000) I Users (10000)

(19)

9/44

People

I Stan core (15) I Research collaborators (30) I Developers (100) I User community (1000) I Users (10000)

(20)

10/44

Funding

I National Science Foundation

I Institute for Education Sciences

I Department of Energy

I Novartis

I YouGov

(21)

11/44

Roles of Stan

I Bayesian inference for unsophisticated users (alternative to

Stata, Bugs, etc.)

I Bayesian inference for sophisticated users (alternative to

programming it yourself)

I Fast and scalable gradient computation

I Environment for developing new algorithms

(22)

11/44

Roles of Stan

I Bayesian inference for unsophisticated users (alternative to

Stata, Bugs, etc.)

I Bayesian inference for sophisticated users (alternative to

programming it yourself)

I Fast and scalable gradient computation

I Environment for developing new algorithms

(23)

11/44

Roles of Stan

I Bayesian inference for unsophisticated users (alternative to

Stata, Bugs, etc.)

I Bayesian inference for sophisticated users (alternative to

programming it yourself)

I Fast and scalable gradient computation

I Environment for developing new algorithms

(24)

11/44

Roles of Stan

I Bayesian inference for unsophisticated users (alternative to

Stata, Bugs, etc.)

I Bayesian inference for sophisticated users (alternative to

programming it yourself)

I Fast and scalable gradient computation

I Environment for developing new algorithms

(25)

11/44

Roles of Stan

I Bayesian inference for unsophisticated users (alternative to

Stata, Bugs, etc.)

I Bayesian inference for sophisticated users (alternative to

programming it yourself)

I Fast and scalable gradient computation

I Environment for developing new algorithms

(26)

12/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(27)

13/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(28)

14/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(29)

15/44

“This week, the New York Times and CBS News published a story using, in part, information from a non-probability, opt-in survey sparking concern among many in the polling community. In general, these methods have little grounding in theory and the results can vary widely based on the particular method used.”

— Michael Link,

President, American Association for Public Opinion Research

(30)

16/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(31)

17/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(32)

18/44

Xbox estimates, adjusting for demographics

(33)

19/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(34)

20/44

I Karl Rove, Wall Street Journal, 7 Oct: “Mr. Romney’s bounce

is significant.”

I Nate Silver, New York Times, 6 Oct: “Mr. Romney has not

only improved his own standing but also taken voters away from Mr. Obama’s column.”

(35)

21/44

Xbox estimates, adjusting for demographics and partisanship

(36)

22/44

Jimmy Carter Republicans and George W. Bush Democrats

(37)

23/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(38)

24/44 Gelman Carpenter Hoffman Lee Goodrich Betancourt . . . Stan: A platform for Bayesian inference

(39)

25/44

Toxicology

(40)

26/44

Earth science

(41)

27/44

Lots of other applications

Astronomy, ecology, linguistics, epidemiology, soil science, . . .

(42)

28/44

Steps of Bayesian data analysis

I Model building

I Inference

I Model checking

I Model understanding and improvement

(43)

28/44

Steps of Bayesian data analysis

I Model building

I Inference

I Model checking

I Model understanding and improvement

(44)

28/44

Steps of Bayesian data analysis

I Model building

I Inference

I Model checking

I Model understanding and improvement

(45)

28/44

Steps of Bayesian data analysis

I Model building

I Inference

I Model checking

I Model understanding and improvement

(46)

28/44

Steps of Bayesian data analysis

I Model building

I Inference

I Model checking

I Model understanding and improvement

(47)

29/44

Background on Bayesian computation

I Point estimates and standard errors

I Hierarchical models

I Posterior simulation

I Markov chain Monte Carlo (Gibbs sampler and Metropolis

algorithm)

I Hamiltonian Monte Carlo

(48)

29/44

Background on Bayesian computation

I Point estimates and standard errors

I Hierarchical models

I Posterior simulation

I Markov chain Monte Carlo (Gibbs sampler and Metropolis

algorithm)

I Hamiltonian Monte Carlo

(49)

29/44

Background on Bayesian computation

I Point estimates and standard errors

I Hierarchical models

I Posterior simulation

I Markov chain Monte Carlo (Gibbs sampler and Metropolis

algorithm)

I Hamiltonian Monte Carlo

(50)

29/44

Background on Bayesian computation

I Point estimates and standard errors

I Hierarchical models

I Posterior simulation

I Markov chain Monte Carlo (Gibbs sampler and Metropolis

algorithm)

I Hamiltonian Monte Carlo

(51)

29/44

Background on Bayesian computation

I Point estimates and standard errors

I Hierarchical models

I Posterior simulation

I Markov chain Monte Carlo (Gibbs sampler and Metropolis

algorithm)

I Hamiltonian Monte Carlo

(52)

29/44

Background on Bayesian computation

I Point estimates and standard errors

I Hierarchical models

I Posterior simulation

I Markov chain Monte Carlo (Gibbs sampler and Metropolis

algorithm)

I Hamiltonian Monte Carlo

(53)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(54)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(55)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(56)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(57)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(58)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(59)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(60)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(61)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(62)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(63)

30/44

Solving problems

I Problem: Gibbs too slow, Metropolis too problem-specific

I Solution: Hamiltonian Monte Carlo

I Problem: Interpreters too slow, won’t scale

I Solution: Compilation

I Problem: Need gradients of log posterior for HMC

I Solution: Reverse-mode algorithmic differentation

I Problem: Existing algo-diff slow, limited, unextensible

I Solution: Our own algo-diff

I Problem: Algo-diff requires fully templated functions

I Solution: Our own density library, Eigen linear algebra

(64)

31/44

Radford Neal (2011) on Hamiltonian Monte Carlo

“One practical impediment to the use of Hamiltonian Monte Carlo is the need to select suitable values for the leapfrog stepsize,, and the number of leapfrog stepsL. . . Tuning HMC will usually require preliminary runs with trial values forandL. . . Unfortunately, preliminary runs can be misleading . . . ”

(65)

32/44

The No U-Turn Sampler

I Created by Matt Hoffman

I Run the HMC steps until they start to turn around

(bend with an angle >180◦)

I Computationally efficient

I Requires no tuning of #steps

I Complications to preserve detailed balance

(66)

33/44

NUTS Example Trajectory

Hoffman and Gelman

−0.1 0 0.1 0.2 0.3 0.4 0.5 −0.1 0 0.1 0.2 0.3 0.4

Figure 2: Example of a trajectory generated during one iteration of NUTS. The blue ellipse is a contour of the target distribution, the black open circles are the positionsθ traced out by the leapfrog integrator and associated with elements of the set of visited statesB, the black solid circle is the starting position, the red solid circles are positions associated with states that must be excluded from the setCof possible next samples because their joint probability is below the slice variableu, and the positions with a red “x” through them correspond to states that must be excluded fromCto satisfy detailed balance. The blue arrow is the vector from the positions associated with the leftmost to the rightmost leaf nodes in the rightmost height-3 subtree, and the magenta arrow is the (normalized) momentum vector at the final state in the trajectory. The doubling process stops here, since the blue and magenta arrows make an angle of more than 90 degrees. The crossed-out nodes with a red “x” are in the right half-tree, and must be ignored when choosing the next sample.

being more complicated, the analogous algorithm that eliminates the slice variable seems empirically to be slightly less efficient than the algorithm presented in this paper.

6

I Blue ellipse is contour of target distribution

I Initial position at black solid circle

I Arrows indicate a U-turn in momentum

(67)

33/44

NUTS Example Trajectory

Hoffman and Gelman

−0.1 0 0.1 0.2 0.3 0.4 0.5 −0.1 0 0.1 0.2 0.3 0.4

Figure 2: Example of a trajectory generated during one iteration of NUTS. The blue ellipse is a contour of the target distribution, the black open circles are the positionsθ traced out by the leapfrog integrator and associated with elements of the set of visited statesB, the black solid circle is the starting position, the red solid circles are positions associated with states that must be excluded from the setCof possible next samples because their joint probability is below the slice variableu, and the positions with a red “x” through them correspond to states that must be excluded fromCto satisfy detailed balance. The blue arrow is the vector from the positions associated with the leftmost to the rightmost leaf nodes in the rightmost height-3 subtree, and the magenta arrow is the (normalized) momentum vector at the final state in the trajectory. The doubling process stops here, since the blue and magenta arrows make an angle of more than 90 degrees. The crossed-out nodes with a red “x” are in the right half-tree, and must be ignored when choosing the next sample.

being more complicated, the analogous algorithm that eliminates the slice variable seems empirically to be slightly less efficient than the algorithm presented in this paper.

6

I Blue ellipse is contour of target distribution

I Initial position at black solid circle

I Arrows indicate a U-turn in momentum

(68)

33/44

NUTS Example Trajectory

Hoffman and Gelman

−0.1 0 0.1 0.2 0.3 0.4 0.5 −0.1 0 0.1 0.2 0.3 0.4

Figure 2: Example of a trajectory generated during one iteration of NUTS. The blue ellipse is a contour of the target distribution, the black open circles are the positionsθ traced out by the leapfrog integrator and associated with elements of the set of visited statesB, the black solid circle is the starting position, the red solid circles are positions associated with states that must be excluded from the setCof possible next samples because their joint probability is below the slice variableu, and the positions with a red “x” through them correspond to states that must be excluded fromCto satisfy detailed balance. The blue arrow is the vector from the positions associated with the leftmost to the rightmost leaf nodes in the rightmost height-3 subtree, and the magenta arrow is the (normalized) momentum vector at the final state in the trajectory. The doubling process stops here, since the blue and magenta arrows make an angle of more than 90 degrees. The crossed-out nodes with a red “x” are in the right half-tree, and must be ignored when choosing the next sample.

being more complicated, the analogous algorithm that eliminates the slice variable seems empirically to be slightly less efficient than the algorithm presented in this paper.

6

I Blue ellipse is contour of target distribution

I Initial position at black solid circle

I Arrows indicate a U-turn in momentum

(69)

33/44

NUTS Example Trajectory

Hoffman and Gelman

−0.1 0 0.1 0.2 0.3 0.4 0.5 −0.1 0 0.1 0.2 0.3 0.4

Figure 2: Example of a trajectory generated during one iteration of NUTS. The blue ellipse is a contour of the target distribution, the black open circles are the positionsθ traced out by the leapfrog integrator and associated with elements of the set of visited statesB, the black solid circle is the starting position, the red solid circles are positions associated with states that must be excluded from the setCof possible next samples because their joint probability is below the slice variableu, and the positions with a red “x” through them correspond to states that must be excluded fromCto satisfy detailed balance. The blue arrow is the vector from the positions associated with the leftmost to the rightmost leaf nodes in the rightmost height-3 subtree, and the magenta arrow is the (normalized) momentum vector at the final state in the trajectory. The doubling process stops here, since the blue and magenta arrows make an angle of more than 90 degrees. The crossed-out nodes with a red “x” are in the right half-tree, and must be ignored when choosing the next sample.

being more complicated, the analogous algorithm that eliminates the slice variable seems empirically to be slightly less efficient than the algorithm presented in this paper.

6

I Blue ellipse is contour of target distribution

I Initial position at black solid circle

I Arrows indicate a U-turn in momentum

(70)

34/44

NUTS vs. Gibbs and Metropolis

The No-U-Turn Sampler

Figure 7: Samples generated by random-walk Metropolis, Gibbs sampling, and NUTS. The plots compare 1,000 independent draws from a highly correlated 250-dimensional distribu-tion (right) with 1,000,000 samples (thinned to 1,000 samples for display) generated by random-walk Metropolis (left), 1,000,000 samples (thinned to 1,000 samples for display) generated by Gibbs sampling (second from left), and 1,000 samples generated by NUTS (second from right). Only the first two dimensions are shown here.

4.4 Comparing the Efficiency of HMC and NUTS

Figure 6 compares the efficiency of HMC (with various simulation lengthsλ ≈ �L) and NUTS (which chooses simulation lengths automatically). The x-axis in each plot is the targetδused by the dual averaging algorithm from section 3.2 to automatically tune the step size�. The y-axis is the effective sample size (ESS) generated by each sampler, normalized by the number of gradient evaluations used in generating the samples. HMC’s best performance seems to occur aroundδ= 0.65, suggesting that this is indeed a reasonable default value for a variety of problems. NUTS’s best performance seems to occur aroundδ = 0.6, but does not seem to depend strongly onδwithin the range δ∈[0.45,0.65]. δ= 0.6 therefore seems like a reasonable default value for NUTS.

On the two logistic regression problems NUTS is able to produce effectively indepen-dent samples about as efficiently as HMC can. On the multivariate normal and stochastic volatility problems, NUTS withδ= 0.6 outperforms HMC’s best ESS by about a factor of three.

As expected, HMC’s performance degrades if an inappropriate simulation length is cho-sen. Across the four target distributions we tested, the best simulation lengthsλfor HMC varied by about a factor of 100, with the longest optimalλbeing 17.62 (for the multivari-ate normal) and the shortest optimalλbeing 0.17 (for the simple logistic regression). In practice, finding a good simulation length for HMC will usually require some number of preliminary runs. The results in Figure 6 suggest that NUTS can generate samples at least as efficiently as HMC, even discounting the cost of any preliminary runs needed to tune HMC’s simulation length.

25

I Two dimensions of highly correlated 250-dim distribution

I 1M samples from Metropolis, 1M from Gibbs (thin to 1K)

I 1K samples from NUTS, 1K independent draws

(71)

34/44

NUTS vs. Gibbs and Metropolis

The No-U-Turn Sampler

Figure 7: Samples generated by random-walk Metropolis, Gibbs sampling, and NUTS. The plots compare 1,000 independent draws from a highly correlated 250-dimensional distribu-tion (right) with 1,000,000 samples (thinned to 1,000 samples for display) generated by random-walk Metropolis (left), 1,000,000 samples (thinned to 1,000 samples for display) generated by Gibbs sampling (second from left), and 1,000 samples generated by NUTS (second from right). Only the first two dimensions are shown here.

4.4 Comparing the Efficiency of HMC and NUTS

Figure 6 compares the efficiency of HMC (with various simulation lengthsλ ≈ �L) and NUTS (which chooses simulation lengths automatically). The x-axis in each plot is the targetδused by the dual averaging algorithm from section 3.2 to automatically tune the step size�. The y-axis is the effective sample size (ESS) generated by each sampler, normalized by the number of gradient evaluations used in generating the samples. HMC’s best performance seems to occur aroundδ= 0.65, suggesting that this is indeed a reasonable default value for a variety of problems. NUTS’s best performance seems to occur aroundδ = 0.6, but does not seem to depend strongly onδwithin the range δ∈[0.45,0.65]. δ= 0.6 therefore seems like a reasonable default value for NUTS.

On the two logistic regression problems NUTS is able to produce effectively indepen-dent samples about as efficiently as HMC can. On the multivariate normal and stochastic volatility problems, NUTS withδ= 0.6 outperforms HMC’s best ESS by about a factor of three.

As expected, HMC’s performance degrades if an inappropriate simulation length is cho-sen. Across the four target distributions we tested, the best simulation lengthsλfor HMC varied by about a factor of 100, with the longest optimalλbeing 17.62 (for the multivari-ate normal) and the shortest optimalλbeing 0.17 (for the simple logistic regression). In practice, finding a good simulation length for HMC will usually require some number of preliminary runs. The results in Figure 6 suggest that NUTS can generate samples at least as efficiently as HMC, even discounting the cost of any preliminary runs needed to tune HMC’s simulation length.

25

I Two dimensions of highly correlated 250-dim distribution

I 1M samples from Metropolis, 1M from Gibbs (thin to 1K)

I 1K samples from NUTS, 1K independent draws

(72)

34/44

NUTS vs. Gibbs and Metropolis

The No-U-Turn Sampler

Figure 7: Samples generated by random-walk Metropolis, Gibbs sampling, and NUTS. The plots compare 1,000 independent draws from a highly correlated 250-dimensional distribu-tion (right) with 1,000,000 samples (thinned to 1,000 samples for display) generated by random-walk Metropolis (left), 1,000,000 samples (thinned to 1,000 samples for display) generated by Gibbs sampling (second from left), and 1,000 samples generated by NUTS (second from right). Only the first two dimensions are shown here.

4.4 Comparing the Efficiency of HMC and NUTS

Figure 6 compares the efficiency of HMC (with various simulation lengthsλ ≈ �L) and NUTS (which chooses simulation lengths automatically). The x-axis in each plot is the targetδused by the dual averaging algorithm from section 3.2 to automatically tune the step size�. The y-axis is the effective sample size (ESS) generated by each sampler, normalized by the number of gradient evaluations used in generating the samples. HMC’s best performance seems to occur aroundδ= 0.65, suggesting that this is indeed a reasonable default value for a variety of problems. NUTS’s best performance seems to occur aroundδ = 0.6, but does not seem to depend strongly onδwithin the range δ∈[0.45,0.65]. δ= 0.6 therefore seems like a reasonable default value for NUTS.

On the two logistic regression problems NUTS is able to produce effectively indepen-dent samples about as efficiently as HMC can. On the multivariate normal and stochastic volatility problems, NUTS withδ= 0.6 outperforms HMC’s best ESS by about a factor of three.

As expected, HMC’s performance degrades if an inappropriate simulation length is cho-sen. Across the four target distributions we tested, the best simulation lengthsλfor HMC varied by about a factor of 100, with the longest optimalλbeing 17.62 (for the multivari-ate normal) and the shortest optimalλbeing 0.17 (for the simple logistic regression). In practice, finding a good simulation length for HMC will usually require some number of preliminary runs. The results in Figure 6 suggest that NUTS can generate samples at least as efficiently as HMC, even discounting the cost of any preliminary runs needed to tune HMC’s simulation length.

25

I Two dimensions of highly correlated 250-dim distribution

I 1M samples from Metropolis, 1M from Gibbs (thin to 1K)

I 1K samples from NUTS, 1K independent draws

(73)

34/44

NUTS vs. Gibbs and Metropolis

The No-U-Turn Sampler

Figure 7: Samples generated by random-walk Metropolis, Gibbs sampling, and NUTS. The plots compare 1,000 independent draws from a highly correlated 250-dimensional distribu-tion (right) with 1,000,000 samples (thinned to 1,000 samples for display) generated by random-walk Metropolis (left), 1,000,000 samples (thinned to 1,000 samples for display) generated by Gibbs sampling (second from left), and 1,000 samples generated by NUTS (second from right). Only the first two dimensions are shown here.

4.4 Comparing the Efficiency of HMC and NUTS

Figure 6 compares the efficiency of HMC (with various simulation lengthsλ ≈ �L) and NUTS (which chooses simulation lengths automatically). The x-axis in each plot is the targetδused by the dual averaging algorithm from section 3.2 to automatically tune the step size�. The y-axis is the effective sample size (ESS) generated by each sampler, normalized by the number of gradient evaluations used in generating the samples. HMC’s best performance seems to occur aroundδ= 0.65, suggesting that this is indeed a reasonable default value for a variety of problems. NUTS’s best performance seems to occur aroundδ = 0.6, but does not seem to depend strongly onδwithin the range δ∈[0.45,0.65]. δ= 0.6 therefore seems like a reasonable default value for NUTS.

On the two logistic regression problems NUTS is able to produce effectively indepen-dent samples about as efficiently as HMC can. On the multivariate normal and stochastic volatility problems, NUTS withδ= 0.6 outperforms HMC’s best ESS by about a factor of three.

As expected, HMC’s performance degrades if an inappropriate simulation length is cho-sen. Across the four target distributions we tested, the best simulation lengthsλfor HMC varied by about a factor of 100, with the longest optimalλbeing 17.62 (for the multivari-ate normal) and the shortest optimalλbeing 0.17 (for the simple logistic regression). In practice, finding a good simulation length for HMC will usually require some number of preliminary runs. The results in Figure 6 suggest that NUTS can generate samples at least as efficiently as HMC, even discounting the cost of any preliminary runs needed to tune HMC’s simulation length.

25

I Two dimensions of highly correlated 250-dim distribution

I 1M samples from Metropolis, 1M from Gibbs (thin to 1K)

I 1K samples from NUTS, 1K independent draws

(74)

35/44

NUTS vs. Basic HMC

I 250-D normal and logistic regression models

I Vertical axis shows effective #sims (big is good)

I (Left) NUTS; (Right) HMC with increasingt =L

(75)

36/44

NUTS vs. Basic HMC II

I Hierarchical logistic regression and stochastic volatility

I Simulation time is step sizetimes #steps L

I NUTS can beat optimally tuned HMC

(76)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(77)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(78)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(79)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(80)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(81)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(82)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(83)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(84)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(85)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(86)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(87)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(88)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(89)

37/44

Solving more problems in Stan

I Problem: Need ease of use of BUGS

I Solution: Compile directed graphical model language

I Problem: Need to tune parameters for HMC

I Solution: Auto tuning, adaptation

I Problem: Efficient up-to-proportion density calcs

I Solution: Density template metaprogramming

I Problem: Limited error checking, recovery

I Solution: Static model typing, informative exceptions

I Problem: Poor boundary behavior

I Solution: Calculate limits (e.g. limx→0xlogx)

I Problem: Restrictive licensing (e.g., closed, GPL, etc.)

I Solution: Open-source, BSD license

(90)

38/44

New stuff: Differential equation models

Simple harmonic oscillator:

dz1 dt = −z2 dz2 dt = −z1−θz2 with observations(y1,y2)t,t =1, . . . ,T: y1t ∼ N(z1(t), σ21) y2t ∼ N(z2(t), σ22) Given data(y1,y2)t,t =1, . . . ,T,

estimate initial state(y1,y2)t=0 and parameterθ

(91)

39/44

Stan program: 1

functions {

real[] sho(real t, real[] y, real[] theta, real[] x_r, int[] x_i) { real dydt[2];

dydt[1] <- y[2];

dydt[2] <- -y[1] - theta[1] * y[2]; return dydt; } } data { int<lower=1> T; real y[T,2]; real t0; real ts[T]; } transformed data { real x_r[0]; int x_i[0]; }

(92)

40/44

Stan program: 2

parameters { real y0[2]; vector<lower=0>[2] sigma; real theta[1]; } model { real z[T,2]; sigma ~ cauchy(0,2.5); theta ~ normal(0,1); y0 ~ normal(0,1);

z <- integrate_ode(sho, y0, t0, ts, theta, x_r, x_i); for (t in 1:T)

y[t] ~ normal(z[t], sigma); }

(93)

41/44

Stan output

Run RStan with data simulated from

θ=0.15,y0= (1,0), and σ=0.1: Inference for Stan model: sho.

4 chains, each with iter=2000; warmup=1000; thin=1;

post-warmup draws per chain=1000, total post-warmup draws=4000.

mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat y0[1] 1.05 0.00 0.09 0.87 0.98 1.05 1.10 1.23 1172 1 y0[2] -0.06 0.00 0.06 -0.18 -0.10 -0.06 -0.02 0.06 1524 1 sigma[1] 0.14 0.00 0.04 0.08 0.11 0.13 0.16 0.25 1354 1 sigma[2] 0.11 0.00 0.03 0.06 0.08 0.10 0.12 0.18 1697 1 theta[1] 0.15 0.00 0.04 0.08 0.13 0.15 0.17 0.22 1112 1 lp__ 28.97 0.06 1.80 24.55 27.95 29.37 30.29 31.35 992 1

(94)

42/44

Big Data, Big Model, Scalable Computing

10-3 10-2 10-1 100 102 103 104 105 106 Seconds / Sample Total Ratings 10 Items 100 Items 1000 Items

(95)

43/44

Thinking about scalability

I Hierarchical item response model:

Stan JAGS

# items # raters # groups # data time memory time memory 20 2,000 100 40,000 :02m 16MB :03m 220MB 40 8,000 200 320,000 :16m 92MB :40m 1400MB 80 32,000 400 2,560,000 4h:10m 580MB :??m ?MB

I Also, Stan generated 4x effective sample size per iteration

(96)

43/44

Thinking about scalability

I Hierarchical item response model:

Stan JAGS

# items # raters # groups # data time memory time memory 20 2,000 100 40,000 :02m 16MB :03m 220MB 40 8,000 200 320,000 :16m 92MB :40m 1400MB 80 32,000 400 2,560,000 4h:10m 580MB :??m ?MB

I Also, Stan generated 4x effective sample size per iteration

(97)

43/44

Thinking about scalability

I Hierarchical item response model:

Stan JAGS

# items # raters # groups # data time memory time memory 20 2,000 100 40,000 :02m 16MB :03m 220MB 40 8,000 200 320,000 :16m 92MB :40m 1400MB 80 32,000 400 2,560,000 4h:10m 580MB :??m ?MB

I Also, Stan generated 4x effective sample size per iteration

(98)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(99)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(100)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives

I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(101)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(102)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(103)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo

I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(104)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(105)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle

I Black-box variational Bayes

I Data partitioning and expectation propagation

(106)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

(107)

44/44

Future work

I Programming

I Faster gradients and higher-order derivatives I Functions

I Statistical algorithms

I Riemannian Hamiltonian Monte Carlo I (Penalized) mle

I (Penalized) marginal mle I Black-box variational Bayes

I Data partitioning and expectation propagation

References

Related documents

This paper was organized as the following structure: (a) the intro- duction of the new approach of the real-road simulation, combining the traffic and vehicle simulations; (b)

An osteoid osteoma is a small, benign, intracortical bone tumour, and was the first type of bone tumour treated by thermal ablation [8,9].. RFA is close to 90% effective in dealing

NALCO BT-25 dosage will vary depending on the feedwater calcium hardness and the desired boiler water phosphate residual.. Calcium Factor = 16 ppm NALCO BT-25 per ppm feedwater

Stage 2 Child Care, which is available to families on welfare and with stable employment. Families may be eligible for Stage 2 Child Care for up to 24 months after they stop receiving

Long-term: App user monetization will lead to significantly higher margins and growth rates, likely increasing the valuation levels of myTaste to be more in line with other

In order to show how 9/11 drastically worsened the reality of Muslim communities in the United Kingdom, I will, same as in the first chapter, discuss the legislature,

Altarawneh study (2006) aimed to investigate the effect of using the two amended learning sessions premise explanation assurance predictive and habitual in

Seven outcomes were used in this systematic review to evaluate the effectiveness of social norms interventions that were reported by the included studies: (1) alcohol-related