吉布斯采样的具体执行过程只需要三个步骤,非常非常简单好理解,其它相关的背景知识能帮助加深理解。
Monte Carlo methods
- 它是很宽泛的一类计算方法,依赖重复的随机采样去获得数值结果。a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results。
- 它的本质是使用随机性去解决确定性的问题。The underlying concept is to use randomness to solve problems that might be deterministic in principle。 it solves deterministic problems using a probabilistic analog(模拟退火也是这样)。MC方法在数学和物理上用的很多,在不可能使用别的方法(很难实现)的时候MC就特别有用。
- 它主要用于解决三种问题:优化,数值积分numerical integration,从概率分布中采样 generating draws from a probability distribution(采出一组满足那个分布的实际取值)。
原则上,蒙特卡罗方法可以用来解决任何具有概率解释having a probabilistic interpretation的问题。根据大数定律By the law of large numbers,某一随机变量的期望可以用该变量的样本的经验均值(即样本均值)来近似。当变量的概率分布参数化时(参数确定下来时),数学家们经常使用马尔可夫链蒙特卡罗(MCMC)采样器 a Markov chain Monte Carlo (MCMC) sampler。- 其核心思想 central idea是设计一个具有给定平稳概率分布的马尔科夫链模型 a prescribed stationary probability distribution。根据遍历理论By the ergodic theorem,用MCMC采样器的随机状态的经验测度来近似平稳分布the stationary distribution is approximated by the empirical measures of the random states of the MCMC sampler。
Markov chain Monte Carlo methods(MCMC方法)
- MCMC方法包含了一类用于从特定概率分布中采样的算法。
Markov chain Monte Carlo methods中的Markov chain 是因为这些方法生成的序列都是马尔科夫链,每个值都只和自己前后几个值有关; Monte Carlo是因为这些方法用的是随机化的方法在解决确定性问题,从已知概率分布中采样出一系列符合这个分布的样本。- 它们是通过构建一个自身的分布接近它的平稳分布的马尔科夫链,这个马尔科夫链就是被采样的分布的一组采样值,这需要观察这个马尔科夫链一些步骤才能完成,且观察的步骤越多,得到的采样值的分布就越接近于想要的分布(即多重复几次以使马尔科夫链达到平稳分布By constructing a Markov chain that has the desired distribution as its equilibrium distribution, one can obtain a sample of the desired distribution by observing[clarification needed] the chain after a number of steps. The more steps there are, the more closely the distribution of the sample matches the actual desired distribution.
- MCMC方法最初是被用于计算多维积分的数值近似值。
- MCMC方法从一个连续随机变量中,以和已知函数成比例的概率密度生成一组采样样本,这组样本就可以用于计算这个变量的期望和方差。
当联合分布不被明确知道或者联合分布很难直接采样但每个变量的条件分布已知且容易采样时,吉布斯采样适用is applicable。
比如在RBM的训练中,假设隐层有10个单元,他们的联合分布已知,那么直接采样得到一个十元向量很难,这时候就可以用吉布斯采样(隐层单元的条件独立性是吉布斯采样可以适用的重要的必需的基础)。
吉布斯采样是一种用于统计推断的方法,尤其是贝叶斯推断 a means of statistical inference, especially Bayesian inference。它是一种随机化算法(即使用随机数的算法),是用于统计推断的确定性算法(如EM算法)的替代品an alternative。
最初的吉布斯采样是Metropolis–Hastings 算法的一个特例。但后来得到扩展,**它可以被看成是一个通用的用于通过依次采样每一个变量从一组变量中采样的框架,**而且可以把Metropolis–Hastings 算法,甚至更高级的算法比如 slice sampling切片采样, adaptive rejection sampling 自适应拒绝采样and adaptive rejection Metropolis algorithms,合并进来实现采样过程的一些步骤。
吉布斯采样依次in turn从每个变量的分布中生成一个实例instance,基于其他变量的当前值 conditional on the current values of the other variables。可以证明,这样生成的采样值序列是一个马尔科夫链,并且这个马尔科夫链的平稳分布就是我们想要采样的那个后验分布。
The point of Gibbs sampling is that given a multivariate distribution it is simpler to sample from a conditional distribution than to marginalize by integrating over a joint distribution.
Gibbs sampling is particularly well-adapted to sampling the posterior distribution of a Bayesian network, since Bayesian networks are typically specified as a collection of conditional distributions.
假设要采样的联合分布是 P ( x 1 , x 2 , ⋯   , x n ) P(x_1,x_2,\cdots,x_n) P(x1,x2,⋯,xn)
要采样k个样本向量
X ( i ) = ( x 1 ( i ) , x 2 ( i ) , ⋯   , x n ( i ) ) , i = 1 , 2 , ⋯   , k \boldsymbol X^{(i)}=(x_1^{(i)},x_2^{(i)},\cdots,x_n^{(i)}),i=1,2,\cdots,k X(i)=(x1(i),x2(i),⋯,xn(i)),i=1,2,⋯,k
分量的条件分布和联合分布成正比,分母不是 x j x_j xj的函数,所以对于 x j x_j xj的所有取值都是一样的,所以就相当于一个 x j x_j xj分布上的归一化函数。所以说对条件分布采样实际和对联合分布采样的效果是一样的。
比如,隐马尔科夫模型中,用块吉布斯采样和前向-后向算法forward-backward algorithm一次得到(in one go)所有潜变量的采样值。
即,假设显层单元为 v = ( v 1 , v 2 , ⋯   , v n ) \boldsymbol v=(v_1,v_2,\cdots,v_n) v=(v1,v2,⋯,vn)
隐层单元为 h = ( h 1 , h 2 , ⋯   , h m ) \boldsymbol h=(h_1,h_2,\cdots,h_m) h=(h1,h2,⋯,hm)