15
$\begingroup$

I went through Geoff Hinton's Neural Networks course on Coursera and also through introduction to restricted boltzmann machines, still I didn't understand the intuition behind RBMs.

Why do we need to compute energy in this machine? And what is the use of the probability in this machine? I also saw this video. In the video, he just wrote the probability and energy equations before the computation steps and didn't appear to use it anywhere.

Adding to the above, I am not sure what the likelihood function is for?

$\endgroup$
  • $\begingroup$ I have tried to tidy up the question, but I think it needs more work. You need to explain what you do understand, and more specifically where you are stuck, otherwise the question is too broad. $\endgroup$ – Neil Slater Dec 7 '16 at 16:31
  • $\begingroup$ The only thing which got into the head is there are three steps, first the positive phase, then the negative phase which is followed by the reconstruction of weights. But, what about the energies and probability function? what is the use over here? and how many times we have to do this process (positive phase -> negative phase > reconstruction of weights)? $\endgroup$ – Born2Code Dec 7 '16 at 17:03
5
$\begingroup$

RBM's are an interesting beast. To answer your question, and to jog my memory on them, I'll derive RBMs and talk through the derivation. You mentioned that you're confused on the likelihood, so my derivation will be from the perspective of trying to maximize the likelihood. So let's begin.

RBMs contain two different sets of neurons, visible and hidden, I'll denote them $v$ and $h$ respectively. Given a specific configuration of $v$ and $h$, we map it the probability space.

$$p(v,h) = \frac{e^{-E(v,h)}}{Z}$$

There are a couple things more to define. The surrogate function we use to map from a specific configuration to the probability space is called the energy function $E(v,h)$. The $Z$ constant is a normalization factor to ensure that we actually map to the probability space. Now let's get to what we're really looking for; the probability of a set of visible neurons, in other words, the probability of our data. $$Z = \sum_{v \in V}\sum_{h \in H}e^{-E(v,h)}$$ $$p(v)=\sum_{h \in H}p(v,h)=\frac{\sum_{h \in H}e^{-E(v,h)}}{\sum_{v \in V}\sum_{h \in H}e^{-E(v,h)}}$$

Although there are a lot of terms in this equation, it simply comes down to writing the correct probability equations. Hopefully, so far, this has helped you realize why we need energy function to calculate the probability, or what is done more usually the unnormalized probability $p(v)*Z$. The unnormalized probability is used because the partition function $Z$ is very expensive to compute.

Now let's get to the actual learning phase of RBMs. To maximize likelihood, for every data point, we have to take a gradient step to make $p(v)=1$. To get the gradient expressions it takes some mathematical acrobatics. The first thing we do is take the log of $p(v)$. We will be operating in the log probability space from now on in order to make the math feasible.

$$\log(p(v))=\log[\sum_{h \in H}e^{-E(v,h)}]-\log[\sum_{v \in V}\sum_{h \in H}e^{-E(v,h)}]$$ Let's take the gradient with respect to the paremeters in $p(v)$

\begin{align} \frac{\partial \log(p(v))}{\partial \theta}=& -\frac{1}{\sum_{h' \in H}e^{-E(v,h')}}\sum_{h' \in H}e^{-E(v,h')}\frac{\partial E(v,h')}{\partial \theta}\\ & + \frac{1}{\sum_{v' \in V}\sum_{h' \in H}e^{-E(v',h')}}\sum_{v' \in V}\sum_{h' \in H}e^{-E(v',h')}\frac{\partial E(v,h)}{\partial \theta} \end{align}

Now I did this on paper and wrote the semi-final equation down as to not waste a lot of space on this site. I recommend you derive these equations yourself. Now I'll write some equations down that will help out in continuing our derivation. Note that: $Zp(v,h)=e^{-E(v,h')}$, $p(v)=\sum_{h \in H}p(v,h)$ and that $p(h|v) = \frac{p(v,h)}{p(h)}$

\begin{align} \frac{\partial log(p(v))}{\partial \theta}&= -\frac{1}{p(v)}\sum_{h' \in H}p(v,h')\frac{\partial E(v,h')}{\partial \theta}+\sum_{v' \in V}\sum_{h' \in H}p(v',h')\frac{\partial E(v',h')}{\partial \theta}\\ \frac{\partial log(p(v))}{\partial \theta}&= -\sum_{h' \in H}p(h'|v)\frac{\partial E(v,h')}{\partial \theta}+\sum_{v' \in V}\sum_{h' \in H}p(v',h')\frac{\partial E(v',h')}{\partial \theta} \end{align}

And there we go, we derived maximum likelihood estimation for RBM's, if you want you can write the last two terms via expectation of their respective terms (conditional, and joint probability).

Notes on energy function and stochasticity of neurons.

As you can see above in my derivation, I left the definition of the energy function rather vague. And the reason for doing that is that many different versions of RBM implement various energy functions. The one that Hinton describes in the lecture linked above, and shown by @Laurens-Meeus is: $$E(v,h)=−a^Tv−b^Th−v^TWh.$$

It might be easier to reason about the gradient terms above via the expectation form.

$$\frac{\partial \log(p(v))}{\partial \theta}= -\mathop{\mathbb{E}}_{p(h'|v)}\frac{\partial E(v,h')}{\partial \theta}+\mathop{\mathbb{E}}_{p(v',h')}\frac{\partial E(v',h')}{\partial \theta}$$

The expectation of the first term is actually really easy to calculate, and that was the genius behind RBMs. By restricting the connection the conditional expectation simply becomes a forward propagation of the RBM with the visible units clamped. This is the so called wake phase in Boltzmann machines. Now calculating the second term is much harder and usually Monte Carlo methods are utilized to do so. Writing the gradient via average of Monte Carlo runs:

$$\frac{\partial \log(p(v))}{\partial \theta}\approx -\langle \frac{\partial E(v,h')}{\partial \theta}\rangle_{p(h'|v)}+\langle\frac{\partial E(v',h')}{\partial \theta}\rangle_{p(v',h')}$$

Calculating the first term is not hard, as stated above, therefore Monte-Carlo is done over the second term. Monte Carlo methods use random successive sampling of the distribution, to calculate the expectation (sum or integral). Now this random sampling in classical RBM's is defined as setting a unit to be either 0 or 1 based on its probability stochasticly, in other words, get a random uniform number, if it is less than the neurons probability set it to 1, if it is greater than set it to 0.

$\endgroup$
  • $\begingroup$ How do we make hidden layer binary too? Bcoz after the activation function operation, we would be getting values in the range between 0 and 1. $\endgroup$ – Born2Code Dec 8 '16 at 8:17
  • $\begingroup$ This is usually done by thresholding the activation. Anything above 0.5, would become 1, anything below would be zero. $\endgroup$ – Armen Aghajanyan Dec 8 '16 at 8:53
  • $\begingroup$ But in this link , in section 3.1: Hinton has stated "the hidden unit turns on if this probability is greater than a random number uniformly distributed between 0 and 1". What does this actually mean? And also in this link, they say "Then the jth unit is on if upon choosing s uniformly distributed random number between 0 and 1 we find that its value is less than sig[j]. Otherwise it is off." I didn't get this. $\endgroup$ – Born2Code Dec 8 '16 at 9:02
  • $\begingroup$ ????? How to say whether that particular unit is turned on or off? $\endgroup$ – Born2Code Dec 8 '16 at 9:48
  • $\begingroup$ I've added an edit. I suggest reading up on Monte Carlo methods because the stochasticity of this algorithm is derived from there. $\endgroup$ – Armen Aghajanyan Dec 8 '16 at 16:38
5
$\begingroup$

In addition to the existing answers, I would like to talk about this energy function, and the intuition behind that a bit. Sorry if this is a bit long and physical.

The energy function describes a so-called Ising model, which is a model of ferromagnetism in terms of statistical mechanics / quantum mechanics. In statistical mechanics, we use a so-called Hamiltonian operator to describe the energy of a quantum-mechanical system. And a system always tries to be in the state with the lowest energy.

Now, the Ising model basically describes the interaction between electrons with a spin $\sigma_k$ of either +1 or -1, in presence of an external magnetic field $h$. The interaction between two electrons $i$ and $j$ is described by a coefficient $J_{ij}$. This Hamiltonian (or energy function) is $$\hat{H} = \sum_{i,j} J_{ij} \sigma_i \sigma_j - \mu \sum_j h_j \sigma_j$$ where $\hat{H}$ denotes the Hamiltonian. A standard procedure to get from an energy function to the probability, that a system is in a given state (i.e. here: a configuration of spins, e.g. $\sigma_1 = {+1}, \sigma_2 = {-1}, ...$) is to use the Boltzmann distribution, which says that at a temperature $T$, the probability $p_i$ of the system to be in a state $i$ with energy $E_i$ is given by $$p_i = \frac{\exp(-E_i/kT)}{\sum_{i}\exp(-E_i/kt)}$$ At this point, you should recognize that these two equations are the exact same equations as in the videos by Hinton and the answer by Armen Aghajanyan. This leads us to the question:

What does the RBM have to do with this quantum-mechanical model of ferromagnetism?

We need to use a final physical quantity: the entropy. As we know from thermodynamics, a system will settle in the state with the minimal energy, which also corresponds to the state with the maximal entropy.

As introduced by Shanon in 1946, in information theory, the entropy $H$ can also be seen as a measure of the information content in $X$, given by the following sum over all possible states of $X$: $$H(X) = -\sum_i P(x_i) \log P(x_i)$$ Now, the most efficient way to encode the information content in $X$, is to use a way that maximizes the entropy $H$.

Finally, this is where we get back to RBMs: Basically, we want this RBM to encode as much information as possible. So, as we have to maximize the (information-theoretical) entropy in our RBM-System. As proposed by Hopfield in 1982, we can maximize the information-theoretical entropy exactly like the physical entropy: by modelling the RBM like the Ising model above, and use the same methods to minimize the energy. And that is why we need this strange energy function for in an RBM!

The nice mathematical derivation in Armen Aghajanyan's answer shows everything we need to do, to minimize the energy, thus maximizing entropy and storing / saving as much information as possible in our RBM.

PS: Please, dear physicists, forgive any inaccuracies in this engineer's derivation. Feel free to comment on or fix inaccuracies (or even mistakes).

$\endgroup$
  • $\begingroup$ I saw this video, Just watch the video from that point. how do you get that sampled number? whether we have just run rand() in matlab and obtain it? and then it would be different for each h(i) . Oh nooo! I don't think machine will learn properly. $\endgroup$ – Born2Code Dec 9 '16 at 4:38
  • $\begingroup$ @Born2Code this is another question. Can you post it as a new question to this site? Please try to add the equations you are talking about to the new question, and explain what parts you don't understand. $\endgroup$ – hbaderts Dec 9 '16 at 14:51
  • $\begingroup$ link $\endgroup$ – Born2Code Dec 10 '16 at 2:57
0
$\begingroup$

The answer of @Armen has gave myself a lot of insights. One question hasn't been answered however.

The goal is to maximize the probability (or likelihood) of the $v$. This is correlated to minimizing the energy function related to $v$ and $h$:

$$E(v,h) = -a^{\mathrm{T}} v - b^{\mathrm{T}} h -v^{\mathrm{T}} W h$$

Our variables are $a$, $b$ and $W$, which have to be trained. I'm quite sure this training will be the ultimate goal of the RBM.

$\endgroup$
  • $\begingroup$ How do we make hidden layer binary too? Bcoz after the activation function operation, we would be getting values in the range between 0 and 1. $\endgroup$ – Born2Code Dec 8 '16 at 11:30
  • $\begingroup$ @Born2Code: The activation function gives you the probability that a neuron has value 1. Therefore to "make it binary", you sample from the probabilities calculated for either $h$ or $v$ - in other words you literally do something like h_bin = (rand() < h_val) ? 1 : 0 - this has to be done for each neuron, and each time you want a sample. $\endgroup$ – Neil Slater Dec 8 '16 at 12:03
  • $\begingroup$ @NeilSlater: but why a random number? Also, whether the random should be generated for each iteration or the same number should be used for all the iterations? one more serious doubt, how many iterations have to be done? I have a training set V, which has only one vector, i.e. v1. With v1, how many times should I have to iterate? $\endgroup$ – Born2Code Dec 8 '16 at 12:10
  • $\begingroup$ @NeilSlater: One more doubt is, whether the same random number is to be compared with all the values of hidden layer? I know this is such an idiotic question but still $\endgroup$ – Born2Code Dec 8 '16 at 12:25
  • 1
    $\begingroup$ It's a random number because that is how you resolve probabilities to binary values. It is a dIfferent number for each neuron inside h or v - you are sampling a vector of binary values for h or v, in order to generate an example that the network "believes" exists - i.e. an example that has a high statistical chance of being representative of the training set. During training, you determine how well it matches an existing training example and adjust weights accordingly. $\endgroup$ – Neil Slater Dec 8 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.