Changeset 2502


Ignore:
Timestamp:
Jun 28, 2011, 11:09:54 PM (10 years ago)
Author:
Peter
Message:

mad: avoid copying data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/statistics/utility.h

    r2496 r2502  
    3131#include "yat/classifier/DataLookupWeighted1D.h"
    3232#include "yat/classifier/Target.h"
     33#include "yat/normalizer/utility.h"
    3334#include "yat/utility/concept_check.h"
     35#include "yat/utility/DataIterator.h"
    3436#include "yat/utility/deprecate.h"
    3537#include "yat/utility/iterator_traits.h"
     
    258260    double m = median(first, last, sorted);
    259261    typedef typename std::iterator_traits<RandomAccessIterator>::value_type T;
    260     typedef std::vector<T> Vec;
    261     Vec ad;
    262     ad.reserve(std::distance(first, last));
    263     // copy values (and weights if RandomAccessIterator is weighted)
    264     std::copy(first, last, std::back_insert_iterator<Vec>(ad));
    265     utility::iterator_traits<typename Vec::iterator> traits;
    266     for (typename Vec::iterator i=ad.begin() ; i!=ad.end(); ++i) {
    267       // adjust data
    268       traits.data(i) = std::abs(traits.data(i)-m);
     262    std::vector<T> ad(std::distance(first, last));
     263    // copy weights if needed
     264    normalizer::detail::copy_weight_if_weighted(first, last, ad.begin());
     265    // assign data (absolute deviation from median)
     266    utility::iterator_traits<RandomAccessIterator> traits;
     267    utility::DataIterator<typename std::vector<T>::iterator> first2(ad.begin());
     268    while (first!=last) {
     269      *first2 = std::abs(traits.data(first)-m);
     270      ++first;
     271      ++first2;
    269272    }
    270273    std::sort(ad.begin(), ad.end());
Note: See TracChangeset for help on using the changeset viewer.