#ifndef _theplu_yat_statistics_averagerpair_ #define _theplu_yat_statistics_averagerpair_ // $Id: AveragerPair.h 1486 2008-09-09 21:17:19Z jari$ /* Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "Averager.h" #include "yat/utility/iterator_traits.h" #include #include namespace theplu{ namespace yat{ namespace statistics{ /// /// @brief Class for taking care of mean and covariance of two variables. /// /// @see Averager AveragerWeighted AveragerPairWeighted /// class AveragerPair { public: /// /// @brief The default constructor /// AveragerPair(void); /// /// Constructor taking sum of \a x , \a xx , \a y , \a yy , xy and /// number of pair of values \a n /// //AveragerPair(const double x, const double xx, const double y, // const double yy, const double xy, const unsigned long n) // : x_(Averager(x,xx,n)), y_(Averager(y,yy,n)), xy_(xy) {} /// /// The copy constructor /// AveragerPair(const AveragerPair&); /// /// Adding \a n pairs of data points with value \a x and \a y. /// void add(const double x, const double y, const long n=1); /** \brief Concordence correlation coefficient. \f$\frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sum_i (x_i-m_x)^2+\sum_i (y_i-m_y)^2 + n(m_x-m_y)^2} \f$ */ double ccc(void) const; /** \f$\frac{\sum_i (x_i-m_x)(y_i-m_y)}{\sqrt{\sum_i (x_i-m_x)^2\sum_i (y_i-m_y)^2}} \f$ \return %Pearson correlation coefficient. */ double correlation(void) const; /// /// Calculating covariance using /// \f$\frac{1}{N}\sum_i (x_i-m_x)(y_i-m_y) \f$, /// where \f$m \f$ is the mean. /// /// @return The covariance. /// double covariance(void) const; /// /// @return The mean of xy. /// double mean_xy(void) const; /** \return Average squared deviation between x and y \f$\frac{1}{N} \sum (x-y)^2 \f$ */ double msd(void) const; /// /// @return The number of pair of data points. /// long n(void) const; /// /// @brief Reset everything to zero /// void reset(void); /// /// @return The sum of xy. /// double sum_xy(void) const; /** \return Sum of squared deviation between x and y \f$\sum (x-y)^2 \f$ */ double sum_squared_deviation(void) const; /// /// @return \f$\sum_i (x_i-m_x)(y_i-m_y) \f$ /// double sum_xy_centered(void) const; /// /// @return A const refencer to the averager object for x. /// const Averager& x_averager(void) const; /// /// @return A const reference to the averager object for y /// const Averager& y_averager(void) const; /// /// @brief The assigment operator /// const AveragerPair& operator=(const AveragerPair& a); /// /// Operator to add another Averager /// const AveragerPair& operator+=(const AveragerPair&); private: Averager x_; Averager y_; double xy_; }; /** \brief adding data from two ranges to AveragerPair \a ap */ template void add(AveragerPair& ap, Iter1 first1, Iter1 last1, Iter2 first2) { utility::check_iterator_is_unweighted(first1); utility::check_iterator_is_unweighted(first2); for ( ; first1 != last1; ++first1, ++first2) ap.add(*first1, *first2); } }}} // of namespace statistics, yat, and theplu #endif