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

Last change on this file since 1580 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.1 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2004 Peter Johansson
5  Copyright (C) 2005 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
7
8  This file is part of the yat library, http://dev.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with yat. If not, see <http://www.gnu.org/licenses/>.
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                           const 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                           const 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    score_.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  const std::vector<size_t>& InputRanker::id(void) const
101  {
102    return id_;
103  }
104
105
106  const std::vector<size_t>& InputRanker::rank(void) const
107  {
108    return rank_;
109  }
110
111
112  double InputRanker::score(size_t rank) const
113  {
114    return score_[rank];
115  }
116
117}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.