# Changeset 1512

Ignore:
Timestamp:
Sep 19, 2008, 4:29:24 PM (14 years ago)
Message:

fixes #439 - and also took care of ties

Location:
trunk
Files:
2 edited

### Legend:

Unmodified
 r1510 same. Each element x is replaced by \f$sum(w_i)/sum(w) \f$ where the first sum runs over elements for which \f$x_i < x \f$. 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. In the unweighted case that can be simplified to \f$rank/n \f$, i.e., the samllest element is assigned to 0, next smallest \f$1/n \f$ etc. \return result + (last-first) */ utility::sort_index(first, last, perm); double n = perm.size(); for ( size_t i=0; i(i)/n; 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); } utility::weight_iterator(result)); // set values with w=0 to 0 to avoid problems with NaNs utility::iterator_traits forward_trait; utility::iterator_traits trait; for (ForwardIterator i=first; i!=last; ++i) if (forward_trait.weight(i)==0) forward_trait.data(i)=0.0; if (trait.weight(i)==0) trait.data(i)=0.0; std::vector index(std::distance(first, last)); std::vector perm(std::distance(first, last)); utility::sort_index(utility::data_iterator(first), utility::data_iterator(last), index); utility::iterator_traits trait; trait.data(result+index[0])=0; for (size_t i=1; i rtrait; double sum_w=0; size_t i=0; while ( i(), w_sum)); std::bind2nd(std::divides(), sum_w)); return result + n; }