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

Last change on this file since 720 was 720, checked in by Jari Häkkinen, 15 years ago

Fixes #170. Almost all inlines removed, some classes have no cc file.

  • 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/ROC.h"
31#include "yat/utility/stl_utility.h"
32
33#include <cmath>
34#include <functional>
35#include <utility>
36#include <vector>
37
38namespace theplu {
39namespace yat {
40namespace classifier { 
41
42
43  InputRanker::InputRanker(const MatrixLookup& data, 
44                           const Target& target, 
45                           statistics::Score& score_object)
46  {
47    assert(data.columns()==target.size());
48    size_t nof_genes = data.rows();
49
50    //scoring each input
51    std::vector<std::pair<double, size_t> > score;
52    for (size_t i=0; i<nof_genes; i++) {
53      double area = score_object.score(target,DataLookup1D(data,i,true));
54      score.push_back(std::make_pair(area,i));
55    }
56
57    //sort the scores and assign id_ and rank_
58    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
59   
60    id_.resize(nof_genes);
61    rank_.resize(nof_genes);
62    score_.resize(nof_genes);
63    for (size_t i=0; i<nof_genes; i++){
64      id_[i]=score[i].second;
65      score_[i]=score[i].first;
66      rank_[id_[i]]=i;           
67    }
68  }
69
70
71  InputRanker::InputRanker(const MatrixLookupWeighted& data, 
72                           const Target& target, 
73                           statistics::Score& score_object)
74  {
75    assert(data.columns()==target.size());
76    size_t nof_genes = data.rows();
77
78    //scoring each input
79    std::vector<std::pair<double, size_t> > score;
80    for (size_t i=0; i<nof_genes; i++) {
81      double area=score_object.score(target,DataLookupWeighted1D(data,i,true));
82      score.push_back(std::make_pair(area,i));
83    }
84
85    //sort the scores and assign id_ and rank_
86    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
87   
88    id_.resize(nof_genes);
89    rank_.resize(nof_genes);
90    for (size_t i=0; i<nof_genes; i++){
91      id_[i]=score[i].second;
92      score_[i]=score[i].first;
93      rank_[id_[i]]=i;           
94    }
95  }
96
97
98  const std::vector<size_t>& InputRanker::id(void) const
99  {
100    return id_;
101  }
102
103
104  const std::vector<size_t>& InputRanker::rank(void) const
105  {
106    return rank_;
107  }
108
109
110  double InputRanker::score(size_t rank) const
111  {
112    return score_[rank];
113  }
114
115}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.