1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2008 Kurt Jacobson.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
16 #include "CosineDistance.h"
23 double CosineDistance::distance(const vector
<double> &v1
,
24 const vector
<double> &v2
)
26 dist
= 1.0; dDenTot
= 0; dDen1
= 0; dDen2
= 0; dSum1
=0;
29 //check if v1, v2 same size
30 if (v1
.size() != v2
.size())
32 cerr
<< "CosineDistance::distance: ERROR: vectors not the same size\n";
37 for(int i
=0; i
<v1
.size(); i
++)
43 dDenTot
= sqrt(fabs(dDen1
*dDen2
)) + small
;
44 dist
= 1-((dSum1
)/dDenTot
);