1 #ifndef _theplu_yat_normalizer_spearman_
2 #define _theplu_yat_normalizer_spearman_
28 #include "yat/utility/concept_check.h"
29 #include "yat/utility/DataIterator.h"
30 #include "yat/utility/iterator_traits.h"
31 #include "yat/utility/sort_index.h"
34 #include "yat/utility/WeightIterator.h"
36 #include <boost/concept_check.hpp>
37 #include <boost/iterator/iterator_concepts.hpp>
46 namespace normalizer {
77 template<
typename RandomAccessIter1,
typename RandomAccessIter2>
78 void operator()(RandomAccessIter1 first, RandomAccessIter1 last,
79 RandomAccessIter2 result)
const
81 using boost_concepts::RandomAccessTraversal;
82 BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIter1>));
84 BOOST_CONCEPT_ASSERT((DataIteratorConcept<RandomAccessIter1>));
86 using boost_concepts::WritableIterator;
87 BOOST_CONCEPT_ASSERT((WritableIterator<RandomAccessIter2>));
88 BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIter2>));
89 BOOST_CONCEPT_ASSERT((DataIteratorConcept<RandomAccessIter2>));
92 typename weighted_if_any2<RandomAccessIter1,RandomAccessIter2>::type tag;
93 normalize(first, last, result, tag);
99 template<
typename RandomAccessIter1,
typename RandomAccessIter2>
100 void normalize(RandomAccessIter1 first, RandomAccessIter1 last,
101 RandomAccessIter2 result,
104 std::vector<size_t> perm;
106 double n = perm.size();
108 while ( i<perm.size() ) {
110 while (i<perm.size() && first[perm[i]]<=first[perm[min_i]])
112 double res = (i + min_i)/(2.0*n);
113 for ( ; min_i < i; ++min_i)
114 result[perm[min_i]] = res;
120 template<
typename RandomAccessIter1,
typename RandomAccessIter2>
121 void normalize(RandomAccessIter1 first, RandomAccessIter1 last,
122 RandomAccessIter2 result,
123 utility::weighted_iterator_tag)
const
125 detail::copy_weight_if_weighted(first, last, result);
126 std::vector<size_t> perm;
128 utility::iterator_traits<RandomAccessIter1> trait;
129 utility::iterator_traits<RandomAccessIter2> rtrait;
134 while ( i<perm.size() ) {
137 while (i<perm.size() && (trait.weight(first+perm[i])==0 ||
138 trait.data(first+perm[i]) <=
139 trait.data(first+perm[min_i])) ) {
140 w += trait.weight(first+perm[i]);
143 double res = (sum_w + 0.5*w)/total_w;
144 for (
size_t j=min_i; j<i; ++j)
145 rtrait.data(result+perm[j]) = res;
Concept check for Data Iterator.
Definition: concept_check.h:228
double sum_weight(Iterator first, Iterator last)
Definition: utility.h:543
Some useful functions are placed here.
Definition: iterator_traits.h:47
Spearman(void)
default constructor
Definition: Spearman.h:63
void operator()(RandomAccessIter1 first, RandomAccessIter1 last, RandomAccessIter2 result) const
Definition: Spearman.h:78
Replace elements with normalized rank.
Definition: Spearman.h:57
void sort_index(InputIterator first, InputIterator last, std::vector< size_t > &sort_index)
Definition: sort_index.h:146
Definition: iterator_traits.h:159