annotate src/DistanceMetric.h @ 145:ecfb4ada171b noise

Add a constant value (representing "noise") to each distance and sum
author Chris Cannam
date Fri, 16 Jan 2015 16:43:56 +0000
parents 254e16f831ee
children b79151bb75af
rev   line source
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@26 25 enum DistanceNormalisation {
Chris@26 26
Chris@26 27 /** Do not normalise distance metrics */
Chris@26 28 NoDistanceNormalisation,
Chris@26 29
Chris@26 30 /** Normalise distance metric for pairs of frames by the sum
Chris@26 31 * of the two frames. */
Chris@26 32 NormaliseDistanceToSum,
Chris@26 33
Chris@26 34 /** Normalise distance metric for pairs of frames by the log
Chris@26 35 * of the sum of the frames. */
Chris@26 36 NormaliseDistanceToLogSum,
Chris@26 37 };
Chris@26 38
Chris@143 39 struct Parameters {
Chris@143 40
Chris@143 41 Parameters() :
Chris@144 42 norm(NormaliseDistanceToLogSum)
Chris@143 43 {}
Chris@143 44
Chris@143 45 /** Normalisation for distance metrics. */
Chris@143 46 DistanceNormalisation norm;
Chris@143 47 };
Chris@143 48
Chris@143 49 DistanceMetric(Parameters params);
Chris@26 50
Chris@26 51 /** Calculates the Manhattan distance between two vectors, with an
Chris@26 52 * optional normalisation by the combined values in the
Chris@26 53 * vectors. Since the vectors contain energy, this could be
Chris@26 54 * considered as a squared Euclidean distance metric. Note that
Chris@26 55 * normalisation assumes the values are all non-negative.
Chris@26 56 *
Chris@26 57 * @param f1 one of the vectors involved in the distance calculation
Chris@26 58 * @param f2 one of the vectors involved in the distance calculation
Chris@26 59 * @return the distance
Chris@26 60 */
Chris@26 61 double calcDistance(const std::vector<double> &f1,
Chris@26 62 const std::vector<double> &f2);
Chris@26 63
Chris@26 64 private:
Chris@143 65 Parameters m_params;
Chris@26 66 };
Chris@26 67
Chris@26 68 #endif