Mercurial > hg > match-vamp
changeset 157:d6c1556fadd0 refactors
Default is actually Manhattan, not Euclidean (it just looks like squared-Euclidean for energy vectors). Add Euclidean as another alternative.
author | Chris Cannam |
---|---|
date | Thu, 29 Jan 2015 10:55:24 +0000 |
parents | d6df9fe7b12f |
children | d6cdbd814c8c cdbee79699b0 |
files | src/DistanceMetric.cpp src/DistanceMetric.h src/MatchVampPlugin.cpp |
diffstat | 3 files changed, 26 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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
--- 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);