Changeset 1432


Ignore:
Timestamp:
Aug 25, 2008, 3:54:18 PM (15 years ago)
Author:
Peter
Message:

refs #416 moving quantile normalizer to new dir. Also moved the algorithm to a class (rather than free function).

Location:
trunk
Files:
2 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r1420 r1432  
    4141  knn_test matrix_lookup_test matrix_test \
    4242  nbc_test \
    43   ncc_test nni_test pca_test range_test regression_test rnd_test roc_test \
     43  ncc_test nni_test normalization_test pca_test \
     44  range_test regression_test rnd_test roc_test \
    4445  score_test  smart_ptr_test    \
    4546  statistics_test subset_generator_test svd_test svm_test target_test \
  • trunk/test/Suite.h

    r1360 r1432  
    2626
    2727#include <fstream>
     28#include <iostream>
    2829#include <sstream>
    2930
  • trunk/test/utility_test.cc

    r1385 r1432  
    3737
    3838using namespace theplu::yat;
    39 void test_quantile_normalize(test::Suite&);
    4039void test_inverse(test::Suite&);
    4140
     
    151150  }
    152151
    153   test_quantile_normalize(suite);
    154152  test_inverse(suite);
    155153
     
    218216 
    219217}
    220 
    221 
    222 void test_quantile_normalize(test::Suite& suite)
    223 {
    224   suite.err() << "Testing quantile normalization\n";
    225  
    226   utility::Matrix m(2,2);
    227   m(0,0) = 0;
    228   m(0,1) = 10;
    229   m(1,0) = 2;
    230   m(1,1) = 4;
    231   utility::quantile_normalize(m);
    232   suite.err() << "Testing m(0,0)\n";
    233   suite.add(suite.equal(m(0,0), 2));
    234   suite.err() << "Testing m(0,1)\n";
    235   suite.add(suite.equal(m(0,1), 6));
    236   suite.err() << "Testing m(1,0)\n";
    237   suite.add(suite.equal(m(1,0), 6));
    238   suite.err() << "Testing m(1,1)\n";
    239   suite.add(suite.equal(m(1,1), 2));
    240 
    241 }
  • trunk/yat/normalization/Makefile.am

    r1429 r1432  
    2525
    2626noinst_LTLIBRARIES = libnormalization.la
    27 libnormalization_la_SOURCES =
     27libnormalization_la_SOURCES = QuantileNormalizer.cc
    2828
    2929include_normalizationdir = $(includedir)/yat/normalization
    3030
    31 include_normalization_HEADERS =
     31include_normalization_HEADERS = QuantileNormalizer.h
  • trunk/yat/normalization/QuantileNormalizer.cc

    r1430 r1432  
    44  Copyright (C) 2005, 2006 Jari Häkkinen, Markus Ringnér
    55  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2008 Peter Johansson
    67
    7   This file is part of the yat library, http://trac.thep.lu.se/yat
     8  This file is part of the yat library, http://dev.thep.lu.se/yat
    89
    910  The yat library is free software; you can redistribute it and/or
     
    2324*/
    2425
    25 #include "utility.h"
     26#include "QuantileNormalizer.h"
    2627
    27 #include "Matrix.h"
    28 #include "stl_utility.h"
    29 #include "VectorConstView.h"
    3028#include "yat/statistics/Averager.h"
    3129
    32 #include <sstream>
    33 #include <string>
     30#include "yat/utility/Matrix.h"
     31#include "yat/utility/VectorConstView.h"
    3432
    3533namespace theplu {
    3634namespace yat {
    37 namespace utility {
     35namespace normalization {
    3836
    39   bool is_double(const std::string& s)
     37  void QuantileNormalizer::operator()(utility::Matrix& data) const
    4038  {
    41     return is<double>(s);
    42   }
    43  
    44 
    45   bool is_equal(std::string s, std::string other)
    46   {
    47     std::stringstream ss(s);
    48     std::string s2;
    49     ss >> s2; // to trim surrounding whitespaces
    50     to_lower(s2);
    51     // Check that nothing is left on stream
    52     std::string s3;
    53     ss >> s3;
    54     if(s3.size())
    55       return false;
    56     return (other==s2);
    57   }
    58 
    59 
    60   bool is_float(const std::string& s)
    61   {
    62     return is<float>(s);
    63   }
    64 
    65 
    66   bool is_int(const std::string& s)
    67   {
    68     return is<int>(s);
    69   }
    70 
    71   bool is_nan(const std::string& s)
    72   {
    73     return is_equal(s, "nan");
    74   }
    75 
    76 
    77   void quantile_normalize(Matrix& data)
    78   {
    79     Matrix data_copy(data);
     39    utility::Matrix data_copy(data);
    8040   
    8141    // sort columns in copy
     
    9252    for (size_t column=0; column<data.columns(); ++column){
    9353      std::vector<size_t> index;
    94       yat::utility::sort_index(index, data.column_const_view(column));
     54      utility::sort_index(index, data.column_const_view(column));
    9555                               
    9656      for (size_t row=0; row<data.rows(); ++row)
  • trunk/yat/utility/utility.cc

    r1419 r1432  
    7575
    7676
    77   void quantile_normalize(Matrix& data)
    78   {
    79     Matrix data_copy(data);
    80    
    81     // sort columns in copy
    82     for (size_t column=0; column<data_copy.columns(); ++column){
    83       std::sort(data_copy.begin_column(column), data_copy.end_column(column));
    84     }
    85 
    86     // calculate average of each row
    87     std::vector<yat::statistics::Averager> averager(data_copy.rows());
    88     for (size_t row=0; row<data_copy.rows(); ++row){
    89       add(averager[row], data_copy.begin_row(row), data_copy.end_row(row));
    90     }
    91 
    92     for (size_t column=0; column<data.columns(); ++column){
    93       std::vector<size_t> index;
    94       yat::utility::sort_index(index, data.column_const_view(column));
    95                                
    96       for (size_t row=0; row<data.rows(); ++row)
    97         data(index[row], column) = averager[row].mean();
    98     }
    99   }
    100 
    101 
    102 
    10377}}} // end of namespace utility, yat and thep
  • trunk/yat/utility/utility.h

    r1401 r1432  
    9898  bool is_nan(const std::string& s);
    9999
    100   /**
    101      \brief Perform quantile normalization
    102 
    103      \since New in yat 0.5
    104    */
    105   void quantile_normalize(Matrix&);
    106 
    107100  // template implementations
    108101  template<typename T>
Note: See TracChangeset for help on using the changeset viewer.