# Modified Conditional Restricted Boltzmann Machines for Query Recommendation in Digital Archives
## 3 RBMs and CRBMs
### Learning Rule of RBMs  
Different from other EBM models that directly minimize the defined loss functions (or energy functions) in the learning phase, RBMs minimize the negative log-likelihood of the probabilities of the observed variables \(\mathbf{v}^{(t)}\) that are clamped to the visible layer:  
\[\mathcal{L}_{E} =\frac{\partial-\log p\Big{(}\mathbf{v}^{(t)}\Big{)}}{\partial \theta}\] \[=\partial-\Bigg{(}\log\sum_{\mathbf{h}}\exp\Big{(}-E\Big{(} \mathbf{v}^{(t)},\mathbf{h}\Big{)}\Big{)}-\log\sum_{\mathbf{v},\mathbf{h}} \exp(-E(\mathbf{v},\mathbf{h}))\Bigg{)}/\partial\theta\] \[=\mathbb{E}_{\mathbf{h}}\Bigg{[}\frac{\partial E\Big{(}\mathbf{ v}^{(t)},\mathbf{h}\Big{)}}{\partial\theta}\mid\mathbf{v}^{(t)}\Bigg{]}-\mathbb{E}_{ \mathbf{v},\mathbf{h}}\bigg{[}\frac{\partial E(\mathbf{v},\mathbf{h})}{ \partial\theta}\Bigg{]}, \tag{9}\]  
where \(\theta\) is all the parameters in the case of RBMs, in which \(\theta=\{\mathbf{W},\mathbf{b_{v}},\mathbf{b_{h}}\}\). Free energy is often utilized instead of the original energy function when training RBMs with a negative log-likelihood because free energy is fast to compute and can avoid the extremely small values that exist in the energy function. It is defined as follows:  
\[\mathcal{L}_{F}=-\log p(\mathbf{v}^{(t)})=F^{c}(\mathbf{v}^{(t)})-F, \tag{10}\]  
where both \(F\) and \(F^{c}\) are free energy and \(F^{c}\) is with the visible units clamped with the observed visible variables (or the training data points \(v^{(t)}\)). Thus, it is also referred to as the clamped free energy. The definition of free energy is below:  
\[F(\mathbf{v}) =-\log Z\] \[=-\mathbf{b_{v}}^{\top}\mathbf{v}-\sum_{j}\log\Big{(}\mathbf{1}+ \exp\Big{(}\mathbf{b_{h}}+\mathbf{W}^{\top}\mathbf{v}\Big{)}\Big{)}_{j} \tag{11}\]  
The loss function \(L\) constructed by the energy or free energy is often denoted as follows:  
\[\mathcal{L}=\left\langle\cdot\right\rangle_{data}-\left\langle\cdot\right\rangle _{model}\quad, \tag{12}\]  
where \(\left\langle\cdot\right\rangle\) represents the expectations under the distribution of the data and the model. The first term \(\left\langle\cdot\right\rangle_{data}\) is called the \"positive phase\", and the second term \(\left\langle\cdot\right\rangle_{model}\) is called the \"negative phase\". The positive phase would increase the probability of observing the configurations by reducing the energy (or free energy). Conversely, the negative phase would decrease the probability of samples generated by the model by raising the energy (or free energy). In RBMs, if they use an energy function to construct the loss function, then the value of the positive phase is estimated by replacing the unknown hidden variables \(\mathbf{h}\) in \(E\Big{(}\mathbf{v}^{(t)},\mathbf{h}\Big{)}\) by first applying the forward inference in Equation (7) to the training data, obtaining \(\mathbf{h}^{(0)}\), and then computing the estimated energy expectation \(E\Big{(}\mathbf{v}^{(t)},\mathbf{h}^{(0)}\Big{)}\). If they use free energy to construct the loss function, then there is no need to estimate \(\mathbf{h}\) because free energy does not use hidden layer variables for computation, as shown in Equation (11). However, the negative phase term is intractable for both the energy function and free energy-constructed loss function because the visible variable \(\mathbf{v}\) is unobserved. It is impossible to find all the configurations over \((\mathbf{v},\mathbf{h})\) in the energy function or all possible \(\mathbf{v}\) in the free energy, which are utilized to compute the expectation of the negative phase term. To make the computation tractable, estimation is carried out using Gibbs sampling [29] in the RBMs as shown in Algorithm 1.