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

Last change on this file since 958 was 958, checked in by Peter, 16 years ago

allowing mixture of weighted and unweighted iterators in vector_distance

• Property svn:eol-style set to `native`
• Property svn:keywords set to `Id`
File size: 1.9 KB
Line
1#ifndef theplu_yat_statistics_vector_distance_h
2#define theplu_yat_statistics_vector_distance_h
3
4// \$Id: vector_distance.h 958 2007-10-10 15:44:06Z peter \$
5
6#include <iterator>
7
8#include "yat/classifier/DataLookup1D.h"
9#include "yat/classifier/DataLookupWeighted1D.h"
10#include "yat/utility/iterator_traits.h"
11
12namespace theplu {
13namespace yat {
14
15namespace 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_if_any2<Iter1, Iter2>::type());
58  }
59
60}}} // of namespace statistics, yat, and theplu
61
62#endif
Note: See TracBrowser for help on using the repository browser.