# Changeset 1536

Ignore:
Timestamp:
Sep 25, 2008, 9:31:57 PM (13 years ago)
Message:

Location:
trunk
Files:
2 edited
1 copied

### Legend:

Unmodified
 r1533 #ifndef _theplu_yat_normalizer_spearman_ #define _theplu_yat_normalizer_spearman_ #ifndef _theplu_yat_normalizer_gauss_ #define _theplu_yat_normalizer_gauss_ /* */ #include "yat/utility/DataIterator.h" #include "Spearman.h" #include "yat/utility/iterator_traits.h" #include "yat/utility/sort_index.h" #include "yat/utility/WeightIterator.h" #include #include #include #include namespace theplu { /** \brief Replace elements with normalized rank \brief Gaussian Normalizer \since New in yat 0.5 */ class Spearman class Gauss { public: /** \brief default constructor */ Spearman(void){} /** It is possible to centralize a range "in place"; it is same. Each element x is replaced by \f$\frac{\sum I(x_i-x) w_i}{\sum w_i} \f$ where I(x) = 1 for x>0, I(x) = 0.5 for x=0, and I(x) = 0 for x<0. The range is first rank normalized using Spearman, after which each element is between 0 and unity. Second each element is replaced by inverse cumulative standard Gaussian distribution. After normalization the range will follow a standard Gaussian distribution (mean zero and unity variance). \see gsl_cdf_ugaussian_Pinv \return result + (last-first) RandomAccessIterator result) const { typename utility::weighted_iterator_traits::type tag; return normalize(first, last, result, tag); Spearman spearman; spearman(first, last, result); RandomAccessIterator end = result + (last-first); utility::iterator_traits trait; while (result != end) { trait.data(result) = gsl_cdf_ugaussian_Pinv(trait.data(result)); ++result; } return result; } private: // unweighted version template RandomAccessIterator normalize(ForwardIterator first, ForwardIterator last, RandomAccessIterator result, utility::unweighted_iterator_tag) const { std::vector perm; utility::sort_index(first, last, perm); double n = perm.size(); size_t i=0; while ( i(i + min_i)/(2*n); for ( ; min_i < i; ++min_i) result[perm[min_i]] = res; } return result + std::distance(first, last); } // weighted version template RandomAccessIterator normalize(ForwardIterator first, ForwardIterator last, RandomAccessIterator result, utility::weighted_iterator_tag) const { std::copy(utility::weight_iterator(first), utility::weight_iterator(last), utility::weight_iterator(result)); // set values with w=0 to 0 to avoid problems with NaNs utility::iterator_traits trait; for (ForwardIterator i=first; i!=last; ++i) if (trait.weight(i)==0) trait.data(i)=0.0; std::vector perm(std::distance(first, last)); utility::sort_index(utility::data_iterator(first), utility::data_iterator(last), perm); utility::iterator_traits rtrait; double sum_w=0; size_t i=0; while ( i(), sum_w)); return result + n; } };