Skip to content

Instantly share code, notes, and snippets.

@mckelvin
Created October 19, 2012 08:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mckelvin/3916965 to your computer and use it in GitHub Desktop.
Save mckelvin/3916965 to your computer and use it in GitHub Desktop.
an example to compute emd
# include <stdio.h>
# include <math.h>
# include "emd.h"
/* 欧几里得距离 */
float dist(feature_t *F1, feature_t *F2) {
int dX = F1->X - F2->X;
int dY = F1->Y - F2->Y;
int dZ = F1->Z - F2->Z;
return sqrt(dXdX + dY*dY + dZ*dZ);
}
int main() {
/* 分布P的特征矢量 */
feature_t f1[4] = { {100,40,22}, {211,20,2}, {32,190,150}, {2,100,100} };
/*分布Q的特征矢量 */
feature_t f2[3] = { {0,0,0}, {50,100,80}, {255,255,255} };
/*分布P的权重 */
float w1[5] = { 0.4, 0.3, 0.2, 0.1 };
/*分布Q的权重 */
float w2[3] = { 0.5, 0.3, 0.2 };
/*分布P的签名 */
signature_t s1 = { 4, f1, w1 };
/*分布Q的签名 */
signature_t s2 = { 3, f2, w2};
/* 计算EMD */
float e;
e = emd(&s1, &s2, dist, 0, 0);
printf("emd = %f\n", e); return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment