1 | #ifndef theplu_yat_statistics_euclidean_distance_h |
---|
2 | #define theplu_yat_statistics_euclidean_distance_h |
---|
3 | |
---|
4 | // $Id: EuclideanDistance.h 1092 2008-02-14 21:54:19Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2007 Peter Johansson, Markus Ringnér |
---|
8 | Copyright (C) 2008 Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 2 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "AveragerPair.h" |
---|
29 | #include "AveragerPairWeighted.h" |
---|
30 | #include "yat/utility/iterator_traits.h" |
---|
31 | |
---|
32 | #include <cmath> |
---|
33 | |
---|
34 | namespace theplu { |
---|
35 | namespace yat { |
---|
36 | namespace statistics { |
---|
37 | |
---|
38 | /// |
---|
39 | /// @brief Calculates the Euclidean distance between two points stored in 1-dimensional containers. Implements the concept \ref concept_distance. |
---|
40 | /// |
---|
41 | /// |
---|
42 | struct EuclideanDistance |
---|
43 | { |
---|
44 | /// |
---|
45 | /// @brief Calculates the Euclidean distance between two ranges. |
---|
46 | /// |
---|
47 | template <typename Iter1, typename Iter2> |
---|
48 | double operator() |
---|
49 | (Iter1 beg1,Iter1 end1, Iter2 beg2) const |
---|
50 | { |
---|
51 | return this->distance(beg1, end1, beg2, |
---|
52 | typename utility::weighted_if_any2<Iter1,Iter2>::type()); |
---|
53 | } |
---|
54 | |
---|
55 | private: |
---|
56 | template <typename Iter1, typename Iter2> |
---|
57 | double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, |
---|
58 | utility::unweighted_iterator_tag) const |
---|
59 | { |
---|
60 | AveragerPair ap; |
---|
61 | add(ap,beg1,end1,beg2); |
---|
62 | return sqrt(ap.sum_squared_deviation()); |
---|
63 | } |
---|
64 | |
---|
65 | template <typename Iter1, typename Iter2> |
---|
66 | double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, |
---|
67 | utility::weighted_iterator_tag) const |
---|
68 | { |
---|
69 | AveragerPairWeighted ap; |
---|
70 | add(ap,beg1,end1,beg2); |
---|
71 | return sqrt(std::distance(beg1,end1)*ap.msd()); |
---|
72 | } |
---|
73 | |
---|
74 | }; |
---|
75 | |
---|
76 | }}} // of namespace statistics, yat, and theplu |
---|
77 | |
---|
78 | #endif |
---|