%slice.m
clear all
close all
%-----------------figure defaults
disp('Illustration of Slice Sampling')
lw = 2;  
set(0, 'DefaultAxesFontSize', 18);
fs = 14;
msize = 5;
%---------------------------------------------
   rand('seed',1)
   xsys=[]; xs=[];
   x=0;
for i=1:5000
   y = exp(-x^2/2)*rand(1,1); %y|x 
   xsys = [xsys; x y];   xs=[xs x];
   x = sqrt(-2*log(y)) * (2*rand(1,1)-1); %x|y
end
%---
figure(1)
plot(xsys(:,1),xsys(:,2),'.')
xlabel('x'); ylabel('y')
print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working11\Figs\slice1.eps'
figure(2)
    qqplot(xs)
xlabel('normal quantiles'); ylabel('slice quantiles'); title('')
print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working11\Figs\slice2.eps'
