source: trunk/yat/classifier/InputRanker.cc @ 781

Last change on this file since 781 was 781, checked in by Peter, 15 years ago

changing name to ROCScore and also added some cassert includes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.0 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "InputRanker.h"
25#include "MatrixLookup.h"
26#include "MatrixLookupWeighted.h"
27#include "DataLookup1D.h"
28#include "DataLookupWeighted1D.h"
29#include "Target.h"
30#include "yat/statistics/Score.h"
31#include "yat/utility/stl_utility.h"
32
33#include <cassert>
34#include <cmath>
35#include <functional>
36#include <utility>
37#include <vector>
38
39namespace theplu {
40namespace yat {
41namespace classifier { 
42
43
44  InputRanker::InputRanker(const MatrixLookup& data, 
45                           const Target& target, 
46                           statistics::Score& score_object)
47  {
48    assert(data.columns()==target.size());
49    size_t nof_genes = data.rows();
50
51    //scoring each input
52    std::vector<std::pair<double, size_t> > score;
53    for (size_t i=0; i<nof_genes; i++) {
54      double area = score_object.score(target,DataLookup1D(data,i,true));
55      score.push_back(std::make_pair(area,i));
56    }
57
58    //sort the scores and assign id_ and rank_
59    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
60   
61    id_.resize(nof_genes);
62    rank_.resize(nof_genes);
63    score_.resize(nof_genes);
64    for (size_t i=0; i<nof_genes; i++){
65      id_[i]=score[i].second;
66      score_[i]=score[i].first;
67      rank_[id_[i]]=i;           
68    }
69  }
70
71
72  InputRanker::InputRanker(const MatrixLookupWeighted& data, 
73                           const Target& target, 
74                           statistics::Score& score_object)
75  {
76    assert(data.columns()==target.size());
77    size_t nof_genes = data.rows();
78
79    //scoring each input
80    std::vector<std::pair<double, size_t> > score;
81    for (size_t i=0; i<nof_genes; i++) {
82      double area=score_object.score(target,DataLookupWeighted1D(data,i,true));
83      score.push_back(std::make_pair(area,i));
84    }
85
86    //sort the scores and assign id_ and rank_
87    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
88   
89    id_.resize(nof_genes);
90    rank_.resize(nof_genes);
91    for (size_t i=0; i<nof_genes; i++){
92      id_[i]=score[i].second;
93      score_[i]=score[i].first;
94      rank_[id_[i]]=i;           
95    }
96  }
97
98
99  const std::vector<size_t>& InputRanker::id(void) const
100  {
101    return id_;
102  }
103
104
105  const std::vector<size_t>& InputRanker::rank(void) const
106  {
107    return rank_;
108  }
109
110
111  double InputRanker::score(size_t rank) const
112  {
113    return score_[rank];
114  }
115
116}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.