source: trunk/src/InputRanker.cc @ 108

Last change on this file since 108 was 108, checked in by Peter, 18 years ago

modified the interface to be able to use any Score object

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 KB
Line 
1// $Id: InputRanker.cc 108 2004-06-16 13:08:09Z 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                         Score& score_object,
19                         const std::vector<size_t>& train_set)
20  :train_set_(train_set),
21   id_(std::vector<size_t>(data.rows())),
22   rank_(std::vector<size_t>(data.rows()))
23 
24{
25  using namespace std;
26  // Peter, this copying and transposing is done since it seems
27  // problematic to get a column vector from a matrix
28  gslapi::matrix data_transposed = data;
29  data_transposed.transpose();
30 
31  size_t nof_genes = data_transposed.rows();
32  size_t nof_samples = data_transposed.columns();
33  if (!train_set_.size()){
34    train_set_.resize(nof_samples);
35    for (size_t i=0; i<nof_samples; i++)
36      train_set_[i]=i; 
37  }
38  //scoring each input
39  std::vector<pair<size_t, double> > score;
40  for (size_t i=0; i<nof_genes; i++){ 
41    double area = score_object.score(data_transposed[i], target); 
42    std::pair<size_t, double> tmp(i,area);
43    score.push_back(tmp);
44  }
45  //sort the scores and assign id_ and rank_
46  sort(score.begin(), score.end(), 
47       pair_value_compare<size_t, double>());
48 
49  for (size_t i=0; i<nof_genes; i++){
50    id_[i]=score[i].first;
51    rank_[id_[i]]=i;           
52  }
53}
54 
55}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.