source: trunk/yat/statistics/pearson_vector_distance.h @ 999

Last change on this file since 999 was 999, checked in by Jari Häkkinen, 15 years ago

Copyright statement added.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 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 999 2007-12-23 20:03:12Z jari $
5
6/*
7  Copyright (C) 2007 Peter Johansson, Markus Ringnér
8
9  This file is part of the yat library, http://trac.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "vector_distance.h"
28
29#include "AveragerPair.h"
30#include "AveragerPairWeighted.h"
31#include "yat/utility/iterator_traits.h"
32
33namespace theplu {
34namespace yat {
35
36namespace statistics {
37
38  ///
39  /// Provides a "label" for
40  /// the Pearson distance measure.
41  ///
42  struct pearson_vector_distance_tag 
43    : public vector_distance_tag
44  {
45    /// \brief tag for pearson distance
46    typedef pearson_vector_distance_tag distance;
47  };
48
49
50  ///
51  /// implementation for distances between vectors
52  /// (containers with random access iterators) using a Pearson
53  /// distance measure and iterators to unweighted containers.
54  ///
55  template <class Iter>
56  double vector_distance(Iter beg1,Iter end1, Iter beg2,
57                         const pearson_vector_distance_tag& disttype,
58                         utility::unweighted_type)
59  {
60    AveragerPair ap;
61    add(ap,beg1,end1,beg2);
62    return 1-ap.correlation();
63  }
64 
65  ///
66  /// implementation for distances between vectors
67  /// (containers with random access iterators) using a Pearson
68  /// distance measure and iterators to unweighted containers.
69  ///
70  template <class Iter>
71  double vector_distance(Iter beg1,Iter end1, Iter beg2,
72                         const pearson_vector_distance_tag& disttype,
73                         utility::weighted_type)
74  {
75    AveragerPairWeighted ap;
76    add(ap,beg1,end1,beg2);
77    return 1-ap.correlation();
78  }
79
80 
81}}} // of namespace statistics, yat, and theplu
82   
83#endif
Note: See TracBrowser for help on using the repository browser.