source: trunk/yat/statistics/vector_distance.h @ 889

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

Refs #245. A new structure to calculate distances between vectors that is based on iterators and traits patterns. Will replace the old inherited Distance structure. Support for iterators to weighted containers is not yet added

File size: 1.7 KB
Line 
1#ifndef theplu_yat_statistics_vector_distance_h
2#define theplu_yat_statistics_vector_distance_h
3
4// $Id$
5
6#include <iterator>
7
8namespace theplu {
9namespace yat {
10
11namespace statistics {
12
13  ///
14  /// For each measure to calculate distances between containers
15  /// with random access iterators one should provide a struct
16  /// which inherits from vector_distance_tag and provides a "label" for
17  /// the distance measure.
18  ///
19  struct vector_distance_tag {
20    typedef vector_distance_tag distance;
21  };
22
23
24  ///
25  /// We are writing a generic function for all distance measures
26  /// between containers with random access iterators (below). The
27  /// general function does not have to know anything about different
28  /// distance measures.  Instead it can access the "label" of each
29  /// distance measure through the special template structure
30  /// vector_distance_traits.
31  ///
32  template <class T>
33  struct vector_distance_traits {
34    typedef typename T::distance distance;
35  };
36
37
38  ///
39  /// The general function for calculating distances between vectors
40  /// (containers with random access iterators). This general function
41  /// calls specialized distance functions implementing various
42  /// distance measures based on the "label" of a distance type object
43  /// (templatized as Dist). It can also call separate implementations
44  /// for iterators to weighted and unweighted iterators based on the
45  /// trait of the iterator (templatized as Iter).
46  ///
47  template <typename Iter, typename Dist>
48  double vector_distance(Iter beg1, Iter end1, Iter beg2, const Dist& disttag)
49  {
50    return vector_distance(beg1,end1,beg2,typename vector_distance_traits<Dist>::distance(),
51                           typename std::iterator_traits<Iter>::iterator_category());
52  }       
53 
54}}} // of namespace statistics, yat, and theplu
55   
56#endif
Note: See TracBrowser for help on using the repository browser.