source: trunk/src/InputRanker.cc @ 120

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

modified to handle weights

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1// $Id: InputRanker.cc 120 2004-07-20 16:25:29Z 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, train_set_); 
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
55InputRanker::InputRanker(const gslapi::matrix& data, 
56                         const gslapi::vector& target, 
57                         const gslapi::matrix& weight, 
58                         Score& score_object,
59                         const std::vector<size_t>& train_set)
60  :train_set_(train_set),
61   id_(std::vector<size_t>(data.rows())),
62   rank_(std::vector<size_t>(data.rows()))
63 
64{
65  using namespace std;
66  // Peter, this copying and transposing is done since it seems
67  // problematic to get a column vector from a matrix
68  gslapi::matrix data_transposed = data;
69  data_transposed.transpose();
70  gslapi::matrix weight_transposed = weight;
71  weight_transposed.transpose();
72 
73  size_t nof_genes = data_transposed.rows();
74  size_t nof_samples = data_transposed.columns();
75  if (!train_set_.size()){
76    train_set_.resize(nof_samples);
77    for (size_t i=0; i<nof_samples; i++)
78      train_set_[i]=i; 
79  }
80  //scoring each input
81  std::vector<pair<size_t, double> > score;
82  for (size_t i=0; i<nof_genes; i++){ 
83    double area = score_object.score(data_transposed[i], target, 
84                                     weight_transposed[i], train_set_); 
85    std::pair<size_t, double> tmp(i,area);
86    score.push_back(tmp);
87  }
88  //sort the scores and assign id_ and rank_
89  sort(score.begin(), score.end(), 
90       pair_value_compare<size_t, double>());
91 
92  for (size_t i=0; i<nof_genes; i++){
93    id_[i]=score[i].first;
94    rank_[id_[i]]=i;           
95  }
96}
97 
98}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.