1 | #ifndef _theplu_classifier_consensusinputranker_ |
---|
2 | #define _theplu_classifier_consensusinputranker_ |
---|
3 | |
---|
4 | // $Id$ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) The authors contributing to this file. |
---|
8 | |
---|
9 | This file is part of the yat library, http://lev.thep.lu.se/trac/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 "yat/classifier/InputRanker.h"! |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | |
---|
31 | class statistics::Score; |
---|
32 | |
---|
33 | namespace classifier { |
---|
34 | |
---|
35 | class IRRetrieve; |
---|
36 | class MatrixLookup; |
---|
37 | class MatrixLookupWeighted; |
---|
38 | class Sampler; |
---|
39 | |
---|
40 | /// |
---|
41 | /// @brief Robust algorithm to rank rows in a data matrix versus a |
---|
42 | /// target vector. |
---|
43 | /// |
---|
44 | /// The idea is to create several (different) ranked lists. The list |
---|
45 | /// could be different because they are based upon different |
---|
46 | /// sub-sets of the data, or the different lists could be different |
---|
47 | /// because they have are generated using different criteria. Having |
---|
48 | /// \f$ N \f$ lists means each row in the data matrix has \f$ N \f$ |
---|
49 | /// ranks (each corresponding to one list) and a consensus ranked |
---|
50 | /// list is created by sorting the data rows with respect to their |
---|
51 | /// median rank. |
---|
52 | /// |
---|
53 | /// For the time being there are two ways to build a |
---|
54 | /// ConsensusInputRanker. 1) Sending a Sampler and a MatrixLookup to |
---|
55 | /// the constructor will create one ranked list for each of the |
---|
56 | /// partitions defined in the Sampler. 2) You can generate |
---|
57 | /// your ranked list outside, using your favourite method, and |
---|
58 | /// adding it into the ConsensusInputRanker object. This allows |
---|
59 | /// combining different scores and different sub-sets in a more |
---|
60 | /// general way. |
---|
61 | /// |
---|
62 | class ConsensusInputRanker |
---|
63 | { |
---|
64 | |
---|
65 | public: |
---|
66 | |
---|
67 | /// |
---|
68 | /// @brief Default constructor |
---|
69 | /// |
---|
70 | /// Truly does nothing but creates a few empty member vectors. |
---|
71 | /// |
---|
72 | ConsensusInputRanker(const IRRetrieve&); |
---|
73 | |
---|
74 | /// |
---|
75 | /// Iterating through @a sampler creating subsets of @a data, and |
---|
76 | /// for each subset is an InputRanker is created using the @a |
---|
77 | /// score. After creation the data rows are sorted with respect to |
---|
78 | /// the median rank (i.e. update() is called). |
---|
79 | /// |
---|
80 | ConsensusInputRanker(const Sampler& sampler, const MatrixLookup&, |
---|
81 | statistics::Score& s, const IRRetrieve&); |
---|
82 | |
---|
83 | /// |
---|
84 | /// Iterating through @a sampler creating subsets of @a data, and |
---|
85 | /// for each subset is an InputRanker is created using the @a |
---|
86 | /// score. After creation the data rows are sorted with respect to |
---|
87 | /// the median rank (i.e. update() is called). |
---|
88 | /// |
---|
89 | ConsensusInputRanker(const Sampler& sampler, |
---|
90 | const MatrixLookupWeighted& data, |
---|
91 | statistics::Score& score, const IRRetrieve&); |
---|
92 | |
---|
93 | /// |
---|
94 | /// @brief add an InputRanker |
---|
95 | /// |
---|
96 | /// @note update() must be called to make the added InputRanker to |
---|
97 | /// influence consensus ids and ranks. If a sequence of |
---|
98 | /// InputRankers are added, update() need to be called only after |
---|
99 | /// the last InputRanker is added. |
---|
100 | /// |
---|
101 | inline void add(const InputRanker& ir) { input_rankers_.push_back(ir); } |
---|
102 | |
---|
103 | /// |
---|
104 | /// Row with lowest rank (highest score) is ranked as number zero |
---|
105 | /// @return index of row ranked as number \a i |
---|
106 | /// |
---|
107 | inline size_t id(const size_t i) const { return id_[i]; } |
---|
108 | |
---|
109 | /// |
---|
110 | /// Row with lowest rank (highest score) is ranked as number zero |
---|
111 | /// @return rank for row \a i |
---|
112 | /// |
---|
113 | inline size_t rank(const size_t i) const { return rank_[i]; } |
---|
114 | |
---|
115 | /// |
---|
116 | /// update ids and ranks |
---|
117 | /// |
---|
118 | void update(void); |
---|
119 | |
---|
120 | |
---|
121 | private: |
---|
122 | |
---|
123 | std::vector<size_t> id_; |
---|
124 | std::vector<InputRanker> input_rankers_; |
---|
125 | std::vector<size_t> rank_; |
---|
126 | const IRRetrieve& retriever_; |
---|
127 | |
---|
128 | }; |
---|
129 | |
---|
130 | }} // of namespace classifier and namespace theplu |
---|
131 | |
---|
132 | #endif |
---|