1 | #ifndef theplu_yat_statistics_vector_distance_h |
---|
2 | #define theplu_yat_statistics_vector_distance_h |
---|
3 | |
---|
4 | // $Id: vector_distance.h 999 2007-12-23 20:03:12Z jari $ |
---|
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 <iterator> |
---|
28 | |
---|
29 | #include "yat/classifier/DataLookup1D.h" |
---|
30 | #include "yat/classifier/DataLookupWeighted1D.h" |
---|
31 | #include "yat/utility/iterator_traits.h" |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | |
---|
36 | namespace statistics { |
---|
37 | |
---|
38 | /// |
---|
39 | /// For each measure to calculate distances between containers |
---|
40 | /// with random access iterators one should provide a struct |
---|
41 | /// that inherits from vector_distance_tag and provides a "label" for |
---|
42 | /// the distance measure. |
---|
43 | /// |
---|
44 | struct vector_distance_tag { |
---|
45 | /// tag defining distance measure |
---|
46 | typedef vector_distance_tag distance; |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | /// |
---|
51 | /// We are writing a generic function for all distance measures |
---|
52 | /// between containers with random access iterators (below). The |
---|
53 | /// general function does not have to know anything about different |
---|
54 | /// distance measures. Instead it can access the "label" of each |
---|
55 | /// distance measure through the special template structure |
---|
56 | /// vector_distance_traits. |
---|
57 | /// |
---|
58 | template <class T> |
---|
59 | struct vector_distance_traits { |
---|
60 | /// \return distance type |
---|
61 | typedef typename T::distance distance; |
---|
62 | }; |
---|
63 | |
---|
64 | |
---|
65 | /// |
---|
66 | /// The general function for calculating distances between vectors |
---|
67 | /// (containers with random access iterators). This general function |
---|
68 | /// calls specialized distance functions implementing various |
---|
69 | /// distance measures based on the "label" of a distance type object |
---|
70 | /// (templatized as Dist). It can also call separate implementations |
---|
71 | /// for iterators to weighted and unweighted iterators based on the |
---|
72 | /// trait of the iterators (templatized as Iter1 and Iter2). |
---|
73 | /// |
---|
74 | template <typename Iter1, typename Iter2, typename Dist> |
---|
75 | double vector_distance(Iter1 beg1, Iter1 end1, Iter2 beg2, const Dist disttag) |
---|
76 | { |
---|
77 | return |
---|
78 | vector_distance(beg1,end1,beg2, |
---|
79 | typename vector_distance_traits<Dist>::distance(), |
---|
80 | typename utility::weighted_if_any2<Iter1, Iter2>::type()); |
---|
81 | } |
---|
82 | |
---|
83 | }}} // of namespace statistics, yat, and theplu |
---|
84 | |
---|
85 | #endif |
---|