Changeset 2152


Ignore:
Timestamp:
Jan 17, 2010, 7:23:16 AM (12 years ago)
Author:
Peter
Message:

fix so Spearman works also when input range is weighted and read-only

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization_test.cc

    r2151 r2152  
    421421             boost::random_access_iterator_archetype<double>(),
    422422             boost::mutable_random_access_iterator_archetype<double>());
     423    using utility::DataWeight;
     424    spearman(boost::random_access_iterator_archetype<DataWeight>(),
     425             boost::random_access_iterator_archetype<DataWeight>(),
     426             boost::mutable_random_access_iterator_archetype<DataWeight>());
    423427  }
    424428
  • trunk/yat/normalizer/Spearman.h

    r2149 r2152  
    109109                utility::weight_iterator(last),
    110110                utility::weight_iterator(result));
     111      std::vector<double> input_vec;
     112      input_vec.reserve(last-first);
    111113      // set values with w=0 to 0 to avoid problems with NaNs
    112114      utility::iterator_traits<RandomAccessIter1> trait;
    113       for (RandomAccessIter1 i=first; i!=last; ++i)
     115      for (RandomAccessIter1 i=first; i!=last; ++i) {
    114116        if (trait.weight(i)==0)
    115           trait.data(i)=0.0;
     117          input_vec.push_back(0.0);
     118        else
     119          input_vec.push_back(trait.data(i));
     120      }
    116121
    117       std::vector<size_t> perm(std::distance(first, last));
    118       utility::sort_index(utility::data_iterator(first),
    119                           utility::data_iterator(last), perm);
     122      std::vector<size_t> perm(input_vec.size());
     123      utility::sort_index(input_vec.begin(), input_vec.end(), perm);
    120124      utility::iterator_traits<RandomAccessIter2> rtrait;
    121125
Note: See TracChangeset for help on using the changeset viewer.