Chris@26
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@26
|
2
|
Chris@26
|
3 /*
|
Chris@26
|
4 Vamp feature extraction plugin using the MATCH audio alignment
|
Chris@26
|
5 algorithm.
|
Chris@26
|
6
|
Chris@26
|
7 Centre for Digital Music, Queen Mary, University of London.
|
Chris@26
|
8 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL.
|
Chris@26
|
9
|
Chris@26
|
10 This program is free software; you can redistribute it and/or
|
Chris@26
|
11 modify it under the terms of the GNU General Public License as
|
Chris@26
|
12 published by the Free Software Foundation; either version 2 of the
|
Chris@26
|
13 License, or (at your option) any later version. See the file
|
Chris@26
|
14 COPYING included with this distribution for more information.
|
Chris@26
|
15 */
|
Chris@26
|
16
|
Chris@26
|
17 #ifndef DISTANCE_METRIC_H
|
Chris@26
|
18 #define DISTANCE_METRIC_H
|
Chris@26
|
19
|
Chris@26
|
20 #include <vector>
|
Chris@26
|
21
|
Chris@26
|
22 class DistanceMetric
|
Chris@26
|
23 {
|
Chris@26
|
24 public:
|
Chris@156
|
25 enum Metric {
|
Chris@156
|
26
|
Chris@157
|
27 /** Calculate the Manhattan distance between feature
|
Chris@157
|
28 * vectors. If the vectors contain energy, as the default
|
Chris@157
|
29 * MATCH feature does, this could be considered as a squared
|
Chris@157
|
30 * Euclidean distance metric. */
|
Chris@157
|
31 Manhattan,
|
Chris@157
|
32
|
Chris@156
|
33 /** Calculate the Euclidean distance between feature vectors. */
|
Chris@156
|
34 Euclidean,
|
Chris@156
|
35
|
Chris@156
|
36 /** Calculate the cosine distance between feature vectors. The
|
Chris@156
|
37 * normalisation setting will be ignored as the result is
|
Chris@156
|
38 * already magnitude-independent. */
|
Chris@156
|
39 Cosine,
|
Chris@156
|
40 };
|
Chris@156
|
41
|
Chris@26
|
42 enum DistanceNormalisation {
|
Chris@26
|
43
|
Chris@26
|
44 /** Do not normalise distance metrics */
|
Chris@26
|
45 NoDistanceNormalisation,
|
Chris@26
|
46
|
Chris@26
|
47 /** Normalise distance metric for pairs of frames by the sum
|
Chris@26
|
48 * of the two frames. */
|
Chris@26
|
49 NormaliseDistanceToSum,
|
Chris@26
|
50
|
Chris@26
|
51 /** Normalise distance metric for pairs of frames by the log
|
Chris@26
|
52 * of the sum of the frames. */
|
Chris@26
|
53 NormaliseDistanceToLogSum,
|
Chris@26
|
54 };
|
Chris@156
|
55
|
Chris@150
|
56 enum NoiseAddition {
|
Chris@150
|
57
|
Chris@150
|
58 /** Don't add noise. */
|
Chris@150
|
59 NoNoise,
|
Chris@150
|
60
|
Chris@150
|
61 /** Add a constant noise term. This can help avoid
|
Chris@150
|
62 * mis-tracking when one file contains a lot of silence. */
|
Chris@150
|
63 AddNoise,
|
Chris@150
|
64 };
|
Chris@150
|
65
|
Chris@143
|
66 struct Parameters {
|
Chris@143
|
67
|
Chris@143
|
68 Parameters() :
|
Chris@157
|
69 metric(Manhattan),
|
Chris@150
|
70 norm(NormaliseDistanceToLogSum),
|
Chris@150
|
71 noise(AddNoise)
|
Chris@143
|
72 {}
|
Chris@143
|
73
|
Chris@156
|
74 Metric metric;
|
Chris@143
|
75 DistanceNormalisation norm;
|
Chris@150
|
76 NoiseAddition noise;
|
Chris@143
|
77 };
|
Chris@143
|
78
|
Chris@143
|
79 DistanceMetric(Parameters params);
|
Chris@26
|
80
|
Chris@157
|
81 /** Calculates the distance in some metric between two vectors,
|
Chris@157
|
82 * with an optional normalisation by the combined values in the
|
Chris@157
|
83 * vectors. Note that normalisation assumes the values are all
|
Chris@157
|
84 * non-negative.
|
Chris@26
|
85 *
|
Chris@26
|
86 * @param f1 one of the vectors involved in the distance calculation
|
Chris@26
|
87 * @param f2 one of the vectors involved in the distance calculation
|
Chris@26
|
88 * @return the distance
|
Chris@26
|
89 */
|
Chris@26
|
90 double calcDistance(const std::vector<double> &f1,
|
Chris@26
|
91 const std::vector<double> &f2);
|
Chris@26
|
92
|
Chris@26
|
93 private:
|
Chris@143
|
94 Parameters m_params;
|
Chris@26
|
95 };
|
Chris@26
|
96
|
Chris@26
|
97 #endif
|