source: trunk/yat/statistics/euclidean_vector_distance.h @ 895

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

Another try, hm...

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1#ifndef theplu_yat_statistics_euclidean_vector_distance_h
2#define theplu_yat_statistics_euclidean_vector_distance_h
3
4// $Id: euclidean_vector_distance.h 895 2007-09-25 20:39:14Z peter $
5
6#include "AveragerPair.h"
7#include "AveragerPairWeighted.h"
8#include "vector_distance.h"
9
10#include <cmath>
11
12namespace theplu {
13namespace yat {
14
15namespace statistics {
16
17  ///
18  /// Provides a "label" for
19  /// the Euclidean distance measure.
20  ///
21  struct euclidean_vector_distance_tag 
22    : public vector_distance_tag
23  {
24    typedef euclidean_vector_distance_tag distance;
25  };
26
27
28  ///
29  /// implementation for distances between vectors
30  /// (containers with random access iterators) using a Euclidean
31  /// distance measure and iterators to unweighted containers.
32  ///
33  template <typename Iter1, typename Iter2>
34  double vector_distance(Iter1 beg1,Iter1 end1, Iter2 beg2,
35                         const euclidean_vector_distance_tag& disttype,
36                         std::random_access_iterator_tag)
37  {
38    AveragerPair ap;
39    add(ap,beg1,end1,beg2);
40    return sqrt(ap.sum_squared_deviation());
41  }
42 
43
44  ///
45  /// implementation for distances between vectors
46  /// (containers with random access iterators) using a Euclidean
47  /// distance measure and iterators to weighted containers.
48  ///
49  template <typename Iter1, typename Iter2>
50  double vector_distance(Iter1 beg1, Iter1 end1, Iter2 beg2,
51                         const euclidean_vector_distance_tag& disttype,
52                         std::weighted_random_access_iterator_tag)
53  {
54    AveragerPairWeighted ap;
55    add(ap,beg1,end1,beg2);
56    return sqrt(ap.sum_squared_deviation());
57  }
58
59 
60}}} // of namespace statistics, yat, and theplu
61   
62#endif
Note: See TracBrowser for help on using the repository browser.