source: trunk/yat/classifier/ConsensusInputRanker.h @ 680

Last change on this file since 680 was 680, checked in by Jari Häkkinen, 15 years ago

Addresses #153. Introduced yat namespace. Removed alignment namespace. Clean up of code.

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