[转]核函数K(kernel function)

1 核函数K(kernel function)定义

核函数K(kernel function)就是指K(x, y) = <f(x), f(y)>,其中x和y是n维的输入值,f(·) 是从n维到m维的映射(一般,m>>n)。<x, y>是x和y的内积(inner product)(也称点积(dot product))。算法

举个小小栗子。
令 x = (x1, x2, x3, x4); y = (y1, y2, y3, y4);
令 f(x) = (x1x1, x1x2, x1x3, x1x4, x2x1, x2x2, x2x3, x2x4, x3x1, x3x2, x3x3, x3x4, x4x1, x4x2, x4x3, x4x4); f(y)亦然;
令核函数 K(x, y) = (<x, y>)^2.
接下来,让咱们带几个简单的数字进去看看是个什么效果:x = (1, 2, 3, 4); y = (5, 6, 7, 8). 那么:
f(x) = ( 1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16) ;
f(y) = (25, 30, 35, 40, 30, 36, 42, 48, 35, 42, 49, 56, 40, 48, 56, 64) ;
<f(x), f(y)> = 25+60+105+160+60+144+252+384+105+252+441+672+160+384+672+1024
= 4900.
若是咱们用核函数呢?
K(x, y) = (5+12+21+32)^2 = 70^2 = 4900.
就是这样!机器学习

因此如今你看出来了吧,kernel其实就是帮咱们省去在高维空间里进行繁琐计算的“简便运算法”。甚至,它能解决无限维空间没法计算的问题!由于有时f(·)会把n维空间映射到无限维空间去。函数

那么kernel在SVM究竟扮演着什么角色?
初学SVM时经常可能对kernel有一个误读,那就是误觉得是kernel使得低维空间的点投射到高位空间后实现了线性可分。其实否则。这是把kernel和feature space transformation混为了一谈。(这个错误其实很蠢,只要你把SVM从头至尾认真推导一遍就不会犯我这个错。)post

这里写图片描述

这里写图片描述
咱们成功地找到了那个分界线,这就是最直观的kernel啦!
可能不太严谨,可是kernel大概就是这个意思,详细的数学定义楼上说的很好,就不赘述了。
引用一句这门课的教授的话:
“你在你的一辈子中可能会经历不少变故,可能会变成彻底不一样的另外一我的,可是这个世界上只有一个你,我要怎样才能把不一样的“你”分开呢?最直观的方法就是增长“时间”这个维度,虽然这个地球上只有一个你,这个你是不可分割的,可是“昨天在中国的你”和“今天在美国的你”在时间+空间这个维度倒是能够被分割的。”学习

We know that everything in the world can be decomposed into the combination of the basic elements. For example, water is the combination of hydrogen and oxygen. Similarly, in mathematics, basis is used to represent various things in a simple and unified way.atom

In RnRn space, we can use n independent vectors to represent any vector by linear combination. The n independent vectors can be viewed as a set of basis. There are infinite basis sets in RnRn space. Among them, basis vectors that are orthogonal to each other are of special interests. For example, {ei}ni=1{ei}i=1n is a special basis set with mutually orthogonal basis vectors in the same length, where eiei is a vector that has all zero entries except the iith entry which equals 1.
The inner product operator measures the similarity between vectors. For two vectors x and y , the inner product is the projection of one vector to the other.
spa

这里写图片描述

3. Kernel Function

A function f(x)f(x) can be viewed as an infinite vector, then for a function with two independent variables K(x,y)K(x,y) , we can view it as an infinite matrix. Among them, if K(x,y)=K(y,x)K(x,y)=K(y,x) and .net

 
f(x)K(x,y)f(y)dxdy0∫∫f(x)K(x,y)f(y)dxdy≥0

for any function ff , then K(x,y)K(x,y) is symmetric and positive definite, in which case K(x,y)K(x,y) is a kernel function.rest

 

这里写图片描述
这里写图片描述
Here are some commonly used kernels:orm

  • Polynomial kernel K(x,y)=(γxTy+C)dK(x,y)=(γxTy+C)d
  • Gaussian radial basis kernel K(x,y)=exp(γxy2)K(x,y)=exp⁡(−γ‖x−y‖2)
  • Sigmoid kernel K(x,y)=tanh(γxTy+C)K(x,y)=tanh⁡(γxTy+C)

3.1 补充知识

The hyperbolic functions are:

  • Hyperbolic sine:
     
    sinhx=exex2=e2x12ex=1e2x2ex.sinh⁡x=ex−e−x2=e2x−12ex=1−e−2x2e−x.

  • Hyperbolic cosine:
     
    coshx=ex+ex2=e2x+12ex=1+e2x2ex.cosh⁡x=ex+e−x2=e2x+12ex=1+e−2x2e−x.

  • Hyperbolic tangent:
     
    tanhx=sinhxcoshx=exexex+ex=1e2x1+e2x.tanh⁡x=sinh⁡xcosh⁡x=ex−e−xex+e−x=1−e−2x1+e−2x.

 

4. Reproducing Kernel Hilbert Space

Treat {λi−−√ψi}i=1{λiψi}i=1∞ as a set of orthogonal basis and construct a Hilbert space HH . Any function or vector in the space can be represented as the linear combination of the basis. Suppose f=i=1fiλi−−√ψif=∑i=1∞fiλiψi we can denote ff as an infinite vector in HH : f=(f1,f2,...)THf=(f1,f2,...)HT For another function g=(g1,g2,...)THg=(g1,g2,...)HT , we have

< f,g > H=i=1figiH=∑i=1∞figi

 

这里写图片描述
这里写图片描述

5. A Simple Example

这里写图片描述

6 .

线性核函数
这里写图片描述

这里写图片描述

这里写图片描述




参考文献:
[1] 机器学习里的kernel是指什么? - 算法 - 知乎. http://www.zhihu.com/question/30371867 [2016-9-6]
[2] http://songcy.net/posts/story-of-basis-and-kernel-part-1/
[3] http://songcy.net/posts/story-of-basis-and-kernel-part-2/

相关文章
相关标签/搜索