Metropolis Paclet SymbolMore About »

Metropolis

Metropolis[logpdf, logpdfjump, randomjump, x0, n]
generates n Metropolis updates starting from x0. The target distribution is p[x] with the proposal distribution J[xt, x] randomized by x = randomjump[xt] given current xt. Here logpdf[x] = Log[p[x]] and logpdfjump[xt,x] = Log[J[xt,x]]
  • To use Metropolis, you first need to load the Metropolis package using Needs["Metropolis`"].
  • The following options can be given:
DomainConstraintTrue & random variable x satifies DomainConstraint[x]
StartLogpdfNoneprovide Log[p[x0]]
IsReturnLastTruewhether return the last Metropolis update
PrintDetailsFalsewhether print details
  • Each update is given by {x, logpdf[x], 1/0 (acccept/not), Min[1,Metropolis-Hastings ratio]}.
In[1]:=
Click for copyable input
This samples the standard normal distribuiton
In[2]:=
Click for copyable input
Out[2]=
Mean accept ratio:
In[3]:=
Click for copyable input
Out[3]=
Time serie:
In[4]:=
Click for copyable input
Out[4]=
Simulated distribution vs target distribution (red line):
In[5]:=
Click for copyable input
Out[5]=