转自:http://www.sigvc.org/bbs/forum.php?mod=viewthread&tid=981

Earth Mover's Distance (EMD)
原文: http://d.hatena.ne.jp/aidiary/20120804/1344058475
作者: sylvan5
翻译: Myautsai和他的朋友们(Google Translate、shuanger、qiu)


本文将讨论Earth Mover’s Distance (EMD),和欧式距离一样,它们都是一种距离度量的定义、可以用来测量某两个分布之间的距离。EMD主要应用在图像处理和语音信号处理领域,在自然语言处理上很少有听说。
EMD 问题如下图所示
<ignore_js_op> 
Rubner的C语言实现首先我们尝试使用Rubner桑公开的C语言代码(example1.c),编译依赖emd.c和emd.h。其中特征量类型feature_t在emd.h中定义如下:
typedef struct { int X,Y,Z; } feature_t;具体实现代码见emd.c。对于上述例子的解答如下:

普通浏览复制代码
  1. [转]Earth Mover's Distance (EMD)# include <stdio.h>
  2. [转]Earth Mover's Distance (EMD)# include <math.h>
  3. [转]Earth Mover's Distance (EMD)# include "emd.h"
  4. [转]Earth Mover's Distance (EMD)
  5. [转]Earth Mover's Distance (EMD)/* 欧几里得距离 */
  6. [转]Earth Mover's Distance (EMD)float dist(feature_t *F1, feature_t *F2) {
  7. [转]Earth Mover's Distance (EMD)    int dX = F1->X - F2->X;
  8. [转]Earth Mover's Distance (EMD)    int dY = F1->Y - F2->Y;
  9. [转]Earth Mover's Distance (EMD)    int dZ = F1->Z - F2->Z;
  10. [转]Earth Mover's Distance (EMD)    return sqrt(dXdX + dY*dY + dZ*dZ);
  11. [转]Earth Mover's Distance (EMD)}
  12. [转]Earth Mover's Distance (EMD)
  13. [转]Earth Mover's Distance (EMD)int main() {
  14. [转]Earth Mover's Distance (EMD)
  15. [转]Earth Mover's Distance (EMD)    /* 分布P的特征矢量 */
  16. [转]Earth Mover's Distance (EMD)    feature_t f1[4] = { {100,40,22}, {211,20,2}, {32,190,150}, {2,100,100} };
  17. [转]Earth Mover's Distance (EMD)    /*分布Q的特征矢量 */
  18. [转]Earth Mover's Distance (EMD)    feature_t f2[3] = { {0,0,0}, {50,100,80}, {255,255,255} };
  19. [转]Earth Mover's Distance (EMD)    /*分布P的权重 */
  20. [转]Earth Mover's Distance (EMD)    float w1[5] = { 0.40.30.20.1 };
  21. [转]Earth Mover's Distance (EMD)    /*分布Q的权重 */
  22. [转]Earth Mover's Distance (EMD)    float w2[3] = { 0.50.30.2 };
  23. [转]Earth Mover's Distance (EMD)    /*分布P的签名 */
  24. [转]Earth Mover's Distance (EMD)    signature_t s1 = { 4, f1, w1 };
  25. [转]Earth Mover's Distance (EMD)    /*分布Q的签名 */
  26. [转]Earth Mover's Distance (EMD)    signature_t s2 = { 3, f2, w2};
  27. [转]Earth Mover's Distance (EMD)    /* 计算EMD */ 
  28. [转]Earth Mover's Distance (EMD)    float e; 
  29. [转]Earth Mover's Distance (EMD)    e = emd(&s1&s2, dist, 00); 
  30. [转]Earth Mover's Distance (EMD)    printf("emd = %f\n", e); return 0; 
  31. [转]Earth Mover's Distance (EMD)
  32. [转]Earth Mover's Distance (EMD)}



<ignore_js_op> 
结束语本文对与EMD的讨论力求准确,但是错误难免,敬请批评指正,同时请参考其他文献。
参考文献

  • Earth mover’s distance - Wikipedia link
  • Y. Rubner, C. Tomasi and L. J. Guibas: The earth mover’s distance as a metric for image retrieval (PDF), International Journal of Computer Vision, 40(2), pp.99-121, 2000 - EMDの原論文。EMDを類似画像検索に適用しています。
  • Code for the Earth Movers Distance (EMD) - Rubnerさんが公開されているC言語実装 link
  • Fast Earth Mover’s Distance (EMD) Code - EMDを高速計算する実装 link
  • 柳本, 大松: Earth Mover’s Distanceを用いたテキスト分類、人工知能学会全国大会, 2007. - EMDの説明がわかりやすい。画像や音声の手法がテキストにも使えるんですね。
  • lpSolve - R言語のlpSolveのマニュアル。lp.transform()の詳しい仕様はここで。
  • Formal definition of EMD

this article is mainly based on the original text written by sylvan5 on aidiary.some additional contents are added by mckelvin.
本文主要基于sylvan5发表在aidiary的原文,在此基础上增加了一些内容。

相关文章: