Ignore:
Timestamp:
Sep 17, 2008, 10:56:30 PM (14 years ago)
Author:
Peter
Message:

fixes #437 and added support for having known issues in test::Suite

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization_test.cc

    r1497 r1509  
    2424#include "yat/normalizer/Centralizer.h"
    2525#include "yat/normalizer/ColumnNormalizer.h"
     26#include "yat/utility/DataIterator.h"
    2627#include "yat/normalizer/QuantileNormalizer.h"
    2728#include "yat/normalizer/Spearman.h"
    2829
     30#include "yat/utility/DataIterator.h"
    2931#include "yat/utility/Matrix.h"
     32#include "yat/utility/MatrixWeighted.h"
     33#include "yat/utility/WeightIterator.h"
    3034
     35#include <limits>
    3136#include <vector>
    3237
     
    3641void test_quantile_normalize(test::Suite&);
    3742void test_spearman(test::Suite&);
     43void test_spearman_weighted(test::Suite&);
    3844
    3945int main(int argc, char* argv[])
     
    124130  correct.push_back(0.25);
    125131  suite.equal_range(vec.begin(), vec.end(), correct.begin());
     132  test_spearman_weighted(suite);
    126133}
     134
     135
     136void test_spearman_weighted(test::Suite& suite)
     137{
     138  suite.err() << "Testing Weighted Spearman\n";
     139  normalizer::Spearman spearman;
     140
     141  suite.err() << "Testing that unity weights reproduces unweighted case\n";
     142  utility::MatrixWeighted m(1,4,0,1);
     143  utility::MatrixWeighted res(m.rows(), m.columns(),3.14,0);
     144  m(0,0).data()=0;
     145  m(0,1).data()=2;
     146  m(0,2).data()=3;
     147  m(0,3).data()=1;
     148  std::vector<double> correct(m.columns());
     149  std::vector<double> correct_w(m.columns(), 1.0);
     150  std::copy(utility::data_iterator(m.begin_row(0)),
     151            utility::data_iterator(m.end_row(0)),
     152            correct.begin());
     153  spearman(correct.begin(), correct.end(), correct.begin());
     154  spearman(m.begin_row(0), m.end_row(0), res.begin_row(0));
     155
     156  using utility::data_iterator;
     157  suite.add(suite.equal_range(data_iterator(res.begin_row(0)),
     158                               data_iterator(res.end_row(0)),
     159                               correct.begin()));
     160  using utility::weight_iterator;
     161  suite.add(suite.equal_range(weight_iterator(res.begin_row(0)),
     162                               weight_iterator(res.end_row(0)),
     163                               correct_w.begin()));
     164
     165  suite.err() << "Testing rescaling of weights\n";
     166  for (size_t i=0; i<m.columns(); ++i) {
     167    m(0,i).weight() *= 2;
     168    correct_w[i] *= 2;
     169  }   
     170  spearman(m.begin_row(0), m.end_row(0), res.begin_row(0));
     171  suite.add(suite.equal_range(data_iterator(res.begin_row(0)),
     172                               data_iterator(res.end_row(0)),
     173                               correct.begin()));
     174  suite.add(suite.equal_range(weight_iterator(res.begin_row(0)),
     175                               weight_iterator(res.end_row(0)),
     176                               correct_w.begin()));
     177
     178 
     179  suite.err() << "Testing case with a zero weight\n";
     180  m(0,1).data() = std::numeric_limits<double>::quiet_NaN();
     181  m(0,1).weight() = 0.0;
     182  spearman(m.begin_row(0), m.end_row(0), res.begin_row(0));
     183  suite.add(suite.equal(res(0,0).data(), 0));
     184  suite.add(suite.equal(res(0,2).data(), 2.0/3));
     185  suite.add(suite.equal(res(0,3).data(), 1.0/3));
     186}
Note: See TracChangeset for help on using the changeset viewer.