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

Last change on this file since 1274 was 1000, checked in by Jari Häkkinen, 14 years ago

trac moved to new location.

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