首先说一下距离三要素:
1)非负性;2)对称性;3)三角不等式。(PS:有些距离并不能同时满足)
集中一下都有啥距离:
L1距离,L2距离(欧式距离),L∞距离,欧氏距离平方(squared Euclidean distance),intersection distance, Kullback-Leibler(K-L)距离,Jeffrey距离,χ2距离,巴氏距离,Consine距离,quadratic-form(QF)距离,match距离,Kolmogorov-Smirnov(K-S)距离,earth mover distance(EMD), fast earth mover distance (Fast EMD),quadratic-chi 距离, diffusion距离(以上摘录自小木虫论坛的作者zhouweiji的提问,计算直方图距离) ,另外还有街区距离,棋盘距离
已知 n维向量X,Y(有些语言上好表达的,就不上公式了)
对 范数L1 :各个元素的绝对值和; L2:各元素平方和;L0:非零元素个数;
Lp范数定义如下:
欧氏距离
度量两个向量之间的距离
Hellinger距离
度量两个分布之间的相似度
the Hellinger distance (also called Bhattacharyya distance as this was originally introduced by Anil Kumar Bhattacharya) is used to quantify the similarity between two probability distributions. 【个人觉得这里说的不是很对,Hellinger distance 和Bhattacharyya coefficient是一回事,但Bhattacharyya distance则是在该距离的基础上做了对数变换】
Hellinger距离其实就是向量值开根号,然后,在求欧式距离
巴氏距离
度量两个分布之间的相似度
the Bhattacharyya distance measures the similarity of two discrete or continuous probability distributions.
It is closely related to the Bhattacharyya coefficient which is a measure of the amount of overlap between two statistical samples or populations
巴氏距离即Hellinger距离求-ln
马氏距离
度量点到分布的距离
The Mahalanobis distance is a measure of the distance between a point P and a distribution D, introduced by P. C. Mahalanobis in 1936.
KL 距离(Kullback–Leibler divergence)
度量两个分布之间的距离
KL距离不具有对称性,即P到Q的距离,不一定等于Q到P的距离
http://en.wikipedia.org/wiki/Kullback–Leibler_divergence
卡方距离(chi square distance)
多用于直方图比较
其中的期望频数是这样计算的:
一. 概念
KL-divergence,俗称KL距离,常用来衡量两个概率分布的距离。
根据shannon的信息论,给定一个字符集的概率分布,我们可以设计一种编码,使得表示该字符集组成的字符串平均需要的比特数最少。假设这个字符集是X,对x∈X,其出现概率为P(x),那么其最优编码平均需要的比特数等于这个字符集的熵:
H(X)=∑x∈XP(x)log[1/P(x)]
在同样的字符集上,假设存在另一个概率分布Q(X)。如果用概率分布P(X)的最优编码(即字符x的编码长度等于log[1/P(x)]),来为符合分布Q(X)的字符编码,那么表示这些字符就会比理想情况多用一些比特数。KL-divergence就是用来衡量这种情况下平均每个字符多用的比特数,因此可以用来衡量两个分布的距离。即:
DKL(Q||P)=∑x∈XQ(x)[log(1/P(x))] - ∑x∈XQ(x)[log[1/Q(x)]]=∑x∈XQ(x)log[Q(x)/P(x)]
由于-log(u)是凸函数,因此有下面的不等式
DKL(Q||P) = -∑x∈XQ(x)log[P(x)/Q(x)] = E[-logP(x)/Q(x)] ≥ -logE[P(x)/Q(x)] = -log∑x∈XQ(x)P(x)/Q(x) = 0
即KL-divergence始终是大于等于0的。当且仅当两分布相同时,KL-divergence等于0。
二. 例子
下面举一个实际的例子吧:比如有四个类别,一个方法A得到四个类别的概率分别是0.1,0.2,0.3,0.4。另一种方法B(或者说是事实情况)是得到四个类别的概率分别是0.4,0.3,0.2,0.1,那么这两个分布的KL-Distance(A,B)=0.1*log(0.1/0.4)+0.2*log(0.2/0.3)+0.3*log(0.3/0.2)+0.4*log(0.4/0.1)
这个里面有正的,有负的,可以证明KL-Distance()>=0.
从上面可以看出, KL散度是不对称的。即KL-Distance(A,B)!=KL-Distance(B,A)
KL散度是不对称的,当然,如果希望把它变对称,
Ds(p1, p2) = [D(p1, p2) + D(p2, p1)] / 2