banana: banana

Description Usage Arguments Details Value Examples

Description

Let (u, v) be distributed bivariate normal with mean 0 and correlation r and let (x, y) be distributed banana with

x = u a

and

y = v/a + b (u^2 + a^2).

Usage

1
banana(a, b, r)

Arguments

a

Input parameter a defined above

b

Input parameter b defined above

r

Input parameter r defined above

Details

This function takes a, b, and r as inputs and returns a list containing a function to evaluate the PDF of this distribution, a function to evaluate the gradient of this distribution, and a function to draw random samples from this distribution.

Value

list with functions target, grad, and sample

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
ban <- banana(a = 1.25, b = .5, r = .95)
xy <- ban$sample(1000)
plot(xy)
z <- ban$target(xy[,1], xy[,2])
# Show the density
library(ggplot2)
xyz <- as.data.frame(cbind(xy, z))
ggplot(xyz, aes(x, y, alpha = z)) + geom_point(colour = 'black')
# Simulate Hamiltonian behavior starting at 0 with step size .06
f <- function(g){ .06 * ban$grad(g[1], g[2])}
path <- matrix(0, ncol = 2, nrow = 40)
for (i in 1 + seq_len(39)) {
  path[i,] <- path[i-1,] + f(path[i-1,])
}
ggplot(NULL, aes(x, y)) +
  geom_point(aes(alpha = z), data = xyz, colour = 'black', show.legend = FALSE) +
  geom_path(aes(x = path[,1], y = path[,2], alpha = 1), data = NULL, colour ='red', show.legend = FALSE) +
  coord_cartesian(xlim = c(-1, .1), ylim = c(-.1, 1))

jasonmtroos/gentleHMC documentation built on May 14, 2019, 2:06 p.m.