核函数详解

这篇博文开始的例子就很好地揭示了核函数的简单原理,写得很好!

原地址:https://blog.csdn.net/zkq_1986/article/details/52448238算法

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.
就是这样!app

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

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

这里写图片描述

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

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.性能

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.学习

这里写图片描述

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) andatom

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.

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

  • 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 HHf=(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 .

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

这里写图片描述

这里写图片描述

2、现有的核函数统计以下:

1. Linear Kernel

线性核是最简单的核函数,核函数的数学公式以下:


若是咱们将线性核函数应用在KPCA中,咱们会发现,推导以后和原始PCA算法如出一辙,不少童鞋借此说“kernel is shit!!!”,这是不对的,这只是线性核函数偶尔会出现等价的形式罢了。

 

2. Polynomial Kernel

多项式核实一种非标准核函数,它很是适合于正交归一化后的数据,其具体形式以下:


这个核函数是比较好用的,就是参数比较多,可是还算稳定。

 

3. Gaussian Kernel

这里说一种经典的鲁棒径向基核,即高斯核函数,鲁棒径向基核对于数据中的噪音有着较好的抗干扰能力,其参数决定了函数做用范围,超过了这个范围,数据的做用就“基本消失”。高斯核函数是这一族核函数的优秀表明,也是必须尝试的核函数,其数学形式以下:


虽然被普遍使用,可是这个核函数的性能对参数十分敏感,以致于有一大把的文献专门对这种核函数展开研究,一样,高斯核函数也有了不少的变种,如指数核,拉普拉斯核等。

4. Exponential Kernel

      指数核函数就是高斯核函数的变种,它仅仅是将向量之间的L2距离调整为L1距离,这样改动会对参数的依赖性下降,可是适用范围相对狭窄。其数学形式以下:


5. Laplacian Kernel

      拉普拉斯核彻底等价于指数核,惟一的区别在于前者对参数的敏感性下降,也是一种径向基核函数。


6. ANOVA Kernel

      ANOVA 核也属于径向基核函数一族,其适用于多维回归问题,数学形式以下:


7. Sigmoid Kernel

Sigmoid 核来源于神经网络,如今已经大量应用于深度学习,是当今机器学习的宠儿,它是S型的,因此被用做于“激活函数”。关于这个函数的性质能够说好几篇文献,你们能够随便找一篇深度学习的文章看看。


8. Rational Quadratic Kernel

      二次有理核完彻底全是做为高斯核的替代品出现,若是你以为高斯核函数很耗时,那么不妨尝试一下这个核函数,顺便说一下,这个核函数做用域虽广,可是对参数十分敏感,慎用!!!!


9. Multiquadric Kernel

      多元二次核能够替代二次有理核,它是一种非正定核函数。


10. Inverse Multiquadric Kernel

      顾名思义,逆多元二次核来源于多元二次核,这个核函数我没有用过,可是听说这个基于这个核函数的算法,不会遇到核相关矩阵奇异的状况。


11. Circular Kernel

      这个核函数没有用过,其数学形式以下所示:


12. Spherical Kernel

      这个核函数是上一个的简化版,形式以下所示


13. Wave Kernel

      这个核函数没有用过,其适用于语音处理场景。


14. Triangular  Kernel

三角核函数感受就是多元二次核的特例,数学公式以下:


15. Log Kernel

      对数核通常在图像分割上常常被使用,数学形式以下:


16. Spline Kernel


17. Bessel Kernel


18. Cauchy Kernel

      柯西核来源于神奇的柯西分布,与柯西分布类似,函数曲线上有一个长长的尾巴,说明这个核函数的定义域很普遍,言外之意,其可应用于原始维度很高的数据上。


19. Chi-Square Kernel

      卡方核,这是我最近在使用的核函数,让我欲哭无泪,在多个数据集上都没有用,居然比原始算法还要差劲,不知道为何文献做者首推这个核函数,其来源于卡方分布,数学形式以下:


它存在着以下变种:


其实就是上式减去一项获得的产物,这个核函数基于的特征不可以带有赋值,不然性能会急剧降低,若是特征有负数,那么就用下面这个形式:


20. Histogram Intersection Kernel

      直方图交叉核在图像分类里面常常用到,好比说人脸识别,适用于图像的直方图特征,例如extended LBP特征其数学形式以下,形式很是的简单


21. Generalized Histogram Intersection

     顾名思义,广义直方图交叉核就是上述核函数的拓展,形式以下:


22. Generalized T-Student Kernel

      TS核属于mercer核,其数学形式以下,这个核也是常常被使用的


23. Bayesian Kernel

贝叶斯核函数尚未用到过。




参考文献: 
[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/