source: cpp/frams/model/similarity/EMD/emd.h @ 1139

Last change on this file since 1139 was 1064, checked in by Maciej Komosinski, 4 years ago

Properly allocated and de-allocated dynamic arrays of size calculated in runtime, not relying on g++ "extension"

File size: 1.8 KB
Line 
1#ifndef _EMD_H
2#define _EMD_H
3/*
4    emd.h
5
6    Last update: 3/24/98 (but see below for newer changes)
7
8    An implementation of the Earth Movers Distance.
9    Based of the solution for the Transportation problem as described in
10    "Introduction to Mathematical Programming" by F. S. Hillier and
11    G. J. Lieberman, McGraw-Hill, 1990.
12
13    Copyright (C) 1998 Yossi Rubner
14    Computer Science Department, Stanford University
15    E-Mail: rubner@cs.stanford.edu   URL: http://robotics.stanford.edu/~rubner/emd/default.htm
16*/
17
18// List of changes since 2020, compared to the original implementation:
19// r1050: Renamed variables that caused problems with g++ 7.3.0
20// r1062: Global static arrays moved to a function and now allocated dynamically; removed #defined limit of MAX_SIG_SIZE=1000
21
22
23/* DEFINITIONS */
24#define MAX_ITERATIONS 500
25//#define INFINITY       1e20
26#define EPSILON        1e-6
27
28/*****************************************************************************/
29/* feature_t SHOULD BE MODIFIED BY THE USER TO REFLECT THE FEATURE TYPE      */
30//typedef struct {
31//   double X,Y,Z;
32//}
33typedef double feature_t;
34/*****************************************************************************/
35
36
37typedef struct
38{
39  int n;                /* Number of features in the signature */
40  feature_t *Features;  /* Pointer to the features vector */
41  float *Weights;       /* Pointer to the weights of the features */
42} signature_t;
43
44
45typedef struct
46{
47  int from;             /* Feature number in signature 1 */
48  int to;               /* Feature number in signature 2 */
49  float amount;         /* Amount of flow from "from" to "to" */
50} flow_t;
51
52
53
54float emd(signature_t *Signature1, signature_t *Signature2,
55          float (*func)(feature_t *, feature_t *),
56          flow_t *Flow, int *FlowSize);
57
58#endif
Note: See TracBrowser for help on using the repository browser.