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

Last change on this file since 560 was 560, checked in by Markus Ringnér, 16 years ago

Minor fixes plus fixed bug in ConsensusInputRanker?

  • 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 560 2006-03-13 14:36:54Z markus $
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#include <cmath>
16
17namespace theplu {
18namespace classifier { 
19
20
21  InputRanker::InputRanker(const DataLookup2D& data, 
22                           const Target& target, 
23                           statistics::Score& score_object)
24  {
25    assert(data.columns()==target.size());
26 
27    size_t nof_genes = data.rows();
28
29    //scoring each input
30    std::vector<std::pair<double, size_t> > score;
31    for (size_t i=0; i<nof_genes; i++) {
32      double area = score_object.score(target,DataLookup1D(data,i,true));
33      // Peter, remove stupid tmp
34      std::pair<double, size_t> tmp(area,i);
35      score.push_back(tmp);
36    }
37
38    //sort the scores and assign id_ and rank_
39    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
40   
41    id_.resize(nof_genes);
42    rank_.resize(nof_genes);
43    for (size_t i=0; i<nof_genes; i++){
44      id_[i]=score[i].second;
45      rank_[id_[i]]=i;           
46    }
47  }
48
49
50
51  InputRanker::InputRanker(const DataLookup2D& data, 
52                           const Target& target, 
53                           statistics::Score& score_object,
54                           const MatrixLookup& weight)
55  {
56    size_t nof_genes = data.rows();
57
58    //scoring each input
59    std::vector<std::pair<double, size_t> > score;
60    for (size_t i=0; i<nof_genes; i++) {
61      double area = score_object.score(target, DataLookup1D(data,i,true),
62                                       DataLookup1D(weight,i,true));     
63      assert(!std::isnan(area));
64      std::pair<double, size_t> tmp(area,i);
65      score.push_back(tmp);
66    }
67
68    //sort the scores and assign id_ and rank_
69    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
70
71    id_.resize(nof_genes);
72    rank_.resize(nof_genes);
73    for (size_t i=0; i<nof_genes; i++){
74      id_[i]=score[i].second;
75      rank_[id_[i]]=i;           
76    }
77
78  }
79
80
81}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.