1 | #ifndef theplu_yat_statistics_vector_distance_h |
---|
2 | #define theplu_yat_statistics_vector_distance_h |
---|
3 | |
---|
4 | // $Id: vector_distance.h 909 2007-09-28 23:49:05Z peter $ |
---|
5 | |
---|
6 | #include <iterator> |
---|
7 | |
---|
8 | #include "yat/classifier/DataLookup1D.h" |
---|
9 | #include "yat/classifier/DataLookupWeighted1D.h" |
---|
10 | #include "yat/utility/IteratorTraits.h" |
---|
11 | |
---|
12 | namespace theplu { |
---|
13 | namespace yat { |
---|
14 | |
---|
15 | namespace statistics { |
---|
16 | |
---|
17 | /// |
---|
18 | /// For each measure to calculate distances between containers |
---|
19 | /// with random access iterators one should provide a struct |
---|
20 | /// which inherits from vector_distance_tag and provides a "label" for |
---|
21 | /// the distance measure. |
---|
22 | /// |
---|
23 | struct vector_distance_tag { |
---|
24 | typedef vector_distance_tag distance; |
---|
25 | }; |
---|
26 | |
---|
27 | |
---|
28 | /// |
---|
29 | /// We are writing a generic function for all distance measures |
---|
30 | /// between containers with random access iterators (below). The |
---|
31 | /// general function does not have to know anything about different |
---|
32 | /// distance measures. Instead it can access the "label" of each |
---|
33 | /// distance measure through the special template structure |
---|
34 | /// vector_distance_traits. |
---|
35 | /// |
---|
36 | template <class T> |
---|
37 | struct vector_distance_traits { |
---|
38 | typedef typename T::distance distance; |
---|
39 | }; |
---|
40 | |
---|
41 | |
---|
42 | /// |
---|
43 | /// The general function for calculating distances between vectors |
---|
44 | /// (containers with random access iterators). This general function |
---|
45 | /// calls specialized distance functions implementing various |
---|
46 | /// distance measures based on the "label" of a distance type object |
---|
47 | /// (templatized as Dist). It can also call separate implementations |
---|
48 | /// for iterators to weighted and unweighted iterators based on the |
---|
49 | /// trait of the iterators (templatized as Iter1 and Iter2). |
---|
50 | /// |
---|
51 | template <typename Iter1, typename Iter2, typename Dist> |
---|
52 | double vector_distance(Iter1 beg1, Iter1 end1, Iter2 beg2, const Dist disttag) |
---|
53 | { |
---|
54 | return |
---|
55 | vector_distance(beg1,end1,beg2, |
---|
56 | typename vector_distance_traits<Dist>::distance(), |
---|
57 | typename utility::weighted_iterator_traits<Iter1>::type()); |
---|
58 | } |
---|
59 | |
---|
60 | /// A partial specialization for DataLookupWeighted1D |
---|
61 | template<typename Dist> |
---|
62 | double vector_distance(const classifier::DataLookupWeighted1D::const_iterator& beg1,const classifier::DataLookupWeighted1D::const_iterator& end1,const classifier::DataLookupWeighted1D::const_iterator& beg2) |
---|
63 | { |
---|
64 | return vector_distance(beg1,end1,beg2, typename statistics::vector_distance_traits<Dist>::distance()); |
---|
65 | } |
---|
66 | |
---|
67 | /// A partial specialization for DataLookup1D |
---|
68 | template<typename Dist> |
---|
69 | double vector_distance(const classifier::DataLookup1D::const_iterator& beg1,const classifier::DataLookup1D::const_iterator& end1,const classifier::DataLookup1D::const_iterator& beg2) |
---|
70 | { |
---|
71 | return vector_distance(beg1,end1,beg2, typename statistics::vector_distance_traits<Dist>::distance()); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | }}} // of namespace statistics, yat, and theplu |
---|
76 | |
---|
77 | #endif |
---|