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

Last change on this file since 1437 was 1437, checked in by Peter, 13 years ago

merge patch release 0.4.2 to trunk. Delta 0.4.2-0.4.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#ifndef theplu_yat_statistics_pearson_distance_h
2#define theplu_yat_statistics_pearson_distance_h
3
4// $Id: PearsonDistance.h 1437 2008-08-25 17:55:00Z peter $
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 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 "averager_traits.h"
29#include "yat/utility/iterator_traits.h"
30
31namespace theplu {
32namespace yat {
33namespace statistics {
34
35  ///
36  /// @brief Calculates the %Pearson correlation distance between two points given by elements of ranges.
37  ///
38  /// This class is modelling the concept \ref concept_distance.
39  ///
40  struct PearsonDistance
41  {
42    /**
43       \brief Calculates the %Pearson correlation distance between
44       elements of two ranges.
45   
46       If elements of both ranges are unweighted the distance is
47       calculated as \f$ 1-\mbox{C}(x,y) \f$, where \f$ x \f$ and \f$
48       y \f$ are the two points and C is the %Pearson correlation.
49
50       If elements of one or both of ranges have weights the distance
51       is calculated as \f$ 1-[\sum w_{x,i}w_{y,i}(x_i-y_i)^2/(\sum
52       w_{x,i}w_{y,i}(x_i-m_x)^2\sum w_{x,i}w_{y,i}(y_i-m_y)^2)] \f$,
53       where and \f$ w_x \f$ and \f$ w_y \f$ are weights for the
54       elements of the first and the second range, respectively, and
55       \f$ m_x=\sum w_{x,i}w_{y,i}x_i/\sum w_{x,i}w_{y,i} \f$ and
56       correspondingly for \f$ m_y \f$.  If the elements of one of the
57       two ranges are unweighted, the weights for these elements are
58       set to unity.
59    */   
60    template <typename Iter1, typename Iter2>
61    double operator()
62    (Iter1 beg1,Iter1 end1, Iter2 beg2) const
63    {
64      typename averager_pair<Iter1, Iter2>::type ap;
65      add(ap,beg1,end1,beg2);
66      return 1-ap.correlation();
67    }
68  };
69
70}}} // of namespace statistics, yat, and theplu
71   
72#endif
Note: See TracBrowser for help on using the repository browser.