source: trunk/c++_tools/classifier/InputRanker.cc @ 675

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

References #83. Changing project name to yat. Compilation will fail in this revision.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.8 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 "yat/classifier/InputRanker.h"
25
26#include "yat/classifier/MatrixLookup.h"
27#include "yat/classifier/MatrixLookupWeighted.h"
28#include "yat/classifier/DataLookup1D.h"
29#include "yat/classifier/DataLookupWeighted1D.h"
30#include "yat/classifier/Target.h"
31#include "yat/statistics/ROC.h"
32#include "yat/utility/stl_utility.h"
33
34#include <functional>
35#include <utility>
36#include <vector>
37
38#include <cmath>
39
40namespace theplu {
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
73  InputRanker::InputRanker(const MatrixLookupWeighted& data, 
74                           const Target& target, 
75                           statistics::Score& score_object)
76  {
77    assert(data.columns()==target.size());
78    size_t nof_genes = data.rows();
79
80    //scoring each input
81    std::vector<std::pair<double, size_t> > score;
82    for (size_t i=0; i<nof_genes; i++) {
83      double area=score_object.score(target,DataLookupWeighted1D(data,i,true));
84      score.push_back(std::make_pair(area,i));
85    }
86
87    //sort the scores and assign id_ and rank_
88    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
89   
90    id_.resize(nof_genes);
91    rank_.resize(nof_genes);
92    for (size_t i=0; i<nof_genes; i++){
93      id_[i]=score[i].second;
94      score_[i]=score[i].first;
95      rank_[id_[i]]=i;           
96    }
97  }
98
99
100
101}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.