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

Last change on this file since 1706 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • 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_distance_h
2#define theplu_yat_statistics_pearson_distance_h
3
4// $Id: PearsonDistance.h 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
8  Copyright (C) 2008 Peter Johansson, Markus Ringnér
9
10  This file is part of the yat library, http://dev.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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include "averager_traits.h"
27#include "yat/utility/iterator_traits.h"
28
29namespace theplu {
30namespace yat {
31namespace statistics {
32
33  ///
34  /// @brief Calculates the %Pearson correlation distance between two points given by elements of ranges.
35  ///
36  /// This class is modelling the concept \ref concept_distance.
37  ///
38  struct PearsonDistance
39  {
40    /**
41       \brief Calculates the %Pearson correlation distance between
42       elements of two ranges.
43   
44       If elements of both ranges are unweighted the distance is
45       calculated as \f$ 1-\mbox{C}(x,y) \f$, where \f$ x \f$ and \f$
46       y \f$ are the two points and C is the %Pearson correlation.
47
48       If elements of one or both of ranges have weights the distance
49       is calculated as \f$ 1-[\sum w_{x,i}w_{y,i}(x_i-y_i)^2/(\sum
50       w_{x,i}w_{y,i}(x_i-m_x)^2\sum w_{x,i}w_{y,i}(y_i-m_y)^2)] \f$,
51       where and \f$ w_x \f$ and \f$ w_y \f$ are weights for the
52       elements of the first and the second range, respectively, and
53       \f$ m_x=\sum w_{x,i}w_{y,i}x_i/\sum w_{x,i}w_{y,i} \f$ and
54       correspondingly for \f$ m_y \f$.  If the elements of one of the
55       two ranges are unweighted, the weights for these elements are
56       set to unity.
57    */   
58    template <typename Iter1, typename Iter2>
59    double operator()
60    (Iter1 beg1,Iter1 end1, Iter2 beg2) const
61    {
62      typename averager_pair<Iter1, Iter2>::type ap;
63      add(ap,beg1,end1,beg2);
64      return 1-ap.correlation();
65    }
66  };
67
68}}} // of namespace statistics, yat, and theplu
69   
70#endif
Note: See TracBrowser for help on using the repository browser.