1031 |
04 Feb 08 |
markus |
1 |
#ifndef theplu_yat_statistics_euclidean_distance_h |
1031 |
04 Feb 08 |
markus |
2 |
#define theplu_yat_statistics_euclidean_distance_h |
889 |
25 Sep 07 |
markus |
3 |
|
889 |
25 Sep 07 |
markus |
// $Id$ |
889 |
25 Sep 07 |
markus |
5 |
|
999 |
23 Dec 07 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér |
3550 |
03 Jan 17 |
peter |
Copyright (C) 2010, 2016 Peter Johansson |
999 |
23 Dec 07 |
jari |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
999 |
23 Dec 07 |
jari |
11 |
|
999 |
23 Dec 07 |
jari |
The yat library is free software; you can redistribute it and/or |
999 |
23 Dec 07 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
999 |
23 Dec 07 |
jari |
License, or (at your option) any later version. |
999 |
23 Dec 07 |
jari |
16 |
|
999 |
23 Dec 07 |
jari |
The yat library is distributed in the hope that it will be useful, |
999 |
23 Dec 07 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
999 |
23 Dec 07 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
999 |
23 Dec 07 |
jari |
General Public License for more details. |
999 |
23 Dec 07 |
jari |
21 |
|
999 |
23 Dec 07 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
999 |
23 Dec 07 |
jari |
24 |
*/ |
999 |
23 Dec 07 |
jari |
25 |
|
889 |
25 Sep 07 |
markus |
26 |
#include "AveragerPair.h" |
890 |
25 Sep 07 |
markus |
27 |
#include "AveragerPairWeighted.h" |
3534 |
21 Dec 16 |
peter |
28 |
#include "Distance.h" |
889 |
25 Sep 07 |
markus |
29 |
|
889 |
25 Sep 07 |
markus |
30 |
#include <cmath> |
889 |
25 Sep 07 |
markus |
31 |
|
889 |
25 Sep 07 |
markus |
32 |
namespace theplu { |
889 |
25 Sep 07 |
markus |
33 |
namespace yat { |
889 |
25 Sep 07 |
markus |
34 |
namespace statistics { |
3531 |
11 Oct 16 |
peter |
35 |
|
3534 |
21 Dec 16 |
peter |
36 |
/** |
3534 |
21 Dec 16 |
peter |
\brief Calculates the Euclidean distance between elements of |
3534 |
21 Dec 16 |
peter |
two ranges. |
3531 |
11 Oct 16 |
peter |
39 |
|
3534 |
21 Dec 16 |
peter |
If elements of both ranges are unweighted the distance is |
3534 |
21 Dec 16 |
peter |
calculated as \f$ \sqrt{\sum (x_i-y_i)^2 } \f$, where \f$ x_i |
3534 |
21 Dec 16 |
peter |
\f$ and \f$ y_i \f$ are elements of the first and second range, |
3534 |
21 Dec 16 |
peter |
respectively. |
1093 |
14 Feb 08 |
peter |
44 |
|
3534 |
21 Dec 16 |
peter |
If elements of one or both of ranges have weights the distance |
3534 |
21 Dec 16 |
peter |
is calculated as \f$ \sqrt{N \sum |
3534 |
21 Dec 16 |
peter |
w_{x,i}w_{y,i}(x_i-y_i)^2/\sum w_{x,i}w_{y,i}} \f$, where \f$ N |
3534 |
21 Dec 16 |
peter |
\f$ is the number of elements in the two ranges and \f$ w_x \f$ |
3534 |
21 Dec 16 |
peter |
and \f$ w_y \f$ are weights for the elements of the first and |
3534 |
21 Dec 16 |
peter |
the second range, respectively. If the elements of one of the |
3534 |
21 Dec 16 |
peter |
two ranges are unweighted, the weights for these elements are |
3534 |
21 Dec 16 |
peter |
set to unity. |
3534 |
21 Dec 16 |
peter |
53 |
*/ |
3534 |
21 Dec 16 |
peter |
54 |
class EuclideanDistance : public Distance<EuclideanDistance> |
3534 |
21 Dec 16 |
peter |
55 |
{ |
3534 |
21 Dec 16 |
peter |
56 |
private: |
3534 |
21 Dec 16 |
peter |
57 |
friend class Distance<EuclideanDistance>; |
889 |
25 Sep 07 |
markus |
58 |
|
1050 |
07 Feb 08 |
peter |
59 |
template <typename Iter1, typename Iter2> |
3531 |
11 Oct 16 |
peter |
60 |
double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, |
1092 |
14 Feb 08 |
peter |
61 |
utility::unweighted_iterator_tag) const |
1050 |
07 Feb 08 |
peter |
62 |
{ |
1050 |
07 Feb 08 |
peter |
63 |
AveragerPair ap; |
1050 |
07 Feb 08 |
peter |
64 |
add(ap,beg1,end1,beg2); |
1050 |
07 Feb 08 |
peter |
65 |
return sqrt(ap.sum_squared_deviation()); |
1050 |
07 Feb 08 |
peter |
66 |
} |
889 |
25 Sep 07 |
markus |
67 |
|
1050 |
07 Feb 08 |
peter |
68 |
template <typename Iter1, typename Iter2> |
3531 |
11 Oct 16 |
peter |
69 |
double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, |
1092 |
14 Feb 08 |
peter |
70 |
utility::weighted_iterator_tag) const |
1050 |
07 Feb 08 |
peter |
71 |
{ |
1050 |
07 Feb 08 |
peter |
72 |
AveragerPairWeighted ap; |
1050 |
07 Feb 08 |
peter |
73 |
add(ap,beg1,end1,beg2); |
1050 |
07 Feb 08 |
peter |
74 |
return sqrt(std::distance(beg1,end1)*ap.msd()); |
1050 |
07 Feb 08 |
peter |
75 |
} |
3531 |
11 Oct 16 |
peter |
76 |
|
1050 |
07 Feb 08 |
peter |
77 |
}; |
890 |
25 Sep 07 |
markus |
78 |
|
889 |
25 Sep 07 |
markus |
79 |
}}} // of namespace statistics, yat, and theplu |
3531 |
11 Oct 16 |
peter |
80 |
|
889 |
25 Sep 07 |
markus |
81 |
#endif |