1 | #ifndef theplu_yat_statistics_pearson_distance_h |
---|
2 | #define theplu_yat_statistics_pearson_distance_h |
---|
3 | |
---|
4 | // $Id: pearson_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 "distance.h" |
---|
28 | |
---|
29 | #include "AveragerPair.h" |
---|
30 | #include "AveragerPairWeighted.h" |
---|
31 | #include "yat/utility/iterator_traits.h" |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | |
---|
36 | namespace statistics { |
---|
37 | |
---|
38 | /// |
---|
39 | /// Provides a "label" for |
---|
40 | /// the Pearson distance measure. |
---|
41 | /// |
---|
42 | struct pearson_distance_tag |
---|
43 | : public distance_tag |
---|
44 | { |
---|
45 | /// \brief tag for pearson distance |
---|
46 | typedef pearson_distance_tag distance; |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | /// |
---|
51 | /// implementation for distances between vectors |
---|
52 | /// (containers with random access iterators) using a Pearson |
---|
53 | /// distance measure and iterators to unweighted containers. |
---|
54 | /// |
---|
55 | template <class Iter> |
---|
56 | double distance(Iter beg1,Iter end1, Iter beg2, |
---|
57 | const pearson_distance_tag& disttype, |
---|
58 | utility::unweighted_type) |
---|
59 | { |
---|
60 | AveragerPair ap; |
---|
61 | add(ap,beg1,end1,beg2); |
---|
62 | return 1-ap.correlation(); |
---|
63 | } |
---|
64 | |
---|
65 | /// |
---|
66 | /// implementation for distances between vectors |
---|
67 | /// (containers with random access iterators) using a Pearson |
---|
68 | /// distance measure and iterators to unweighted containers. |
---|
69 | /// |
---|
70 | template <class Iter> |
---|
71 | double distance(Iter beg1,Iter end1, Iter beg2, |
---|
72 | const pearson_distance_tag& disttype, |
---|
73 | utility::weighted_type) |
---|
74 | { |
---|
75 | AveragerPairWeighted ap; |
---|
76 | add(ap,beg1,end1,beg2); |
---|
77 | return 1-ap.correlation(); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | }}} // of namespace statistics, yat, and theplu |
---|
82 | |
---|
83 | #endif |
---|