source: trunk/yat/statistics/PearsonDistance.h @ 1069

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

First few steps on #323

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1#ifndef theplu_yat_statistics_pearson_distance_h
2#define theplu_yat_statistics_pearson_distance_h
3
4// $Id: PearsonDistance.h 1069 2008-02-11 21:57:24Z markus $
5
6/*
7  Copyright (C) 2007 Peter Johansson, Markus Ringnér
8  Copyright (C) 2008 Peter Johansson
9
10  This file is part of the yat library, http://trac.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 2 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include "AveragerPair.h"
29#include "AveragerPairWeighted.h"
30#include "yat/utility/iterator_traits.h"
31
32namespace theplu {
33namespace yat {
34namespace statistics {
35
36  ///
37  /// @brief Calculates the Pearson correlation distance between two points stored in 1-dimensional containers. Implements the concept \ref concept_distance.
38  ///
39  ///
40  struct PearsonDistance
41  {
42    ///
43    /// @brief Calculates the Pearson correlation distance between two ranges.
44    ///
45    template <typename Iter1, typename Iter2>
46    double operator()
47    (Iter1 beg1,Iter1 end1, Iter2 beg2) const
48    {
49      return this->distance(beg1, end1, beg2, 
50                      typename utility::weighted_if_any2<Iter1,Iter2>::type());
51    }
52
53  private:
54    template <typename Iter1, typename Iter2>
55    double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 
56                     utility::unweighted_type) const
57    {
58      AveragerPairWeighted ap;
59      add(ap,beg1,end1,beg2);
60      return 1-ap.correlation();
61    }
62
63    template <typename Iter1, typename Iter2>
64    double distance (Iter1 beg1,Iter1 end1, Iter2 beg2, 
65                     utility::weighted_type) const
66    {
67      AveragerPairWeighted ap;
68      add(ap,beg1,end1,beg2);
69      return 1-ap.correlation();
70    }
71   
72  };
73
74}}} // of namespace statistics, yat, and theplu
75   
76#endif
Note: See TracBrowser for help on using the repository browser.