# Learning Kernel Stein Discrepancy for Training Energy-Based Models
## 4 Learning the Kernel Stein Discrepancy of Energy-Based Models  
In the above section, we introduced two methods of hypothesis testing. MMD has been widely used in various unnormalized models [32; 33]. But, due to the need to estimate the theoretical density distribution of \(q\), KSD's use in unnormalized models is extremely limited, only applied in the mixed Gaussian model [34]. In this article, we propose an algorithm for solving Problem 1 by using Kernel Stein Discrepancy to train unnormalized density models. The bottleneck of measuring KSD as the explicit density estimation of \(q\) is unsuspected. In [35], two generative models were proposed for mutual calibration between the explicit and implicit generative model. The difference between explicit energy-based models and the implicit generative model is measured through the Stein discrepancy. But, its objective function includes three kinds of statistical distances, which increases the complexity of the calculation. And, in the experimental part, no experimental results on likelihood inference are given. Inspired by [35] and the right-hand side of the third equation in Formula (2), it is convenient to obtain the explicit Gibb distribution of samples in explicit energy-based models. Enlightened by this, we replaced \(s_{q}\big{(}y_{j}\big{)}\) in Formula (10) with \(-\
abla_{y}e(y_{j})\). The Kernelized Stein Discrepancy of energy-based models is defined as follows:  
\[ \begin{split}\text{KSD}_{e}(q,p)&=E_{p}[u_{q}(y,y ^{\prime})]\\ u_{q}(y,y^{\prime})&=\Big{[}\
abla_{y_{j}}e(y_{j}) \Big{]}^{T}k\Big{(}y_{j},y_{j}^{\prime}\Big{)}\
abla_{y_{j}}e(y_{j})-\Big{[} \
abla_{y_{j}}e(y_{j})\Big{]}^{T}\
abla_{y_{j}^{\prime}}k\Big{(}y_{j},y_{j}^{ \prime}\Big{)}\\ &\quad-\
abla_{y_{j}}k\Big{(}y_{j},y_{j}^{\prime}\Big{)}\
abla_ {y_{j}^{\prime}}e\Big{(}y_{j}^{\prime}\Big{)}+trace\Big{(}\
abla_{y_{j},y_{j }^{\prime}}k\Big{(}y_{j},y_{j}^{\prime}\Big{)}\Big{)}\end{split}  \tag{14}\]  
In the above formula, the explicit density estimation of \(q\) is limited to the Gibb distribution of the energy-based model. And, \(e\) is the energy value of input samples. Although designing the energy function \(e\) is unconstrained, it is hard to find the right energy function for unknown density distribution. Because we know nothing about the distribution of given samples, we have to look for the right energy function \(e\) within a larger function range. In the vast majority of cases, a deep neural network is selected as the energy function, attributed to its strong nonlinear fitting ability and large value range. So, our model also selects a deep energy network as the energy function \(e\). \(k\left(y_{j},\ y_{j}^{\prime}\right)\) in Formula (14) is a strictly positive definite kernel, which maps input samples to the Reproducing Kernel Hilbert Space and returns their inner product. The choice of kernel function for high-dimensional data is always a difficult issue. Different kernel functions map input samples to different feature spaces, and sample features and their inner product values vary accordingly. Here, we select the RBF (Radial Basis Function) as the kernel function, also known as the Gaussian kernel function. The RBF kernel function is defined as follows:  
\[k\big{(}x,x^{\prime}\big{)}=\exp\biggl{(}-\frac{1}{2\sigma^{2}}\big{\|}x-x^{ \prime}\big{\|}^{2}\biggr{)} \tag{15}\]  
The RBF kernel meets the conditions we described in Lemma 2 and has a continuous second-order partial derivative. Hyperparameter \(\sigma\) needs to be set manually. The RBF kernel maps samples to infinite dimensional space, has fewer parameters, and has simple model complexity. Therefore, it is selected as the kernel function to be used in various application scenarios. Then, we can obtain the kernel matrix of input samples by calculatingthe RBF kernel function.