Restricted Boltzmann Machines
—-目錄
Energy-Based Models (EBM)
Energy-based models associate a scalar energy to each configuration of the variables of interest. Learning corresponds to modifying that energy function so that its shape has desirable properties. For example, we would like plausible or desirable configurations to have low energy. Energy-based probabilistic models define a probability distribution through an energy function, as follows:
The normalizing factor Z is called the partition function by analogy with physical systems.
EBMs with Hidden Units
In many cases of interest, we do not observe the example x fully, or we want to introduce some non-observed variables to increase the expressive power of the model. So we consider an observed part (still denoted x here) and a hidden part h. We can then write:
In such cases, to map this formulation to one similar to Eq. (1), we introduce the notation (inspired from physics) of free energy, defined as follows:
which allow us to write:
The data negative log-likelihood gradient then has a particularly intresting form.
推導過程如下:(注意x和
Notice that the above gradient contains two terms, which are referred to as the positive and negative phase. The terms positive and negative do not refer to the sign of each term in the equation, but rather reflect their effect on the probability density defined by the model. The first term increases the probability of training data (by reducing the corresponding free energy), while the second term decreases the probability of samples generated by the model.
It is usually difficult to determine this gradient analytically, as it involves the computation of
The first step in making this computation tractable is to estimate the expectation using a fixed number of model samples. Samples used to estimate the negative phase gradient are referred to as negative particles, which are denoted as
where we would ideally like elements
有了以上的公式,我們基本上就可以訓練一個EBM了,唯一留下的問題是how to extract these negative particles
Restricted Boltzmann Machines (RBM)
Boltzmann Machines (BMs) are a particular form of log-linear Markov Random Field (MRF), i.e., for which the energy function is linear in its free parameters. To make them powerful enough to represent complicated distributions (i.e., go from the limited parametric setting to a non-parametric one), we consider that some of the variables are never observed (they are called hidden). By having more hidden variables (also called hidden units), we can increase the modeling capacity of the Boltzmann Machine (BM). Restricted Boltzmann Machines further restrict BMs to those without visible-visible and hidden-hidden connections. A graphical depiction of an RBM is shown below.
The energy function E(v,h) of an RBM is defined as:
where
This translates directly to the following free energy formula(其中
Because of the specific structure of RBMs, visible and hidden units are conditionally independent given one-another. Using this property, we can write:
RBMs with binary units
In the commonly studied case of using binary units (where
首先我們將式(8)寫成標量的形式:
所以有:
注意:其中
同理也可以推導出式(12)。
The free energy of an RBM with binary units further simplifies to:
因爲
我們可以通過式(6)來對RBM的各個參數(b, c, W)求導,不過計算量太大,不可取,我們可以通過採樣的方法來近似估計。
Sampling in an RBM
Samples of p(x) can be obtained by running a Markov chain to convergence, using Gibbs sampling as the transition operator.
Gibbs sampling of the joint of N random variables
For RBMs, S consists of the set of visible and hidden units. However, since they are conditionally independent, one can perform block Gibbs sampling. In this setting, visible units are sampled simultaneously given fixed values of the hidden units. Similarly, hidden units are sampled simultaneously given the visibles. A step in the Markov chain is thus taken as follows:
注意h和v均是向量,每個分量同時採樣。
where
This can be illustrated graphically:
As
Contrastive Divergence (CD-k)
Contrastive Divergence uses two tricks to speed up the sampling process:
- since we eventually want
p(v)≈ptrain(v) (the true, underlying distribution of the data), we initialize the Markov chain with a training example (i.e., from a distribution that is expected to be close to p, so that the chain will be already close to having converged to its final distribution p).例如我們用訓練樣本來初始化Markov chain,使得模型最後達到和訓練數據相同的分佈。 - CD does not wait for the chain to converge. Samples are obtained after only k-steps of Gibbs sampling. In pratice, k=1 has been shown to work surprisingly well.
- restarting a chain for each observed example. 每次Markov Chain 收斂,求得參數的梯度後,再重新初始化Markov Chain,再求參數的梯度,以此類推。
我們可以通過CD-k算法來估計梯度的計算:
x可以是輸入的訓練樣本,而
詳細的請見下面代碼:
# determine gradients on RBM parameters
# note that we only need the sample at the end of the chain
chain_end = nv_samples[-1]
cost = T.mean(self.free_energy(self.input)) - T.mean(
self.free_energy(chain_end))
# We must not compute the gradient through the gibbs sampling
gparams = T.grad(cost, self.params, consider_constant=[chain_end])
Persistent CD
Persistent CD Tieleman08(詳細請參考論文) uses another approximation for sampling from p(v,h). It relies on a single Markov chain, which has a persistent state (i.e., not restarting a chain for each observed example). For each parameter update, we extract new samples by simply running the chain for k-steps. The state of the chain is then preserved for subsequent updates.
The general intuition is that if parameter updates are small enough compared to the mixing rate of the chain, the Markov chain should be able to “catch up” to changes in the model.
one RBM example
代碼請參考我的githubRestrictedBoltzmannMachines.py.
參考資料
【1】DeepLearning Tutorial Restricted Boltzmann Machines (RBM),這個是使用Theano實現深度學習算法的一個教程。
【2】 section 5 of Learning Deep Architectures for AI這是Hinton大神提出怎麼訓練RBM的文章。
【3】受限玻爾茲曼機(RBM)學習筆記,這是一個很詳細的RBM原理講解的教程,非常好懂。