source: trunk/lib/classifier/InputRanker.cc @ 536

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

fixed problem with ConsensusInputranker? - Now all tests do pass

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