Matlab practice Matlab code taken from Professor Joo Ho Choi He applied it to with proposal distribution Nx10 Matlab code for that give in the notes Here applied to the triangular distribution with Ux025x025 ID: 549483
Download Presentation The PPT/PDF document "Metropolis Algorithm" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Metropolis Algorithm Matlab practice
Matlab 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)Slide2
Metropolis-Hastings algorithm
Metropolis algorithm A proposal distribution q(x*|x) is symmetric w.r.t x* and x. Then the ratio is simplified. Example: normal pdf at x* with mean at x equals to the vice versa.Practice with matlabGenerate samples of this distribution using a proposal
pdf As the random walk progresses, the number of samples are increased, and the distribution converges to the target distribution.Slide3
Triangular distribution
p=2x in [0,1]Matlab realization p=@(x) heaviside(x).*heaviside(1-x)*2.*xxx=linspace(-1,2,301); fp=p(xx); plot (xx,fp)Slide4
Uniform proposal distribution
q(x)=U(x-0.25,x+0.25)Sampling:clear; X(1)=0; N=1e4; delta=0.25;for i=1:N-1;x=X(i); xs=x+2*(rand-0.5)*deltau=randif u<min(1,p(xs
)/(p(x)+1.e-10)); X(1+i)=xs; else; X(1+i)=x; end;endPlottingN0=1; xx=linspace(0,1,26);dx=0.04; %It often pays to have larger N0
nb=histc(X(N0+1:N),xx); bar(xx+dx/2,nb/(N-N0)/dx);Slide5
Compare CDFs
ecdf(X); hold onxx=linspace(0,1,101);xx2=xx.^2;plot(xx,xx2,'r')legend('
ecdf','exact')Slide6
practice problems
Try triangular distribution with with a normal proposal distribution with different mean and standard deviations.Do Professor Choi’s example with different starting points.
Source: Smithsonian Institution
Number: 2004-57325