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