Changeset 1304


Ignore:
Timestamp:
May 14, 2008, 10:11:57 PM (13 years ago)
Author:
Peter
Message:

quantile normalization closes #288

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Suite.cc

    r1249 r1304  
    6262
    6363
    64   void Suite::add(bool ok)
     64  bool Suite::add(bool ok)
    6565  {
    6666    ok_ = ok_ && ok;
     67    return ok;
    6768  }
    6869
  • trunk/test/Suite.h

    r1249 r1304  
    4545    /**
    4646       set ok to 'b && ok'
     47
     48       \return b
    4749    */
    48     void add(bool b);
     50    bool add(bool b);
    4951
    5052    /**
  • trunk/test/utility_test.cc

    r1289 r1304  
    2626#include "Suite.h"
    2727
     28#include "yat/utility/Matrix.h"
    2829#include "yat/utility/utility.h"
    2930#include "yat/utility/stl_utility.h"
     
    3233#include <iostream>
    3334#include <string>
     35
     36using namespace theplu::yat;
     37void test_quantile_normalize(test::Suite&);
    3438
    3539int main(int argc, char* argv[])
     
    113117  }
    114118
     119  test_quantile_normalize(suite);
     120
    115121  return suite.return_value();
    116122}
     123
     124void test_quantile_normalize(test::Suite& suite)
     125{
     126  suite.err() << "Testing quantile normalization\n";
     127 
     128  utility::Matrix m(2,2);
     129  m(0,0) = 0;
     130  m(0,1) = 10;
     131  m(1,0) = 2;
     132  m(1,1) = 4;
     133  utility::quantile_normalize(m);
     134  suite.err() << "Testing m(0,0)\n";
     135  suite.add(suite.equal(m(0,0), 2));
     136  suite.err() << "Testing m(0,1)\n";
     137  suite.add(suite.equal(m(0,1), 6));
     138  suite.err() << "Testing m(1,0)\n";
     139  suite.add(suite.equal(m(1,0), 6));
     140  suite.err() << "Testing m(1,1)\n";
     141  suite.add(suite.equal(m(1,1), 2));
     142
     143}
  • trunk/yat/utility/utility.cc

    r1275 r1304  
    2525#include "utility.h"
    2626
     27#include "Matrix.h"
    2728#include "stl_utility.h"
     29#include "VectorConstView.h"
     30#include "yat/statistics/Averager.h"
    2831
    2932#include <sstream>
     
    102105
    103106
     107  void quantile_normalize(Matrix& data)
     108  {
     109    Matrix data_copy(data);
     110   
     111    // sort columns in copy
     112    for (size_t column=0; column<data_copy.columns(); ++column){
     113      std::sort(data_copy.begin_column(column), data_copy.end_column(column));
     114    }
     115
     116    // calculate average of each row
     117    std::vector<yat::statistics::Averager> averager(data_copy.rows());
     118    for (size_t row=0; row<data_copy.rows(); ++row){
     119      add(averager[row], data_copy.begin_row(row), data_copy.end_row(row));
     120    }
     121
     122    for (size_t column=0; column<data.columns(); ++column){
     123      std::vector<size_t> index;
     124      const VectorConstView col_vec(data,column,false);
     125      yat::utility::sort_index(index, data.column_const_view(column));
     126                               
     127      for (size_t row=0; row<data.rows(); ++row)
     128        data(index[row], column) = averager[row].mean();
     129    }
     130  }
     131
     132
    104133
    105134}}} // end of namespace utility, yat and thep
  • trunk/yat/utility/utility.h

    r1275 r1304  
    4444namespace utility {
    4545
    46   class vector;
     46  class Matrix;
    4747
    4848  /**
     
    8181  bool is_nan(const std::string& s);
    8282
     83  /**
     84     \brief Perform quantile normalization
     85   */
     86  void quantile_normalize(Matrix&);
    8387
    8488  // template implementations
Note: See TracChangeset for help on using the changeset viewer.