source: trunk/src/InputRanker.cc @ 89

Last change on this file since 89 was 89, checked in by Peter, 19 years ago

InputRanker? added

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.3 KB
Line 
1// $Id: InputRanker.cc 89 2004-05-28 17:44:42Z peter $
2
3// Thep C++ Tools
4#include "InputRanker.h"
5#include "ROC.h"
6#include "matrix.h"
7#include "vector.h"
8#include "stl_utility.h"
9
10#include <vector>
11#include <utility>
12
13namespace theplu {
14namespace cpptools { 
15
16InputRanker::InputRanker(const gslapi::matrix& data, 
17                         const gslapi::vector& target, 
18                         const std::vector<size_t> train_set)
19  :train_set_(train_set),
20   id_(std::vector<size_t>(data.rows())),
21   rank_(std::vector<size_t>(data.rows()))
22 
23{
24  using namespace std;
25  // Peter, this copying and transposing is done since it seems
26  // problematic to get a column vector from a matrix
27  gslapi::matrix data_transposed = data;
28  data_transposed.transpose();
29 
30  size_t nof_genes = data_transposed.rows();
31  size_t nof_samples = data_transposed.columns();
32  if (!train_set_.size())
33    for (size_t i=0; i<nof_samples; i++)
34      train_set_.push_back(i); 
35
36  //scoring each gene
37  std::vector<pair<size_t, double> > score;
38  for (size_t i=0; i<nof_genes; i++){
39    ROC roc(data_transposed[train_set_[i]], target);
40    std::pair<size_t, double> tmp(i,roc.area());
41    score.push_back(tmp);
42  }
43  //sort the scores and assign id_ and rank_
44  sort(score.begin(), score.end(), 
45       pair_value_compare<size_t, double>());
46 
47  for (size_t i=0; i<nof_genes; i++){
48    id_[i]=score[i].first;
49    rank_[id_[i]]=i;
50  }
51 
52 
53}
54
55}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.