Changeset 1740


Ignore:
Timestamp:
Jan 21, 2009, 2:03:13 PM (14 years ago)
Author:
Peter
Message:

addresses #478 - implemented weighted normalization. Need to add test especially to test that the templates compile.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization_test.cc

    r1738 r1740  
    153153  // Enough iteration will make all columns to have the same values as
    154154  // the target.
    155   suite.err() << "Testing that q=matrix rows gives QuantileNormaliztion\n";
     155  suite.err() << "Testing that q=matrix rows gives QuantileNormalization\n";
    156156  utility::Matrix m2(4,2);
    157157  m2(0,0) = 0; m2(0,1) = 10;
  • trunk/yat/normalizer/qQuantileNormalizer.h

    r1739 r1740  
    2222
    2323#include "yat/regression/CSplineInterpolation.h"
     24#include "yat/utility/DataIterator.h"
    2425#include "yat/utility/DataWeight.h"
    2526#include "yat/utility/iterator_traits.h"
    2627#include "yat/utility/Vector.h"
     28#include "yat/utility/WeightIterator.h"
    2729#include "yat/utility/yat_assert.h"
    2830
     
    158160
    159161    Partitioner target_;
     162
     163    // unweighted version
     164    template<typename RandomAccessIterator1, typename RandomAccessIterator2>
     165    void normalize(const Partitioner& source,RandomAccessIterator1 first,
     166                   RandomAccessIterator1 last, RandomAccessIterator2 result,
     167                   utility::unweighted_iterator_tag tag) const;
     168
     169    // weighted version
     170    // copy weights and apply unweighted version on data part
     171    template<typename RandomAccessIterator1, typename RandomAccessIterator2>
     172    void normalize(const Partitioner& source,RandomAccessIterator1 first,
     173                   RandomAccessIterator1 last, RandomAccessIterator2 result,
     174                   utility::weighted_iterator_tag tag) const;
    160175  };
    161176
     
    179194                                       RandomAccessIterator2 result) const
    180195  {
     196    Partitioner source(first, last, target_.size());
     197    typename utility::weighted_iterator_traits<RandomAccessIterator2>::type tag;
     198    normalize(source, first, last, result, tag);
     199  }
     200
     201
     202  template<typename RandomAccessIterator1, typename RandomAccessIterator2>
     203  void
     204  qQuantileNormalizer::normalize(const qQuantileNormalizer::Partitioner& source,
     205                                 RandomAccessIterator1 first,
     206                                 RandomAccessIterator1 last,
     207                                 RandomAccessIterator2 result,
     208                                 utility::unweighted_iterator_tag tag) const
     209  {
    181210    size_t N = last-first;
    182211    utility::yat_assert<std::runtime_error>
     
    186215    utility::sort_index(first, last, sorted_index);
    187216
    188     Partitioner source(first, last, target_.size());
    189217    utility::Vector diff(source.averages());
    190218    diff-=target_.averages();
     
    233261
    234262
     263  template<typename RandomAccessIterator1, typename RandomAccessIterator2>
     264  void qQuantileNormalizer::normalize(const Partitioner& source,
     265                                      RandomAccessIterator1 first,
     266                                      RandomAccessIterator1 last,
     267                                      RandomAccessIterator2 result,
     268                                      utility::weighted_iterator_tag tag) const
     269  {
     270    // copy the weights
     271    std::copy(utility::weight_iterator<RandomAccessIterator1>(first),
     272              utility::weight_iterator<RandomAccessIterator1>(last),
     273              utility::weight_iterator<RandomAccessIterator2>(result));
     274    // apply algorithm on data part of range
     275    normalize(source, utility::data_iterator<RandomAccessIterator1>(first),
     276              utility::data_iterator<RandomAccessIterator1>(last),
     277              utility::data_iterator<RandomAccessIterator2>(result),
     278              utility::unweighted_iterator_tag());
     279  }
     280
     281
    235282  template<typename BidirectionalIterator>
    236283  qQuantileNormalizer::Partitioner::Partitioner(BidirectionalIterator first,
Note: See TracChangeset for help on using the changeset viewer.