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

Last change on this file since 937 was 937, checked in by Peter, 14 years ago

changing name of IteratorTraits? to iterator_traits

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
RevLine 
[889]1#ifndef theplu_yat_statistics_vector_distance_h
2#define theplu_yat_statistics_vector_distance_h
3
4// $Id: vector_distance.h 937 2007-10-05 23:11:18Z peter $
5
6#include <iterator>
7
[898]8#include "yat/classifier/DataLookup1D.h"
9#include "yat/classifier/DataLookupWeighted1D.h"
[937]10#include "yat/utility/iterator_traits.h"
[898]11
[889]12namespace theplu {
13namespace yat {
14
15namespace statistics {
[898]16 
[889]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
[891]49  /// trait of the iterators (templatized as Iter1 and Iter2).
[889]50  ///
[891]51  template <typename Iter1, typename Iter2, typename Dist>
52  double vector_distance(Iter1 beg1, Iter1 end1, Iter2 beg2, const Dist disttag)
[889]53  {
[909]54    return 
55      vector_distance(beg1,end1,beg2,
56                      typename vector_distance_traits<Dist>::distance(),
57                      typename utility::weighted_iterator_traits<Iter1>::type());
[889]58  }       
[898]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  }
[889]66 
[898]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) 
[891]70  {
[898]71    return vector_distance(beg1,end1,beg2, typename statistics::vector_distance_traits<Dist>::distance());
72  }
[891]73 
[889]74}}} // of namespace statistics, yat, and theplu
[891]75
[889]76#endif
Note: See TracBrowser for help on using the repository browser.