Adaptive rejection Metropolis sampling
- Dr. Jarad Niemi
STAT 615 - Iowa State University
November 14, 2017
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 1 / 20
Adaptive rejection Metropolis sampling Dr. Jarad Niemi STAT 615 - - - PowerPoint PPT Presentation
Adaptive rejection Metropolis sampling Dr. Jarad Niemi STAT 615 - Iowa State University November 14, 2017 Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 1 / 20 (Logarithmically) Concave Univariate Function
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 1 / 20
x y p(x) p(y)
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 2 / 20
1e−05 1e−03 1e−01 1 2 3 4 5
x density distribution
cauchy exponential normal
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 3 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 4 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 5 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 6 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 7 / 20
0.0 0.5 1.0 1 2 3
x density distribution
Exp(1) M*Exp(1) N^+(0,1) 0.01 0.10 1.00 1 2 3
x log density
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 8 / 20
0.0 0.3 0.6 0.9 1 2 3 4 5
x M*Exp(x;1) accept
FALSE TRUE
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 9 / 20
log density density Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 10 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 11 / 20
library(ars) f = function(x) -x^2/2 # log of standard normal density fp = function(x) -x # derivative of log of standard normal density x = ars(1e4, f, fp)
x Density −2 2 4 0.0 0.1 0.2 0.3 0.4
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 12 / 20
f = function(x) log(1/(1+x^2)) # log of standard cauchy density fp = function(x) -2*x/(1+x^2) # derivative of log of cauchy density x = ars(1e4, f, fp) ## ## Error in sobroutine initial_... ## ifault= 5 Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 13 / 20
y = rnorm(10) f = Vectorize(function(theta) sum(-(y-theta)^2/2) - abs(theta)) fp = Vectorize(function(theta) sum((y-theta)) - (theta>0) + (theta<0)) x = ars(1e4, f, fp) Posterior for Normal data with Laplace prior on mean
x Density −1.0 −0.5 0.0 0.5 1.0 0.0 0.5 1.0 1.5
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 14 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 15 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 16 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 17 / 20
−4 −2 2 4 −5 −4 −3 −2 −1
x f(x, v)
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 18 / 20
f = function(x,mean) -(x-mean)^2/2 x = dlm::arms(runif(1,3,17), f, function(x,mean) ((x-mean)>-7)*((x-mean)<7), 1e4, mean=10) hist(x,101,prob=TRUE,main="Gaussian(10,1)") curve(dnorm(x,10), add=TRUE, lwd=2, col='red')
x Density 6 8 10 12 14 0.0 0.1 0.2 0.3 0.4
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 19 / 20
Jarad Niemi (STAT615@ISU) Adaptive rejection Metropolis sampling November 14, 2017 20 / 20