MATLAB抽取随机数MCMC原理
概率统计推断中许多问题需要计算复杂的积分或者在⼤的结果空间内求和。如计算函数的期望,其中是随机变量,密度函数为,如果是连续随机变量,则
若是离散随机变量,则
The general idea of Monte Carlo integration is to use samples to approximate the expectation of a complex distribution.(蒙特卡洛积分的⼀般思想是⽤抽样的样本矩近似复杂分布的期望)
是从分布抽取的独⽴样本,因此,我们可⽤有限项求和近似上述积分:
⼀般来说,随着增加抽样量,近似精度越来越⾼。Crucially,近似精度还依赖于样本的相关性。当样本是相关的,有效样本规模减⼩。(When the samples are correlated, the effective sample size decreases. This is not an issue with the rejection sampler but a potential problem with MCMC approaches. 我是这么理解的,对与Metropolis-Hastings算法来讲,相关性不是问题,因为采⽤了rejection策略,⽽对于Gibbs抽样,需要注意相关性问题,因为在Gibbs抽样中抽得的样本全留下。)
⼆、Markov chains
A markov chain is a stochastic process where we transition from one state to another state using a simple sequential procedure.设起始状态为,转移函数为(to determine the next state, conditional on the last state.) We then keep iterating to create a sequence of states:
产⽣T个状态的Markov链的步骤如下:
1. Set
2. Generate a initial value , and set .
3. Repeat
   t=t+1
   sample a new value from the transition function
   set
4. Until .
下⾯重点介绍MCMC,讨论三种⽅法Metropolis,Metropolis-Hasting,Gibbs sampling。
MCMC关键的两个分布是target distribution和proposal distribution。MCMC的⽬的就是抽target distribution的样本。
Metropolis算法
  Metropolis是MCMC所有⽅法中最简单的,是Metropolis-Hastings的⼀种特殊情形,proposal分布需要对称()。
  算法步骤:matlab生成随机数
  1. Set
  2. Generate a initial value , and set .
  3. Repeat
     Generate a proposal from
     Evaluate the acceptance probability
     Generate a from a Uniform(0,1) distribution
     If , accept the proposal and set ,else set .
  4.Until .   
注意给定的proposal distribution 实际上是个条件分布。从接受率公式可看出,target distribution可以是unnormalized。
Metropolis-Hastings算法
Metropolis-Hastings算法(MH)是Metropolis算法的generalized version。 算法步骤⼀样,但是接受率需改为
  proposal distribution的选取原则
  可以看出,在Metropolis算法和MH算法中,proposal distribution起到和很重要的作⽤。proposal distribution原则上可以任意选择,常见有两种简单⽅式,⼀种是随机游动链,新值为现在值加上⼀随机变量,即,此时,,其中为任⼀概率密度。另⼀种称为独⽴链,新
值与现在值⽆关,即,其中为任⼀概率密度。对于有界的随机变量,注意应该建⽴合适的proposal distribution。Generally,⼀个好的rule是to use a proposal distribution has positive density on the sa
me support as the target distribution. For example, if the target distribution has support over ,the proposal distribution should have the same support. 

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。