4200 |
19 Aug 22 |
peter |
1 |
#ifndef _theplu_yat_classifier_consensusinputranker_ |
4200 |
19 Aug 22 |
peter |
2 |
#define _theplu_yat_classifier_consensusinputranker_ |
115 |
19 Jul 04 |
peter |
3 |
|
675 |
10 Oct 06 |
jari |
// $Id$ |
115 |
19 Jul 04 |
peter |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2004, 2005 Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
675 |
10 Oct 06 |
jari |
11 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
13 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
18 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
23 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
26 |
*/ |
675 |
10 Oct 06 |
jari |
27 |
|
680 |
11 Oct 06 |
jari |
28 |
#include "InputRanker.h" |
675 |
10 Oct 06 |
jari |
29 |
|
828 |
19 Mar 07 |
peter |
30 |
#include <vector> |
828 |
19 Mar 07 |
peter |
31 |
|
115 |
19 Jul 04 |
peter |
32 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
33 |
namespace yat { |
828 |
19 Mar 07 |
peter |
34 |
namespace statistics { |
828 |
19 Mar 07 |
peter |
35 |
class Score; |
828 |
19 Mar 07 |
peter |
36 |
class VectorFunction; |
828 |
19 Mar 07 |
peter |
37 |
} |
4200 |
19 Aug 22 |
peter |
38 |
namespace classifier { |
115 |
19 Jul 04 |
peter |
39 |
|
667 |
06 Oct 06 |
peter |
40 |
class IRRetrieve; |
615 |
31 Aug 06 |
peter |
41 |
class MatrixLookup; |
615 |
31 Aug 06 |
peter |
42 |
class MatrixLookupWeighted; |
615 |
31 Aug 06 |
peter |
43 |
class Sampler; |
475 |
22 Dec 05 |
peter |
44 |
|
592 |
24 Aug 06 |
peter |
45 |
/// |
592 |
24 Aug 06 |
peter |
/// @brief Robust algorithm to rank rows in a data matrix versus a |
4200 |
19 Aug 22 |
peter |
/// target vector. |
592 |
24 Aug 06 |
peter |
48 |
/// |
592 |
24 Aug 06 |
peter |
/// The idea is to create several (different) ranked lists. The list |
592 |
24 Aug 06 |
peter |
/// could be different because they are based upon different |
592 |
24 Aug 06 |
peter |
/// sub-sets of the data, or the different lists could be different |
828 |
19 Mar 07 |
peter |
/// because they have been generated using different criteria. Having |
597 |
28 Aug 06 |
markus |
/// \f$ N \f$ lists means each row in the data matrix has \f$ N \f$ |
828 |
19 Mar 07 |
peter |
/// ranks (each corresponding to one list). A |
828 |
19 Mar 07 |
peter |
/// statistics::VectorFunction is used to boil down these ranks to |
828 |
19 Mar 07 |
peter |
/// one consensus rank, and a ranked list is created by sorting the |
828 |
19 Mar 07 |
peter |
/// data rows with respect to this consensus rank. |
592 |
24 Aug 06 |
peter |
58 |
/// |
592 |
24 Aug 06 |
peter |
/// For the time being there are two ways to build a |
615 |
31 Aug 06 |
peter |
/// ConsensusInputRanker. 1) Sending a Sampler and a MatrixLookup to |
828 |
19 Mar 07 |
peter |
/// the add function will create one ranked list for each of the |
615 |
31 Aug 06 |
peter |
/// partitions defined in the Sampler. 2) You can generate |
592 |
24 Aug 06 |
peter |
/// your ranked list outside, using your favourite method, and |
592 |
24 Aug 06 |
peter |
/// adding it into the ConsensusInputRanker object. This allows |
592 |
24 Aug 06 |
peter |
/// combining different scores and different sub-sets in a more |
592 |
24 Aug 06 |
peter |
/// general way. |
4200 |
19 Aug 22 |
peter |
67 |
/// |
115 |
19 Jul 04 |
peter |
68 |
class ConsensusInputRanker |
115 |
19 Jul 04 |
peter |
69 |
{ |
4200 |
19 Aug 22 |
peter |
70 |
|
115 |
19 Jul 04 |
peter |
71 |
public: |
597 |
28 Aug 06 |
markus |
72 |
|
522 |
23 Feb 06 |
peter |
73 |
/// |
522 |
23 Feb 06 |
peter |
/// @brief Default constructor |
522 |
23 Feb 06 |
peter |
75 |
/// |
592 |
24 Aug 06 |
peter |
/// Truly does nothing but creates a few empty member vectors. |
4200 |
19 Aug 22 |
peter |
77 |
/// |
828 |
19 Mar 07 |
peter |
78 |
ConsensusInputRanker(const IRRetrieve&, const statistics::VectorFunction&); |
4200 |
19 Aug 22 |
peter |
79 |
|
115 |
19 Jul 04 |
peter |
80 |
/// |
615 |
31 Aug 06 |
peter |
/// Iterating through @a sampler creating subsets of @a data, and |
615 |
31 Aug 06 |
peter |
/// for each subset is an InputRanker is created using the @a |
615 |
31 Aug 06 |
peter |
/// score. After creation the data rows are sorted with respect to |
615 |
31 Aug 06 |
peter |
/// the median rank (i.e. update() is called). |
4200 |
19 Aug 22 |
peter |
85 |
/// |
4200 |
19 Aug 22 |
peter |
86 |
void add(const Sampler& sampler, const MatrixLookup&, |
938 |
05 Oct 07 |
peter |
87 |
const statistics::Score& s); |
4200 |
19 Aug 22 |
peter |
88 |
|
615 |
31 Aug 06 |
peter |
89 |
/// |
828 |
19 Mar 07 |
peter |
/// @brief Add a set of InputRankers |
828 |
19 Mar 07 |
peter |
91 |
/// |
615 |
31 Aug 06 |
peter |
/// Iterating through @a sampler creating subsets of @a data, and |
615 |
31 Aug 06 |
peter |
/// for each subset is an InputRanker is created using the @a |
615 |
31 Aug 06 |
peter |
/// score. After creation the data rows are sorted with respect to |
615 |
31 Aug 06 |
peter |
/// the median rank (i.e. update() is called). |
4200 |
19 Aug 22 |
peter |
96 |
/// |
4200 |
19 Aug 22 |
peter |
97 |
void add(const Sampler& sampler, const MatrixLookupWeighted& data, |
938 |
05 Oct 07 |
peter |
98 |
const statistics::Score& score); |
4200 |
19 Aug 22 |
peter |
99 |
|
115 |
19 Jul 04 |
peter |
100 |
/// |
828 |
19 Mar 07 |
peter |
/// @brief Add an InputRanker |
522 |
23 Feb 06 |
peter |
102 |
/// |
522 |
23 Feb 06 |
peter |
/// @note update() must be called to make the added InputRanker to |
522 |
23 Feb 06 |
peter |
/// influence consensus ids and ranks. If a sequence of |
522 |
23 Feb 06 |
peter |
/// InputRankers are added, update() need to be called only after |
522 |
23 Feb 06 |
peter |
/// the last InputRanker is added. |
522 |
23 Feb 06 |
peter |
107 |
/// |
720 |
26 Dec 06 |
jari |
108 |
void add(const InputRanker& ir); |
4200 |
19 Aug 22 |
peter |
109 |
|
133 |
16 Aug 04 |
peter |
110 |
/// |
475 |
22 Dec 05 |
peter |
/// Row with lowest rank (highest score) is ranked as number zero |
475 |
22 Dec 05 |
peter |
/// @return index of row ranked as number \a i |
133 |
16 Aug 04 |
peter |
113 |
/// |
720 |
26 Dec 06 |
jari |
114 |
size_t id(size_t i) const; |
4200 |
19 Aug 22 |
peter |
115 |
|
817 |
17 Mar 07 |
peter |
116 |
/** |
817 |
17 Mar 07 |
peter |
@return ith InputRanker |
817 |
17 Mar 07 |
peter |
118 |
*/ |
817 |
17 Mar 07 |
peter |
119 |
const InputRanker& input_ranker(size_t i) const; |
817 |
17 Mar 07 |
peter |
120 |
|
133 |
16 Aug 04 |
peter |
121 |
/// |
522 |
23 Feb 06 |
peter |
/// Row with lowest rank (highest score) is ranked as number zero |
522 |
23 Feb 06 |
peter |
/// @return rank for row \a i |
133 |
16 Aug 04 |
peter |
124 |
/// |
720 |
26 Dec 06 |
jari |
125 |
size_t rank(size_t i) const; |
4200 |
19 Aug 22 |
peter |
126 |
|
828 |
19 Mar 07 |
peter |
127 |
/** |
4200 |
19 Aug 22 |
peter |
\brief \brief reserve memory for internal vector of InputRankers |
828 |
19 Mar 07 |
peter |
129 |
|
828 |
19 Mar 07 |
peter |
This function is recommended before adding using add(const |
828 |
19 Mar 07 |
peter |
InputRanker&) to avoid re-allocations. |
828 |
19 Mar 07 |
peter |
132 |
*/ |
828 |
19 Mar 07 |
peter |
133 |
void reserve(size_t n); |
828 |
19 Mar 07 |
peter |
134 |
|
828 |
19 Mar 07 |
peter |
135 |
|
522 |
23 Feb 06 |
peter |
136 |
/// |
522 |
23 Feb 06 |
peter |
/// update ids and ranks |
522 |
23 Feb 06 |
peter |
138 |
/// |
522 |
23 Feb 06 |
peter |
139 |
void update(void); |
115 |
19 Jul 04 |
peter |
140 |
|
115 |
19 Jul 04 |
peter |
141 |
|
115 |
19 Jul 04 |
peter |
142 |
private: |
522 |
23 Feb 06 |
peter |
143 |
|
133 |
16 Aug 04 |
peter |
144 |
std::vector<size_t> id_; |
115 |
19 Jul 04 |
peter |
145 |
std::vector<InputRanker> input_rankers_; |
133 |
16 Aug 04 |
peter |
146 |
std::vector<size_t> rank_; |
666 |
06 Oct 06 |
peter |
147 |
const IRRetrieve& retriever_; |
828 |
19 Mar 07 |
peter |
148 |
const statistics::VectorFunction& vec_func_; |
115 |
19 Jul 04 |
peter |
149 |
}; |
115 |
19 Jul 04 |
peter |
150 |
|
680 |
11 Oct 06 |
jari |
151 |
}}} // of namespace classifier, yat, and theplu |
115 |
19 Jul 04 |
peter |
152 |
|
115 |
19 Jul 04 |
peter |
153 |
#endif |