# Changeset 1139 for trunk/yat/statistics

Ignore:
Timestamp:
Feb 24, 2008, 2:59:27 AM (14 years ago)
Message:

iterators in PearsonCorrelation? interface

Location:
trunk/yat/statistics
Files:
2 edited

### Legend:

Unmodified
 r1125 Copyright (C) 2004, 2005 Peter Johansson Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson Copyright (C) 2007 Peter Johansson Copyright (C) 2007, 2008 Peter Johansson This file is part of the yat library, http://trac.thep.lu.se/yat */ #include "Score.h" #include "AveragerPair.h" #include "AveragerPairWeighted.h" #include "yat/classifier/Target.h" #include "yat/utility/iterator_traits.h" namespace theplu { \f$\frac{\vert \sum_i(x_i-\bar{x})(y_i-\bar{y})\vert }{\sqrt{\sum_i (x_i-\bar{x})^2\sum_i (x_i-\bar{x})^2}} \f$. If ForwardIterator is weighted correlation is calculated as \f$\frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert } {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}} \f$, where \f$m_x = \frac{\sum w_ix_i}{\sum w_i} \f$ and \f$m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is chosen to get a correlation equal to unity when \a x and \a y are equal. @return Pearson correlation, if absolute=true absolute value of Pearson is used. */ template double score(const classifier::Target& target, const utility::VectorBase& value); ForwardIterator first, ForwardIterator last); /** m_x = \frac{\sum w_ix_i}{\sum w_i} \f$. This expression is chosen to get a correlation equal to unity when \a x and \a y are equal. @return absolute value of weighted version of Pearson correlation. are equal. \return absolute value of weighted version of Pearson correlation. \note ietartors must be non-weighted */ template double score(const classifier::Target& target, const classifier::DataLookupWeighted1D& value); /** \f$ \frac{\vert \sum_iw^2_i(x_i-\bar{x})(y_i-\bar{y})\vert } {\sqrt{\sum_iw^2_i(x_i-\bar{x})^2\sum_iw^2_i(y_i-\bar{y})^2}} \f$, where \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f$and \f$ m_x = \frac{\sum w_ix_i}{\sum w_i} \f\$. This expression is chosen to get a correlation equal to unity when \a x and \a y are equal. @return absolute value of weighted version of Pearson correlation. */ double score(const classifier::Target& target, const utility::VectorBase& value, const utility::VectorBase& weight); ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); /** int nof_samples_; template double score(const classifier::Target& target, ForwardIterator first, ForwardIterator last, utility::unweighted_iterator_tag); template double score(const classifier::Target& target, ForwardIterator first, ForwardIterator last, utility::weighted_iterator_tag); }; template double PearsonCorrelation::score(const classifier::Target& target, ForwardIterator first, ForwardIterator last) { nof_samples_ = target.size(); using utility::yat_assert; yat_assert("PearsonCorrelation: sizes mismatch"); r_ = score(target, first, last, utility::iterator_traits::type()); return r_; } template double PearsonCorrelation::score(const classifier::Target& target, ForwardIterator first, ForwardIterator last, utility::unweighted_iterator_tag tag) { AveragerPair ap; for (size_t i=0; first!=last; ++first, ++i) ap.add(target.binary(i), *first); nof_samples_ = ap.n(); return ap.correlation(); } template double PearsonCorrelation::score(const classifier::Target& target, ForwardIterator first, ForwardIterator last, utility::weighted_iterator_tag tag) { AveragerPairWeighted ap; for (size_t i=0; first!=last; ++first, ++i) ap.add(target.binary(i), first.data(), 1.0, first.weight()); nof_samples_ = ap.n(); return ap.correlation(); } template double PearsonCorrelation::score(const classifier::Target& target, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) { utility::check_iterator_is_unweighted(first1); utility::check_iterator_is_unweighted(first2); AveragerPairWeighted ap; for (size_t i=0; first1!=last1; ++first1, ++i, ++first2) ap.add(target.binary(i), *first1, 1.0, *first2); nof_samples_ = ap.n(); r_ = ap.correlation(); } }}} // of namespace statistics, yat, and theplu