annotate maths/CosineDistance.cpp @ 209:ccd2019190bf msvc

Some MSVC fixes, including (temporarily, probably) renaming the FFT source file to avoid getting it mixed up with the Vamp SDK one in our object dir
author Chris Cannam
date Thu, 01 Feb 2018 16:34:08 +0000
parents e4a57215ddee
children bb78ca3fe7de
rev   line source
cannam@31 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@31 2
cannam@31 3 /*
cannam@31 4 QM DSP Library
cannam@31 5
cannam@31 6 Centre for Digital Music, Queen Mary, University of London.
cannam@31 7 This file copyright 2008 Kurt Jacobson.
Chris@84 8
Chris@84 9 This program is free software; you can redistribute it and/or
Chris@84 10 modify it under the terms of the GNU General Public License as
Chris@84 11 published by the Free Software Foundation; either version 2 of the
Chris@84 12 License, or (at your option) any later version. See the file
Chris@84 13 COPYING included with this distribution for more information.
cannam@31 14 */
cannam@31 15
cannam@31 16 #include "CosineDistance.h"
cannam@31 17
cannam@31 18 #include <iostream>
cannam@31 19 #include <limits>
cannam@31 20
cannam@31 21 using std::cerr;
cannam@31 22
cannam@31 23 double CosineDistance::distance(const vector<double> &v1,
cannam@31 24 const vector<double> &v2)
cannam@31 25 {
cannam@31 26 dist = 1.0; dDenTot = 0; dDen1 = 0; dDen2 = 0; dSum1 =0;
cannam@74 27 double small = 1e-20;
cannam@31 28
cannam@31 29 //check if v1, v2 same size
cannam@31 30 if (v1.size() != v2.size())
cannam@31 31 {
cannam@31 32 cerr << "CosineDistance::distance: ERROR: vectors not the same size\n";
cannam@31 33 return 1.0;
cannam@31 34 }
cannam@31 35 else
cannam@31 36 {
Chris@189 37 for(int i=0; i<int(v1.size()); i++)
cannam@31 38 {
cannam@31 39 dSum1 += v1[i]*v2[i];
cannam@31 40 dDen1 += v1[i]*v1[i];
cannam@31 41 dDen2 += v2[i]*v2[i];
cannam@31 42 }
cannam@74 43 dDenTot = sqrt(fabs(dDen1*dDen2)) + small;
cannam@31 44 dist = 1-((dSum1)/dDenTot);
cannam@31 45 return dist;
cannam@31 46 }
cannam@31 47 }