727e2e4Interactive WALNUTS sampling of a 2D banana targetJeremy Magland 1function lp = log_density(theta)
2%LOG_DENSITY Unnormalized log density of the "banana" target.
3% The standard banana from chi-feng's mcmc-demo: a correlated Gaussian
4% (mean [0; 4], covariance [1 0.5; 0.5 1]) pulled into a banana shape by a
5% quadratic twist. theta is a 2x1 column vector. The normalizing constant is
6% dropped (irrelevant for sampling and for the heatmap).
7a = 2;
8b = 0.2;
9x1 = theta(1);
10x2 = theta(2);
11% Twist x -> y, then evaluate the Gaussian at y.
12y1 = x1 / a;
13y2 = x2 * a + a * b * (x1.^2 + a.^2);
14d1 = y1 - 0;
15d2 = y2 - 4;
16% Q = d' * inv(Sigma) * d, with inv([1 .5; .5 1]) = [4/3 -2/3; -2/3 4/3].
17Q = (4 / 3) * (d1.^2 + d2.^2) - (4 / 3) * d1 .* d2;
18lp = -0.5 * Q;
19end