Changeset 828 for trunk/yat/classifier
 Timestamp:
 Mar 19, 2007, 11:15:43 PM (15 years ago)
 Location:
 trunk/yat/classifier
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/ConsensusInputRanker.cc
r817 r828 31 31 #include "yat/statistics/Score.h" 32 32 #include "yat/statistics/utility.h" 33 #include "yat/statistics/VectorFunction.h" 33 34 #include "yat/utility/stl_utility.h" 34 35 … … 44 45 namespace classifier { 45 46 46 ConsensusInputRanker::ConsensusInputRanker(const IRRetrieve& retriever) 47 : retriever_(retriever) 47 ConsensusInputRanker::ConsensusInputRanker(const IRRetrieve& retriever, 48 const statistics::VectorFunction& 49 vf) 50 : retriever_(retriever), vec_func_(vf) 48 51 { 49 52 } 50 53 51 54 52 ConsensusInputRanker::ConsensusInputRanker(const Sampler& sampler, 53 const MatrixLookup& data, 54 statistics::Score& score, 55 const IRRetrieve& retriever) 56 : retriever_(retriever) 55 void ConsensusInputRanker::add(const Sampler& sampler, 56 const MatrixLookup& data, 57 statistics::Score& score) 57 58 { 58 59 assert(sampler.size()); 60 assert(id_.empty()  id_.size()==data.rows()); 61 input_rankers_.reserve(sampler.size()+input_rankers_.size()); 59 62 id_.resize(data.rows()); 60 63 rank_.resize(data.rows()); … … 67 70 } 68 71 69 ConsensusInputRanker::ConsensusInputRanker(const Sampler& sampler, 70 const MatrixLookupWeighted& data, 71 statistics::Score& score, 72 const IRRetrieve& retriever) 73 : retriever_(retriever) 72 void ConsensusInputRanker::add(const Sampler& sampler, 73 const MatrixLookupWeighted& data, 74 statistics::Score& score) 74 75 { 75 assert( sampler.size());76 assert(id_.empty()  id_.size()==data.rows()); 76 77 id_.resize(data.rows()); 77 78 rank_.resize(data.rows()); 78 79 79 for (size_t i=0; i<sampler.size(); ++i){ 80 80 input_rankers_.push_back(InputRanker(MatrixLookupWeighted(data,sampler.training_index(i), false), … … 87 87 void ConsensusInputRanker::add(const InputRanker& ir) 88 88 { 89 assert(id_.empty()  id_.size()==ir.id().size()); 89 90 input_rankers_.push_back(ir); 90 91 } … … 92 93 size_t ConsensusInputRanker::id(size_t i) const 93 94 { 95 assert(i<id_.size()); 94 96 return id_[i]; 95 97 } … … 106 108 } 107 109 110 111 void ConsensusInputRanker::reserve(size_t n) 112 { 113 input_rankers_.reserve(n); 114 } 115 116 108 117 void ConsensusInputRanker::update(void) 109 118 { 110 111 // Sorting with respect to median info (from retriever_) 112 std::vector<std::pair<double,size_t> > medians(id_.size()); 119 // Sorting with respect to VectorFunction(info) where info is a 120 // vector and each element contains infomation retrieved with 121 // retriever_ from each InputRanker 122 std::vector<std::pair<double,size_t> > cons_rank; 123 cons_rank.reserve(id_.size()); 113 124 for (size_t i=0; i<id_.size(); i++){ 114 125 std::vector<double> scores; … … 117 128 scores.push_back(retriever_(input_rankers_[j],i)); 118 129 } 119 medians[i].first = statistics::median(scores); 120 medians[i].second = i; 130 cons_rank.push_back(std::make_pair(vec_func_(scores), i)); 121 131 } 122 132 123 //sort mediansand assign id_ and rank_124 sort( medians.begin(), medians.end(),133 //sort cons_rank and assign id_ and rank_ 134 sort(cons_rank.begin(), cons_rank.end(), 125 135 std::greater<std::pair<double, size_t> >()); 126 136 127 for (size_t i=0; i<medians.size(); i++){ 128 id_[i]=medians[i].second; 137 for (size_t i=0; i<cons_rank.size(); i++){ 138 assert(i<id_.size()); 139 id_[i]=cons_rank[i].second; 140 assert(id_[i]<rank_.size()); 129 141 rank_[id_[i]]=i; 130 142 } 
trunk/yat/classifier/ConsensusInputRanker.h
r817 r828 27 27 #include "InputRanker.h" 28 28 29 #include <vector> 30 29 31 namespace theplu { 30 32 namespace yat { 31 32 class statistics::Score; 33 33 namespace statistics { 34 class Score; 35 class VectorFunction; 36 } 34 37 namespace classifier { 35 38 … … 46 49 /// could be different because they are based upon different 47 50 /// subsets of the data, or the different lists could be different 48 /// because they have aregenerated using different criteria. Having51 /// because they have been generated using different criteria. Having 49 52 /// \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 /// ranks (each corresponding to one list). A 54 /// statistics::VectorFunction is used to boil down these ranks to 55 /// one consensus rank, and a ranked list is created by sorting the 56 /// data rows with respect to this consensus rank. 53 57 /// 54 58 /// For the time being there are two ways to build a 55 59 /// ConsensusInputRanker. 1) Sending a Sampler and a MatrixLookup to 56 /// the constructorwill create one ranked list for each of the60 /// the add function will create one ranked list for each of the 57 61 /// partitions defined in the Sampler. 2) You can generate 58 62 /// your ranked list outside, using your favourite method, and … … 71 75 /// Truly does nothing but creates a few empty member vectors. 72 76 /// 73 ConsensusInputRanker(const IRRetrieve& );77 ConsensusInputRanker(const IRRetrieve&, const statistics::VectorFunction&); 74 78 75 79 /// … … 79 83 /// the median rank (i.e. update() is called). 80 84 /// 81 ConsensusInputRanker(const Sampler& sampler, const MatrixLookup&, 82 statistics::Score& s, const IRRetrieve&); 85 void add(const Sampler& sampler, const MatrixLookup&, statistics::Score& s); 83 86 84 87 /// 88 /// @brief Add a set of InputRankers 89 /// 85 90 /// Iterating through @a sampler creating subsets of @a data, and 86 91 /// for each subset is an InputRanker is created using the @a … … 88 93 /// the median rank (i.e. update() is called). 89 94 /// 90 ConsensusInputRanker(const Sampler& sampler, 91 const MatrixLookupWeighted& data, 92 statistics::Score& score, const IRRetrieve&); 95 void add(const Sampler& sampler, const MatrixLookupWeighted& data, 96 statistics::Score& score); 93 97 94 98 /// 95 /// @brief add an InputRanker99 /// @brief Add an InputRanker 96 100 /// 97 101 /// @note update() must be called to make the added InputRanker to … … 119 123 size_t rank(size_t i) const; 120 124 125 /** 126 \brief \brief reserve memory for internal vector of InputRankers 127 128 This function is recommended before adding using add(const 129 InputRanker&) to avoid reallocations. 130 */ 131 void reserve(size_t n); 132 133 121 134 /// 122 135 /// update ids and ranks … … 131 144 std::vector<size_t> rank_; 132 145 const IRRetrieve& retriever_; 133 146 const statistics::VectorFunction& vec_func_; 134 147 }; 135 148
Note: See TracChangeset
for help on using the changeset viewer.