Changeset 624 for trunk/c++_tools
- Timestamp:
- Sep 5, 2006, 4:29:39 AM (17 years ago)
- Location:
- trunk/c++_tools/classifier
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/c++_tools/classifier/DataLookup1D.cc
r608 r624 2 2 3 3 #include <c++_tools/classifier/DataLookup1D.h> 4 #include <c++_tools/classifier/DataLookup2D.h> 4 5 #include <c++_tools/classifier/MatrixLookup.h> 5 6 -
trunk/c++_tools/classifier/DataLookup1D.h
r608 r624 12 12 namespace theplu { 13 13 namespace classifier { 14 15 class DataLookup2D;16 14 17 15 /// -
trunk/c++_tools/classifier/FeatureSelector.cc
r608 r624 3 3 #include "FeatureSelector.h" 4 4 5 #include "DataLookup2D.h" 5 #include "MatrixLookup.h" 6 #include "MatrixLookupWeighted.h" 6 7 7 8 #include <list> … … 19 20 FeatureSelector::~FeatureSelector() 20 21 { 21 for (std::list<const DataLookup2D*>::iterator i=garbage_.begin();22 for (std::list<const MatrixLookup*>::iterator i=garbage_.begin(); 22 23 i!=garbage_.end(); ++i) 24 delete *i; 25 for (std::list<const MatrixLookupWeighted*>::iterator i= 26 garbage_weighted_.begin(); i!=garbage_weighted_.end(); ++i) 23 27 delete *i; 24 28 } 25 29 26 30 27 const DataLookup2D& FeatureSelector::get(const DataLookup2D& data)31 const MatrixLookup& FeatureSelector::get(const MatrixLookup& matrix) 28 32 { 29 garbage_.push_back( data.selected(features_));33 garbage_.push_back(new MatrixLookup(matrix,features_,true)); 30 34 return *garbage_.back(); 35 } 36 37 38 const MatrixLookupWeighted& 39 FeatureSelector::get(const MatrixLookupWeighted& matrix) 40 { 41 garbage_weighted_.push_back(new MatrixLookupWeighted(matrix,features_, 42 true)); 43 return *garbage_weighted_.back(); 31 44 } 32 45 -
trunk/c++_tools/classifier/FeatureSelector.h
r608 r624 9 9 namespace theplu { 10 10 namespace classifier { 11 class DataLookup2D; 11 class MatrixLookup; 12 class MatrixLookupWeighted; 12 13 class Target; 13 14 … … 31 32 32 33 /// 33 /// @return DataLookup containing only selected features.34 /// @return MatrixLookup containing only selected features. 34 35 /// 35 const DataLookup2D& get(const DataLookup2D& data); 36 const MatrixLookup& get(const MatrixLookup& data); 37 38 /// 39 /// @return MatrixLookupWeighted containing only selected features. 40 /// 41 const MatrixLookupWeighted& get(const MatrixLookupWeighted& data); 36 42 37 43 /// … … 41 47 42 48 /// 43 /// Uses @a datato select features.49 /// Uses @a matrix to select features. 44 50 /// 45 virtual void update(const DataLookup2D& data, const Target& target)=0; 51 virtual void update(const MatrixLookup& matrix, const Target& target)=0; 52 53 /// 54 /// Uses @a matrix to select features. 55 /// 56 virtual void update(const MatrixLookupWeighted& matrix, 57 const Target& target)=0; 46 58 47 59 protected: … … 51 63 52 64 private: 53 std::list<const DataLookup2D*> garbage_; 65 std::list<const MatrixLookup*> garbage_; 66 std::list<const MatrixLookupWeighted*> garbage_weighted_; 54 67 55 68 }; -
trunk/c++_tools/classifier/FeatureSelectorIR.cc
r608 r624 34 34 35 35 36 void FeatureSelectorIR::update(const DataLookup2D& data, const Target& target) 36 void FeatureSelectorIR::update(const MatrixLookup& data, const Target& target) 37 { 38 InputRanker ir = InputRanker(data, target, score_); 39 features_.resize(N_); 40 std::copy(ir.rank().begin()+first_, ir.rank().begin()+first_+N_, 41 features_.begin()); 42 43 } 44 45 46 void FeatureSelectorIR::update(const MatrixLookupWeighted& data, 47 const Target& target) 37 48 { 38 49 InputRanker ir = InputRanker(data, target, score_); -
trunk/c++_tools/classifier/FeatureSelectorIR.h
r608 r624 25 25 /// 26 26 /// 27 void update(const DataLookup2D& data, const Target& target); 27 void update(const MatrixLookup& data, const Target& target); 28 29 /// 30 /// 31 /// 32 void update(const MatrixLookupWeighted& data, const Target& target); 28 33 29 34 private: -
trunk/c++_tools/classifier/InputRanker.cc
r615 r624 4 4 5 5 #include <c++_tools/classifier/MatrixLookup.h> 6 #include <c++_tools/classifier/MatrixLookupWeighted.h> 6 7 #include <c++_tools/classifier/DataLookup1D.h> 8 #include <c++_tools/classifier/DataLookupWeighted1D.h> 7 9 #include <c++_tools/classifier/Target.h> 8 10 #include <c++_tools/statistics/ROC.h> … … 19 21 20 22 21 InputRanker::InputRanker(const DataLookup2D& data,23 InputRanker::InputRanker(const MatrixLookup& data, 22 24 const Target& target, 23 25 statistics::Score& score_object) … … 30 32 for (size_t i=0; i<nof_genes; i++) { 31 33 double area = score_object.score(target,DataLookup1D(data,i,true)); 34 // Peter, remove stupid tmp 35 std::pair<double, size_t> tmp(area,i); 36 score.push_back(tmp); 37 } 38 39 //sort the scores and assign id_ and rank_ 40 sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >()); 41 42 id_.resize(nof_genes); 43 rank_.resize(nof_genes); 44 for (size_t i=0; i<nof_genes; i++){ 45 id_[i]=score[i].second; 46 rank_[id_[i]]=i; 47 } 48 } 49 50 51 52 InputRanker::InputRanker(const MatrixLookupWeighted& data, 53 const Target& target, 54 statistics::Score& score_object) 55 { 56 assert(data.columns()==target.size()); 57 size_t nof_genes = data.rows(); 58 59 //scoring each input 60 std::vector<std::pair<double, size_t> > score; 61 for (size_t i=0; i<nof_genes; i++) { 62 double area=score_object.score(target,DataLookupWeighted1D(data,i,true)); 32 63 // Peter, remove stupid tmp 33 64 std::pair<double, size_t> tmp(area,i); -
trunk/c++_tools/classifier/InputRanker.h
r617 r624 14 14 class DataLookup2D; 15 15 class MatrixLookup; 16 class MatrixLookupWeighted; 16 17 class Target; 17 18 … … 29 30 /// use all samples) 30 31 /// 31 InputRanker(const DataLookup2D&, const Target&, statistics::Score&); 32 InputRanker(const MatrixLookup&, const Target&, statistics::Score&); 33 34 35 /// 36 /// Constructor taking data, target, a Score 37 /// object and vector defining what samples to use (default is to 38 /// use all samples) 39 /// 40 InputRanker(const MatrixLookupWeighted&, const Target&, 41 statistics::Score&); 32 42 33 43 … … 37 47 /// use all samples) 38 48 /// 49 /// @nore this constructor will be removed 39 50 InputRanker(const DataLookup2D&, const Target&, statistics::Score&, 40 51 const MatrixLookup&); -
trunk/c++_tools/classifier/MatrixLookupWeighted.cc
r616 r624 134 134 MatrixLookupWeighted::MatrixLookupWeighted(const size_t rows, 135 135 const size_t columns, 136 const double value) 136 const double value, 137 const double weight) 137 138 : DataLookup2D(rows,columns, true) 138 139 { 139 140 data_ = new utility::matrix(1,1,value); 140 weights_ = new utility::matrix(1,1, 1.0);141 weights_ = new utility::matrix(1,1,weight); 141 142 } 142 143 -
trunk/c++_tools/classifier/MatrixLookupWeighted.h
r616 r624 158 158 /// 159 159 MatrixLookupWeighted(const size_t rows, const size_t columns, 160 const double value=0 );160 const double value=0, const double weight=1); 161 161 162 162 /// … … 176 176 /// 177 177 virtual ~MatrixLookupWeighted(); 178 179 /// 180 /// @return data value of element (@a row, @a column) 181 /// 182 inline double data(size_t row, size_t column) const 183 { return (*data_)(row_index_[row], column_index_[column]); } 178 184 179 185 /// … … 247 253 248 254 /// 255 /// @return weight value of element (@a row, @a column) 256 /// 257 inline double weight(size_t row, size_t column) const 258 { return (*weights_)(row_index_[row], column_index_[column]); } 259 260 /// 249 261 /// Access operator 250 262 /// … … 253 265 inline double operator()(const size_t row, const size_t column) const 254 266 { 255 assert(row<rows()); 256 assert(column<columns()); 257 return (*data_)(row_index_[row], column_index_[column])* 258 (*weights_)(row_index_[row], column_index_[column]); 267 return data(row,column)*weight(row,column); 259 268 } 260 269
Note: See TracChangeset
for help on using the changeset viewer.