source: trunk/yat/statistics/AveragerPair.h @ 1486

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

Addresses #436.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
RevLine 
[680]1#ifndef _theplu_yat_statistics_averagerpair_
2#define _theplu_yat_statistics_averagerpair_
[138]3
[675]4// $Id: AveragerPair.h 1486 2008-09-09 21:17:19Z jari $
[295]5
[675]6/*
[831]7  Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
[1275]8  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
[1295]9  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
[675]10
[1437]11  This file is part of the yat library, http://dev.thep.lu.se/yat
[675]12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
[1486]15  published by the Free Software Foundation; either version 3 of the
[675]16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
[680]29#include "Averager.h"
[675]30
[937]31#include "yat/utility/iterator_traits.h"
[912]32
[138]33#include <cmath>
[180]34#include <utility>
[138]35
36namespace theplu{
[680]37namespace yat{
[197]38namespace statistics{
[487]39
[138]40  ///
[767]41  /// @brief Class for taking care of mean and covariance of two variables.
[138]42  ///
[490]43  /// @see Averager AveragerWeighted AveragerPairWeighted
[489]44  ///
[138]45  class AveragerPair
46  {
47  public:
48
49    ///
[703]50    /// @brief The default constructor
[138]51    ///
[703]52    AveragerPair(void);
53
[138]54    ///
55    /// Constructor taking sum of \a x , \a xx , \a y , \a yy , xy and
56    /// number of pair of values \a n
57    ///
[720]58    //AveragerPair(const double x, const double xx, const double y,
[483]59    //                    const double yy, const double xy, const unsigned long n)
60    //  : x_(Averager(x,xx,n)), y_(Averager(y,yy,n)), xy_(xy) {}
[138]61
62    ///
[703]63    /// The copy constructor
[138]64    ///
[703]65    AveragerPair(const AveragerPair&);
66
[138]67    ///
[197]68    /// Adding \a n pairs of data points with value \a x and \a y.
[138]69    ///
[1295]70    void add(const double x, const double y, const long n=1);
[138]71
[1043]72    /**
[1187]73       \brief Concordence correlation coefficient.
74
[1043]75       \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sum_i
76       (x_i-m_x)^2+\sum_i (y_i-m_y)^2 + n(m_x-m_y)^2} \f$
77       
78    */
[718]79    double ccc(void) const;
80
[1187]81    /**
82       \f$ \frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sqrt{\sum_i
83       (x_i-m_x)^2\sum_i (y_i-m_y)^2}} \f$
84       
85       \return %Pearson correlation coefficient.
86    */
[718]87    double correlation(void) const;
[138]88 
89    ///
[487]90    /// Calculating covariance using
[597]91    /// \f$ \frac{1}{N}\sum_i (x_i-m_x)(y_i-m_y) \f$,
92    /// where \f$ m \f$ is the mean.
[138]93    ///
[197]94    /// @return The covariance.
95    ///
[718]96    double covariance(void) const;
[138]97 
98    ///
[197]99    /// @return The mean of xy.
[138]100    ///
[718]101    double mean_xy(void) const;
[138]102
[1187]103    /**
104       \return Average squared deviation between x and y \f$
105       \frac{1}{N} \sum (x-y)^2 \f$
106    */
[718]107    double msd(void) const;
[138]108
109    ///
[219]110    /// @return The number of pair of data points.
111    ///
[1295]112    long n(void) const;
[219]113
114    ///
[703]115    /// @brief Reset everything to zero
[138]116    ///
[703]117    void reset(void);
[138]118
119    ///
[197]120    /// @return The sum of xy.
[138]121    ///
[718]122    double sum_xy(void) const;
[138]123
[1187]124    /**
125       \return Sum of squared deviation between x and y \f$
126       \sum (x-y)^2 \f$
127    */
[772]128    double sum_squared_deviation(void) const;
129
130    ///
[597]131    /// @return \f$ \sum_i (x_i-m_x)(y_i-m_y) \f$
[219]132    ///
[718]133    double sum_xy_centered(void) const;
[219]134
135    ///
[197]136    /// @return A const refencer to the averager object for x.
[138]137    ///
[718]138    const Averager& x_averager(void) const;
[138]139
140    ///
[197]141    /// @return A const reference to the averager object for y
[138]142    ///
[718]143    const Averager& y_averager(void) const;
[138]144
145    ///
[703]146    /// @brief The assigment operator
[138]147    ///
[703]148    const AveragerPair& operator=(const AveragerPair& a);
[138]149
150    ///
[197]151    /// Operator to add another Averager
[138]152    ///
153    const AveragerPair& operator+=(const AveragerPair&);
154
155  private:
156    Averager x_;
157    Averager y_;
158    double  xy_;
159
160  };
161
[886]162  /**
[1043]163     \brief adding data from two ranges to AveragerPair \a ap
[886]164   */
165  template <class Iter1, class Iter2>
166  void add(AveragerPair& ap, Iter1 first1, Iter1 last1, Iter2 first2)
167  {
[914]168    utility::check_iterator_is_unweighted(first1);
169    utility::check_iterator_is_unweighted(first2);
[886]170    for ( ; first1 != last1; ++first1, ++first2)
171      ap.add(*first1, *first2);
172  }
173
174
[680]175}}} // of namespace statistics, yat, and theplu
[138]176
177#endif
Note: See TracBrowser for help on using the repository browser.