source: branches/peters_vector/lib/classifier/InputRanker.cc @ 469

Last change on this file since 469 was 469, checked in by Peter, 16 years ago

non compiling checking before revision after design meeting

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1// $Id: InputRanker.cc 469 2005-12-19 14:58:29Z peter $
2
3#include <c++_tools/classifier/InputRanker.h>
4
5#include <c++_tools/classifier/DataView.h>
6#include <c++_tools/classifier/VectorView.h>
7#include <c++_tools/classifier/Target.h>
8#include <c++_tools/statistics/ROC.h>
9#include <c++_tools/utility/stl_utility.h>
10
11#include <vector>
12#include <utility>
13
14namespace theplu {
15namespace classifier { 
16
17
18  InputRanker::InputRanker(const DataView& data, 
19                           const Target& target, 
20                           statistics::Score& score_object)
21  {
22    size_t nof_genes = data.rows();
23    size_t nof_samples = data.columns();
24    if (!train_set_.size()){
25      train_set_.resize(nof_samples);
26      for (size_t i=0; i<nof_samples; i++)
27        train_set_[i]=i; 
28    }
29
30    //scoring each input
31    std::vector<std::pair<size_t, double> > score;
32    for (size_t i=0; i<nof_genes; i++) {
33      double area = score_object.score(target,VectorView(data,i,false));
34      std::pair<size_t, double> tmp(i,area);
35      score.push_back(tmp);
36    }
37
38    //sort the scores and assign id_ and rank_
39    sort(score.begin(), score.end(), 
40         utility::pair_value_compare<size_t, double>());
41   
42    for (size_t i=0; i<nof_genes; i++){
43      id_[i]=score[nof_genes-i-1].first;
44      rank_[id_[i]]=i;           
45    }
46  }
47
48
49
50  InputRanker::InputRanker(const DataView& data, 
51                           const Target& target, 
52                           statistics::Score& score_object,
53                           const DataView& weight)
54  {
55    size_t nof_genes = data.rows();
56    size_t nof_samples = data.columns();
57    if (!train_set_.size()){
58      train_set_.resize(nof_samples);
59      for (size_t i=0; i<nof_samples; i++)
60        train_set_[i]=i; 
61    }
62    //scoring each input
63    std::vector<std::pair<size_t, double> > score;
64    for (size_t i=0; i<nof_genes; i++) {
65      double area = score_object.score(target, VectorView(data,i,false),
66                                       VectorView(weight,i,false));
67      std::pair<size_t, double> tmp(i,area);
68      score.push_back(tmp);
69    }
70    //sort the scores and assign id_ and rank_
71    sort(score.begin(), score.end(), 
72         utility::pair_value_compare<size_t, double>());
73
74    for (size_t i=0; i<nof_genes; i++){
75      id_[i]=score[nof_genes-i-1].first;
76      rank_[id_[i]]=i;           
77    }
78  }
79
80
81}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.