# HG changeset patch # User Chris Cannam # Date 1422528924 0 # Node ID d6c1556fadd0189df1fed2355242c68273196358 # Parent d6df9fe7b12fe5d027dcf66ea1e849eed160ee61 Default is actually Manhattan, not Euclidean (it just looks like squared-Euclidean for energy vectors). Add Euclidean as another alternative. diff -r d6df9fe7b12f -r d6c1556fadd0 src/DistanceMetric.cpp --- a/src/DistanceMetric.cpp Thu Jan 29 10:25:47 2015 +0000 +++ b/src/DistanceMetric.cpp Thu Jan 29 10:55:24 2015 +0000 @@ -62,13 +62,21 @@ if (d > 1.0) d = 1.0; return d; // normalisation param ignored + } - // Euclidean - - for (int i = 0; i < featureSize; i++) { - d += fabs(f1[i] - f2[i]); - sum += fabs(f1[i]) + fabs(f2[i]); + if (m_params.metric == Manhattan) { + for (int i = 0; i < featureSize; i++) { + d += fabs(f1[i] - f2[i]); + sum += fabs(f1[i]) + fabs(f2[i]); + } + } else { + // Euclidean + for (int i = 0; i < featureSize; i++) { + d += (f1[i] - f2[i]) * (f1[i] - f2[i]); + sum += fabs(f1[i]) + fabs(f2[i]); + } + d = sqrt(d); } double noise = 1e-3 * featureSize; diff -r d6df9fe7b12f -r d6c1556fadd0 src/DistanceMetric.h --- a/src/DistanceMetric.h Thu Jan 29 10:25:47 2015 +0000 +++ b/src/DistanceMetric.h Thu Jan 29 10:55:24 2015 +0000 @@ -24,6 +24,12 @@ public: enum Metric { + /** Calculate the Manhattan distance between feature + * vectors. If the vectors contain energy, as the default + * MATCH feature does, this could be considered as a squared + * Euclidean distance metric. */ + Manhattan, + /** Calculate the Euclidean distance between feature vectors. */ Euclidean, @@ -60,7 +66,7 @@ struct Parameters { Parameters() : - metric(Euclidean), + metric(Manhattan), norm(NormaliseDistanceToLogSum), noise(AddNoise) {} @@ -72,11 +78,10 @@ DistanceMetric(Parameters params); - /** Calculates the Manhattan distance between two vectors, with an - * optional normalisation by the combined values in the - * vectors. Since the vectors contain energy, this could be - * considered as a squared Euclidean distance metric. Note that - * normalisation assumes the values are all non-negative. + /** Calculates the distance in some metric between two vectors, + * with an optional normalisation by the combined values in the + * vectors. Note that normalisation assumes the values are all + * non-negative. * * @param f1 one of the vectors involved in the distance calculation * @param f2 one of the vectors involved in the distance calculation diff -r d6df9fe7b12f -r d6c1556fadd0 src/MatchVampPlugin.cpp --- a/src/MatchVampPlugin.cpp Thu Jan 29 10:25:47 2015 +0000 +++ b/src/MatchVampPlugin.cpp Thu Jan 29 10:55:24 2015 +0000 @@ -219,11 +219,12 @@ desc.name = "Distance metric"; desc.description = "Metric for distance calculations."; desc.minValue = 0; - desc.maxValue = 1; + desc.maxValue = 2; desc.defaultValue = (int)m_defaultDParams.metric; desc.isQuantized = true; desc.quantizeStep = 1; desc.valueNames.clear(); + desc.valueNames.push_back("Manhattan"); desc.valueNames.push_back("Euclidean"); desc.valueNames.push_back("Cosine"); list.push_back(desc);