6
Metropolis Algorithm Matlab practice Matlab code taken from Professor Joo-Ho Choi He applied it to with proposal distribution N(x,10). Matlab code for that give in the notes. Here applied to the triangular distribution with U(x-0.25,x+0.25) 2 2 0.3exp 0.2 0.7exp 0.2 10 px x x

Metropolis Algorithm Matlab practice

Embed Size (px)

DESCRIPTION

Metropolis Algorithm Matlab practice. Matlab code taken from Professor Joo -Ho Choi He applied it to with proposal distribution N(x,10). Matlab code for that give in the notes. Here applied to the triangular distribution with U(x-0.25,x+0.25). Metropolis-Hastings algorithm. - PowerPoint PPT Presentation

Citation preview

PowerPoint Presentation

Metropolis Algorithm Matlab practiceMatlab code taken from Professor Joo-Ho ChoiHe applied it towith proposal distribution N(x,10).Matlab code for that give in the notes. Here applied to the triangular distribution with U(x-0.25,x+0.25)

% page8: Metropolis(-Hastings) algorithm% true (target) pdf is p(x) where we know it but cant sample data. % proposal (sample) pdf is q(x*|x)=N(x,10) where we can sample.clear; X(1)=0; N=1e4;p = @(x) 0.3*exp(-0.2*x.^2)+0.7*exp(-0.2*(x-10).^2); dx=0.5; xx=-10:dx:20; fp=p(xx); plot(xx,fp)sig=10; for i=1:N-1; u=rand; x=X(i); xs=normrnd(x,sig); % new sample xs based on existing x from proposal pdf. pxs=p(xs);px=p(x); qxs=normpdf(xs,x,sig);qx=normpdf(x,xs,sig); % get p,q. if u