1% WALNUTS sampling of a 2D target.
2%
3% WALNUTS (the within-orbit adaptive leapfrog No-U-Turn Sampler) builds a
4% Hamiltonian orbit, refining the leapfrog step within the orbit so the energy
5% stays accurate, and picks a draw from the orbit. This samples a 2D target
6% (banana by default) and shows the density with the samples on top.
7%
8% The sampler is Nawaf Bou-Rabee's reference MATLAB implementation
9% (helpers/walnuts.m + helpers); the target is helpers/log_density.m /
10% grad_log_density.m. `addpath` must be the first statement.
12addpath('helpers'); % walnuts, extend_orbit_*, micro, leapfrog, u_turn, ...
14rng(1); % reproducible
16walnuts_sampler(1000, 0.8, log(1 / 0.66)); % N samples, step h, energy tol delta