source: trunk/yat/classifier/InputRanker.cc

Last change on this file was 2919, checked in by Peter, 9 years ago

update copyright years

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