yat/classifier/ConsensusInputRanker.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
115 19 Jul 04 peter 5
675 10 Oct 06 jari 6 /*
831 27 Mar 07 peter 7   Copyright (C) 2004, 2005 Peter Johansson
2119 12 Dec 09 peter 8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
4359 23 Aug 23 peter 9   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 10   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
675 10 Oct 06 jari 11
1437 25 Aug 08 peter 12   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 14   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 15   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 16   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 17   License, or (at your option) any later version.
675 10 Oct 06 jari 18
675 10 Oct 06 jari 19   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 20   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 22   General Public License for more details.
675 10 Oct 06 jari 23
675 10 Oct 06 jari 24   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 25   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 46   /// @brief Robust algorithm to rank rows in a data matrix versus a
4200 19 Aug 22 peter 47   /// target vector.
592 24 Aug 06 peter 48   ///
592 24 Aug 06 peter 49   /// The idea is to create several (different) ranked lists. The list
592 24 Aug 06 peter 50   /// could be different because they are based upon different
592 24 Aug 06 peter 51   /// sub-sets of the data, or the different lists could be different
828 19 Mar 07 peter 52   /// because they have been generated using different criteria. Having
597 28 Aug 06 markus 53   /// \f$ N \f$ lists means each row in the data matrix has \f$ N \f$
828 19 Mar 07 peter 54   /// ranks (each corresponding to one list). A
828 19 Mar 07 peter 55   /// statistics::VectorFunction is used to boil down these ranks to
828 19 Mar 07 peter 56   /// one consensus rank, and a ranked list is created by sorting the
828 19 Mar 07 peter 57   /// data rows with respect to this consensus rank.
592 24 Aug 06 peter 58   ///
592 24 Aug 06 peter 59   /// For the time being there are two ways to build a
615 31 Aug 06 peter 60   /// ConsensusInputRanker. 1) Sending a Sampler and a MatrixLookup to
828 19 Mar 07 peter 61   /// the add function will create one ranked list for each of the
615 31 Aug 06 peter 62   /// partitions defined in the Sampler. 2) You can generate
592 24 Aug 06 peter 63   /// your ranked list outside, using your favourite method, and
592 24 Aug 06 peter 64   /// adding it into the ConsensusInputRanker object. This allows
592 24 Aug 06 peter 65   /// combining different scores and different sub-sets in a more
592 24 Aug 06 peter 66   /// 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 74     /// @brief Default constructor
522 23 Feb 06 peter 75     ///
592 24 Aug 06 peter 76     /// 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 81     /// Iterating through @a sampler creating subsets of @a data, and
615 31 Aug 06 peter 82     /// for each subset is an InputRanker is created using the @a
615 31 Aug 06 peter 83     /// score. After creation the data rows are sorted with respect to
615 31 Aug 06 peter 84     /// 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 90     /// @brief Add a set of InputRankers
828 19 Mar 07 peter 91     ///
615 31 Aug 06 peter 92     /// Iterating through @a sampler creating subsets of @a data, and
615 31 Aug 06 peter 93     /// for each subset is an InputRanker is created using the @a
615 31 Aug 06 peter 94     /// score. After creation the data rows are sorted with respect to
615 31 Aug 06 peter 95     /// 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 101     /// @brief Add an InputRanker
522 23 Feb 06 peter 102     ///
522 23 Feb 06 peter 103     /// @note update() must be called to make the added InputRanker to
522 23 Feb 06 peter 104     /// influence consensus ids and ranks. If a sequence of
522 23 Feb 06 peter 105     /// InputRankers are added, update() need to be called only after
522 23 Feb 06 peter 106     /// 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 111     /// Row with lowest rank (highest score) is ranked as number zero
475 22 Dec 05 peter 112     /// @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 117        @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 122     /// Row with lowest rank (highest score) is ranked as number zero
522 23 Feb 06 peter 123     /// @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 128        \brief \brief reserve memory for internal vector of InputRankers
828 19 Mar 07 peter 129
828 19 Mar 07 peter 130        This function is recommended before adding using add(const
828 19 Mar 07 peter 131        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 137     /// 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