# source:trunk/yat/statistics/euclidean_vector_distance.h@900

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

Refs #251. Fixed so the unweighted distances are at the forward-iterator level. To test this I added a distance calculation between a list and a vector in vector_distance_test (also fixed its indentation)

• 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 900 2007-09-27 07:10:33Z markus \$
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::forward_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                         utility::weighted_random_access_iterator_tag)
53  {
54    AveragerPairWeighted ap;
55    add(ap,beg1,end1,beg2);
56    return sqrt(ap.n()*ap.msd());
57  }
58
59
60}}} // of namespace statistics, yat, and theplu
61
62#endif
Note: See TracBrowser for help on using the repository browser.