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

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

Addresses #153. Introduced yat namespace. Removed alignment namespace. Clean up of code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.7 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
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
100}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.