Chapter 3: sampling and posterior distributions for the cauchy
Chapter 3: sampling and posterior distributions for the cauchy
We begin with (3.38), and compute the posterior with respect to a uniform prior over the unknown location parameter. We will utilize a known width parameter in this example, of :
% Cauchy sampling example
%D=cauchyrnd(0,3,[401 1]);
%save Cdat D
load Cdat.mat
rdat=D';
Ns=[1 10 100];
mus=linspace(-25,25,1201)';
alpha=3; Om=ones(size(mus));
COL=[zeros(1,3); .5*[1 1 1]; [.3 .4 .7]];
SYM={':','--','-'};
figure(2); clf
for iN=1:length(Ns), Nnow=Ns(iN);
rdatnow=D(1:Nnow)'; Or=ones(1,Nnow);
floglike=sum(log(alpha)-log((alpha.^2+(Om*rdatnow-mus*Or).^2)),2)-log(pi);
floglike=floglike-max(floglike);
subplot(2,1,1); hold on; plot(mus, floglike ,SYM{iN},'Color',COL(iN,:),'LineWidth',2);
subplot(2,1,2); hold on; plot(mus,exp(floglike),SYM{iN},'Color',COL(iN,:),'LineWidth',2); end
subplot(2,1,1); axis([mus(1) mus(end) -10 0])
subplot(2,1,2); axis([mus(1) mus(end) 0 1])