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

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

using weighted_iterator_traits, closes #151

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