Radial basis function kernel

From HandWiki
Revision as of 23:12, 6 February 2024 by John Stpola (talk | contribs) (over-write)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Machine learning kernel function

In machine learning, the radial basis function kernel, or RBF kernel, is a popular kernel function used in various kernelized learning algorithms. In particular, it is commonly used in support vector machine classification.[1]

The RBF kernel on two samples [math]\displaystyle{ \mathbf{x}\in \mathbb{R}^{k} }[/math] and x', represented as feature vectors in some input space, is defined as[2]

[math]\displaystyle{ K(\mathbf{x}, \mathbf{x'}) = \exp\left(-\frac{\|\mathbf{x} - \mathbf{x'}\|^2}{2\sigma^2}\right) }[/math]

[math]\displaystyle{ \textstyle\|\mathbf{x} - \mathbf{x'}\|^2 }[/math] may be recognized as the squared Euclidean distance between the two feature vectors. [math]\displaystyle{ \sigma }[/math] is a free parameter. An equivalent definition involves a parameter [math]\displaystyle{ \textstyle\gamma = \tfrac{1}{2\sigma^2} }[/math]:

[math]\displaystyle{ K(\mathbf{x}, \mathbf{x'}) = \exp(-\gamma\|\mathbf{x} - \mathbf{x'}\|^2) }[/math]

Since the value of the RBF kernel decreases with distance and ranges between zero (in the infinite-distance limit) and one (when x = x'), it has a ready interpretation as a similarity measure.[2] The feature space of the kernel has an infinite number of dimensions; for [math]\displaystyle{ \sigma = 1 }[/math], its expansion using the multinomial theorem is:[3]

[math]\displaystyle{ \begin{alignat}{2} \exp\left(-\frac{1}{2}\|\mathbf{x} - \mathbf{x'}\|^2\right) &= \exp(\frac{2}{2}\mathbf{x}^\top \mathbf{x'} - \frac{1}{2}\|\mathbf{x}\|^2 - \frac{1}{2}\|\mathbf{x'}\|^2)\\ &= \exp(\mathbf{x}^\top \mathbf{x'}) \exp( - \frac{1}{2}\|\mathbf{x}\|^2) \exp( - \frac{1}{2}\|\mathbf{x'}\|^2) \\ &= \sum_{j=0}^\infty \frac{(\mathbf{x}^\top \mathbf{x'})^j}{j!} \exp\left(-\frac{1}{2}\|\mathbf{x}\|^2\right) \exp\left(-\frac{1}{2}\|\mathbf{x'}\|^2\right)\\ &= \sum_{j=0}^\infty \quad \sum_{n_1+n_2+\dots +n_k=j} \exp\left(-\frac{1}{2}\|\mathbf{x}\|^2\right) \frac{x_1^{n_1}\cdots x_k^{n_k} }{\sqrt{n_1! \cdots n_k! }} \exp\left(-\frac{1}{2}\|\mathbf{x'}\|^2\right) \frac{{x'}_1^{n_1}\cdots {x'}_k^{n_k} }{\sqrt{n_1! \cdots n_k! }} \\ &=\langle \varphi(\mathbf{x}), \varphi(\mathbf{x'}) \rangle \end{alignat} }[/math]
[math]\displaystyle{ \varphi(\mathbf{x}) = \exp\left(-\frac{1}{2}\|\mathbf{x}\|^2\right) \left(a^{(0)}_{l_0},a^{(1)}_1,\dots,a^{(1)}_{l_1},\dots,a^{(j)}_{1},\dots,a^{(j)}_{l_j},\dots \right ) }[/math]

where [math]\displaystyle{ l_j=\tbinom {k+j-1}{j} }[/math],

[math]\displaystyle{ a^{(j)}_{l}=\frac{x_1^{n_1}\cdots x_k^{n_k} }{\sqrt{n_1! \cdots n_k! }} \quad|\quad n_1+n_2+\dots+n_k = j \wedge 1\leq l\leq l_j }[/math]

Approximations

Because support vector machines and other models employing the kernel trick do not scale well to large numbers of training samples or large numbers of features in the input space, several approximations to the RBF kernel (and similar kernels) have been introduced.[4] Typically, these take the form of a function z that maps a single vector to a vector of higher dimensionality, approximating the kernel:

[math]\displaystyle{ \langle z(\mathbf{x}), z(\mathbf{x'}) \rangle \approx \langle \varphi(\mathbf{x}), \varphi(\mathbf{x'}) \rangle = K(\mathbf{x}, \mathbf{x'}) }[/math]

where [math]\displaystyle{ \textstyle\varphi }[/math] is the implicit mapping embedded in the RBF kernel.

Fourier random features

One way to construct such a z is to randomly sample from the Fourier transformation of the kernel[5][math]\displaystyle{ \varphi(x) = \frac{1}{\sqrt D}[\cos\langle w_1, x\rangle, \sin\langle w_1, x\rangle, \cdots \cos\langle w_D, x\rangle, \sin\langle w_D, x\rangle]^T }[/math]where [math]\displaystyle{ w_1, ..., w_D }[/math] are independent samples from the normal distribution [math]\displaystyle{ N(0, \sigma^{-2} I) }[/math].

Theorem: [math]\displaystyle{ \mathbb E[\langle \varphi(x), \varphi(y)\rangle] = e^{\frac{\|x-y\|^2}{2\sigma^2}} }[/math].

Proof: It suffices to prove the case of [math]\displaystyle{ D=1 }[/math]. Use the trigonometric identity [math]\displaystyle{ \cos(a-b) = \cos(a)\cos(b) + \sin(a)\sin(b) }[/math], the spherical symmetry of gaussian distribution, then evaluate the integral [math]\displaystyle{ \int_{-\infty}^{\infty} \frac{\cos (k x) e^{-x^2 / 2}}{\sqrt{2 \pi}} d x=e^{-k^2 / 2} }[/math].

Theorem: [math]\displaystyle{ Var[\langle \varphi(x), \varphi(y)\rangle] = O(D^{-1}) }[/math]. (Appendix A.2[6]).

Nyström method

Another approach uses the Nyström method to approximate the eigendecomposition of the Gram matrix K, using only a random sample of the training set.[7]

See also

References

  1. Chang, Yin-Wen; Hsieh, Cho-Jui; Chang, Kai-Wei; Ringgaard, Michael; Lin, Chih-Jen (2010). "Training and testing low-degree polynomial data mappings via linear SVM". Journal of Machine Learning Research 11: 1471–1490. http://jmlr.org/papers/v11/chang10a.html. 
  2. 2.0 2.1 Jean-Philippe Vert, Koji Tsuda, and Bernhard Schölkopf (2004). "A primer on kernel methods". Kernel Methods in Computational Biology.
  3. Shashua, Amnon (2009). "Introduction to Machine Learning: Class Notes 67577". arXiv:0904.3664v1 [cs.LG].
  4. Andreas Müller (2012). Kernel Approximations for Efficient SVMs (and other feature extraction methods).
  5. Rahimi, Ali; Recht, Benjamin (2007). "Random Features for Large-Scale Kernel Machines". Advances in Neural Information Processing Systems (Curran Associates, Inc.) 20. https://proceedings.neurips.cc/paper/2007/hash/013a006f03dbc5392effeb8f18fda755-Abstract.html. 
  6. Peng, Hao; Pappas, Nikolaos; Yogatama, Dani; Schwartz, Roy; Smith, Noah A.; Kong, Lingpeng (2021-03-19). "Random Feature Attention". arXiv:2103.02143 [cs.CL].
  7. C.K.I. Williams; M. Seeger (2001). "Using the Nyström method to speed up kernel machines". Advances in Neural Information Processing Systems 13. http://papers.nips.cc/paper/1866-using-the-nystrom-method-to-speed-up-kernel-machines.