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

quantile normalization closes #288

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.