1. 程式人生 > >為什麼高斯核函式對映到無窮維度?

為什麼高斯核函式對映到無窮維度?

Consider the polynomial kernel of degree 2 defined by, k(x, y) = (x^Ty)^2where x, y \in \mathbb{R}^2 and x = (x_1, x_2), y = (y_1, y_2).

Thereby, the kernel function can be written as, 
k(x, y) = (x_1y_1 + x_2y_2)^2
= x_{1}^2y_{1}^2 + 2x_1x_2y_1y_2 + x_{2}^2y_{2}^2
Now, let us try to come up with a feature map \Phi such that the kernel function can be written as k(x, y) = \Phi(x)^T\Phi(y).

Consider the following feature map, \Phi(x) = (x_1^2, \sqrt{2}x_1x_2, x_2^2). Basically, this feature map is mapping the points in 
\mathbb{R}^2 to points in \mathbb{R}^3. Also, notice that, \Phi(x)^T\Phi(y) = x_1^2y_1^2 + 2x_1x_2y_1y_2 + x_2^2y_2^2 which is essentially our kernel function.

This means that our kernel function is actually computing the inner/dot product of points in \mathbb{R}^3. That is, it is implicitly mapping our points from \mathbb{R}^2 to \mathbb{R}^3.

NOTE:我們要做的是將線性不可分的sample對映到高維空間(在這個空間中線性可分),然後在這個高維空間中衡量兩個sample之間的相似性,即做點積。在上述的多項式核函式例子中,闡述了通過核函式同樣可以達到我們的目的,而且省略了顯示對映的環節。


Now, coming to RBF.

Let us consider the RBF kernel again for points in \mathbb{R}^2. Then, the kernel can be written as 
k(x, y) = \exp(-\|x - y\|^2)
= \exp(- (x_1 - y_1)^2 - (x_2 - y_2)^2)
= \exp(- x_1^2 + 2x_1y_1 - y_1^2 - x_2^2 + 2x_2y_2 - y_2^2)
= \exp(-\|x\|^2) \exp(-\|y\|^2) \exp(2x^Ty)
(assuming gamma = 1). Using the taylor series you can write this as,
k(x, y) = \exp(-\|x\|^2) \exp(-\|y\|^2) \sum_{n = 0}^{\infty} \frac{(2x^Ty)^n}{n!}

Now, if we were to come up with a feature map \Phi just like we did for the polynomial kernel, you would realize that the feature map would map every point in our 

\mathbb{R}^2 to an infinite vector. Thus, RBF implicitly maps every point to an infinite dimensional space.

NOTE:上面是RBF核函式(也可以理解為高斯核函式),在上面的轉換過程中核函式最終通過傅立葉展開為無窮項,而每項都是一個多項式核函式,從這裡可以看出高斯核函式對映之後為什麼是無窮維的。

另外需要注意一點就是,無窮維的向量並不意味著對兩個無窮維的向量相似性的度量。點積是衡量兩個無窮維向量相似值最終收斂到的值!