source: trunk/yat/statistics/pearson_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.4 KB
Line 
1#ifndef theplu_yat_statistics_pearson_vector_distance_h
2#define theplu_yat_statistics_pearson_vector_distance_h
3
4// $Id: pearson_vector_distance.h 900 2007-09-27 07:10:33Z markus $
5
6#include "vector_distance.h"
7
8#include "AveragerPair.h"
9#include "AveragerPairWeighted.h"
10
11namespace theplu {
12namespace yat {
13
14namespace statistics {
15
16  ///
17  /// Provides a "label" for
18  /// the Pearson distance measure.
19  ///
20  struct pearson_vector_distance_tag 
21    : public vector_distance_tag
22  {
23    typedef pearson_vector_distance_tag distance;
24  };
25
26
27  ///
28  /// implementation for distances between vectors
29  /// (containers with random access iterators) using a Pearson
30  /// distance measure and iterators to unweighted containers.
31  ///
32  template <class Iter>
33  double vector_distance(Iter beg1,Iter end1, Iter beg2,
34                         const pearson_vector_distance_tag& disttype,
35                         std::forward_iterator_tag)
36  {
37    AveragerPair ap;
38    add(ap,beg1,end1,beg2);
39    return 1-ap.correlation();
40  }
41 
42  ///
43  /// implementation for distances between vectors
44  /// (containers with random access iterators) using a Pearson
45  /// distance measure and iterators to unweighted containers.
46  ///
47  template <class Iter>
48  double vector_distance(Iter beg1,Iter end1, Iter beg2,
49                         const pearson_vector_distance_tag& disttype,
50                         utility::weighted_random_access_iterator_tag)
51  {
52    AveragerPairWeighted ap;
53    add(ap,beg1,end1,beg2);
54    return 1-ap.correlation();
55  }
56
57 
58}}} // of namespace statistics, yat, and theplu
59   
60#endif
Note: See TracBrowser for help on using the repository browser.