# source:trunk/yat/statistics/vector_distance.h@898

Last change on this file since 898 was 898, checked in by Markus Ringnér, 15 years ago

A first suggestion for how to adress #250. Also removed contamination of namespace std (see #251).

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