Changeset 720 for trunk/yat/classifier
- Timestamp:
- Dec 26, 2006, 7:21:36 PM (17 years ago)
- Location:
- trunk/yat/classifier
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/ConsensusInputRanker.cc
r680 r720 85 85 } 86 86 87 void ConsensusInputRanker::add(const InputRanker& ir) 88 { 89 input_rankers_.push_back(ir); 90 } 91 92 size_t ConsensusInputRanker::id(size_t i) const 93 { 94 return id_[i]; 95 } 96 97 size_t ConsensusInputRanker::rank(size_t i) const 98 { 99 return rank_[i]; 100 } 101 87 102 void ConsensusInputRanker::update(void) 88 103 { -
trunk/yat/classifier/ConsensusInputRanker.h
r680 r720 100 100 /// the last InputRanker is added. 101 101 /// 102 inline void add(const InputRanker& ir) { input_rankers_.push_back(ir); }102 void add(const InputRanker& ir); 103 103 104 104 /// … … 106 106 /// @return index of row ranked as number \a i 107 107 /// 108 inline size_t id(const size_t i) const { return id_[i]; }108 size_t id(size_t i) const; 109 109 110 110 /// … … 112 112 /// @return rank for row \a i 113 113 /// 114 inline size_t rank(const size_t i) const { return rank_[i]; }114 size_t rank(size_t i) const; 115 115 116 116 /// -
trunk/yat/classifier/DataLookup1D.cc
r680 r720 42 42 } 43 43 44 44 45 DataLookup1D::DataLookup1D(const size_t size, const double value) 45 46 : column_vector_(false), index_(0), owner_(true) … … 47 48 matrix_ = new MatrixLookup(1,size,value); 48 49 } 50 49 51 50 52 DataLookup1D::DataLookup1D(const DataLookup1D& other) … … 54 56 } 55 57 58 56 59 DataLookup1D::~DataLookup1D() 57 60 { 58 61 if (owner_) 59 62 delete matrix_; 63 } 64 65 66 size_t DataLookup1D::size(void) const 67 { 68 return column_vector_ ? matrix_->rows() : matrix_->columns(); 69 } 70 71 72 double DataLookup1D::operator()(const size_t i) const 73 { 74 assert(i<size()); 75 return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); 76 } 77 78 79 double DataLookup1D::operator[](const size_t i) const 80 { 81 return this->operator()(i); 60 82 } 61 83 -
trunk/yat/classifier/DataLookup1D.h
r680 r720 73 73 /// @return number of elements 74 74 /// 75 inline size_t size(void) const 76 { return column_vector_ ? matrix_->rows() : matrix_->columns(); } 75 size_t size(void) const; 77 76 78 77 /// 79 78 /// @brief access operator 80 79 /// 81 inline double operator()(const size_t i) const 82 { 83 assert(i<size()); 84 return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); 85 } 80 double operator()(const size_t i) const; 86 81 87 82 /// 88 83 /// @brief access operator 89 84 /// 90 inline double operator[](const size_t i) const 91 { 92 return this->operator()(i); 93 } 94 85 double operator[](const size_t i) const; 95 86 96 87 /// -
trunk/yat/classifier/DataLookup2D.cc
r680 r720 115 115 } 116 116 117 118 size_t DataLookup2D::columns(void) const 119 { 120 return column_index_.size(); 121 } 122 123 124 size_t DataLookup2D::rows(void) const 125 { 126 return row_index_.size(); 127 } 128 129 117 130 const DataLookup2D& DataLookup2D::operator=(const DataLookup2D& other) 118 131 { -
trunk/yat/classifier/DataLookup2D.h
r680 r720 99 99 /// @return number of columns 100 100 /// 101 inline size_t columns(void) const { return column_index_.size(); }101 size_t columns(void) const; 102 102 103 103 /// 104 104 /// @return number of rows 105 105 /// 106 inline size_t rows(void) const { return row_index_.size(); }106 size_t rows(void) const; 107 107 108 108 /// -
trunk/yat/classifier/DataLookupWeighted1D.cc
r680 r720 58 58 } 59 59 60 60 61 DataLookupWeighted1D::~DataLookupWeighted1D() 61 62 { … … 65 66 66 67 68 double DataLookupWeighted1D::data(const size_t i) const 69 { 70 return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i); 71 } 72 73 74 size_t DataLookupWeighted1D::size(void) const 75 { 76 return column_vector_ ? matrix_->rows() : matrix_->columns(); 77 } 78 79 80 double DataLookupWeighted1D::weight(const size_t i) const 81 { 82 return column_vector_? matrix_->weight(i,index_) : matrix_->weight(index_,i); 83 } 84 85 86 double DataLookupWeighted1D::operator()(const size_t i) const 87 { 88 return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); 89 } 90 91 92 double DataLookupWeighted1D::operator[](const size_t i) const 93 { 94 return this->operator()(i); 95 } 96 67 97 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/DataLookupWeighted1D.h
r680 r720 70 70 virtual ~DataLookupWeighted1D(); 71 71 72 /** 73 \return data(i) 74 */ 75 double data(const size_t i) const; 76 72 77 /// 73 78 /// @return number of elements 74 79 /// 75 inline size_t size(void) const 76 { return column_vector_ ? matrix_->rows() : matrix_->columns(); } 77 78 /// 79 /// @return data(i) 80 /// 81 inline double data(const size_t i) const 82 { 83 return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i); 84 } 80 size_t size(void) const; 85 81 86 82 /// 87 83 /// @return weight(i) 88 84 /// 89 inline double weight(const size_t i) const 90 { 91 return column_vector_? matrix_->weight(i,index_) : 92 matrix_->weight(index_,i); 93 } 85 double weight(const size_t i) const; 94 86 95 87 /// 96 88 /// @return data(i) * weight(i) 97 89 /// 98 inline double operator()(const size_t i) const 99 { 100 return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); 101 } 90 double operator()(const size_t i) const; 102 91 103 92 /// 104 93 /// @return data(i) * weight(i) 105 94 /// 106 inline double operator[](const size_t i) const 107 { 108 return this->operator()(i); 109 } 110 95 double operator[](const size_t i) const; 111 96 112 97 private: -
trunk/yat/classifier/EnsembleBuilder.cc
r704 r720 57 57 } 58 58 59 60 const SupervisedClassifier& EnsembleBuilder::classifier(size_t i) const 61 { 62 return *(classifier_[i]); 63 } 64 65 66 u_long EnsembleBuilder::size(void) const 67 { 68 return classifier_.size(); 69 } 70 71 59 72 void EnsembleBuilder::predict 60 73 (const DataLookup2D& data, … … 90 103 91 104 92 93 105 const std::vector<std::vector<statistics::Averager> >& 94 106 EnsembleBuilder::validate(void) -
trunk/yat/classifier/EnsembleBuilder.h
r680 r720 55 55 virtual ~EnsembleBuilder(void); 56 56 57 58 57 /// 59 58 /// Generate ensemble. Function trains each member of the Ensemble. … … 64 63 /// @Return classifier 65 64 /// 66 inline const SupervisedClassifier& classifier(size_t i) const 67 { 68 return *(classifier_[i]); 69 } 65 const SupervisedClassifier& classifier(size_t i) const; 70 66 71 67 /// 72 68 /// @Return Number of classifiers in ensemble 73 69 /// 74 inline u_long size(void) const 75 { 76 return classifier_.size(); 77 } 70 u_long size(void) const; 78 71 79 72 /// … … 93 86 kernel corresponds to. 94 87 */ 95 void predict(const DataLookup2D& data, 96 std::vector<std::vector<statistics::Averager> > &); 97 88 void predict(const DataLookup2D& data, 89 std::vector<std::vector<statistics::Averager> > &); 98 90 99 91 private: -
trunk/yat/classifier/FeatureSelector.cc
r680 r720 50 50 51 51 52 const std::vector<size_t> FeatureSelector::features(void) const 53 { 54 return features_; 55 } 56 57 52 58 const MatrixLookup& FeatureSelector::get(const MatrixLookup& matrix) 53 59 { -
trunk/yat/classifier/FeatureSelector.h
r680 r720 66 66 /// @return vector of indices corresponding to selected features. 67 67 /// 68 inline const std::vector<size_t> features(void) const { return features_; }68 const std::vector<size_t> features(void) const; 69 69 70 70 /// -
trunk/yat/classifier/InputRanker.cc
r680 r720 69 69 70 70 71 72 71 InputRanker::InputRanker(const MatrixLookupWeighted& data, 73 72 const Target& target, … … 97 96 98 97 98 const std::vector<size_t>& InputRanker::id(void) const 99 { 100 return id_; 101 } 102 103 104 const std::vector<size_t>& InputRanker::rank(void) const 105 { 106 return rank_; 107 } 108 109 110 double InputRanker::score(size_t rank) const 111 { 112 return score_[rank]; 113 } 99 114 100 115 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/InputRanker.h
r680 r720 54 54 InputRanker(const MatrixLookup&, const Target&, statistics::Score&); 55 55 56 57 56 /// 58 57 /// Constructor taking data, target, a Score … … 63 62 statistics::Score&); 64 63 65 66 64 /// 67 65 /// highest ranked gene is ranked as number zero @return id 68 66 /// (index) of input ranked as number \a i 69 67 /// 70 inline const std::vector<size_t>& id(void) const {return id_;}68 const std::vector<size_t>& id(void) const; 71 69 72 70 /// … … 74 72 /// id (row) \a i 75 73 /// 76 inline const std::vector<size_t>& rank(void) const {return rank_;}74 const std::vector<size_t>& rank(void) const; 77 75 78 76 /// … … 84 82 /// number @a rank. 85 83 /// 86 inline double score(size_t rank) const { return score_[rank]; } 87 84 double score(size_t rank) const; 88 85 89 86 private: -
trunk/yat/classifier/Kernel.cc
r680 r720 77 77 } 78 78 79 79 80 Kernel::~Kernel() 80 81 { … … 90 91 91 92 93 const DataLookup2D& Kernel::data(void) const 94 { 95 return *data_; 96 } 97 98 92 99 double Kernel::element(const DataLookup1D& vec, const size_t i) const 93 100 { … … 107 114 } 108 115 116 117 size_t Kernel::size(void) const 118 { 119 return data_->columns(); 120 } 121 122 123 bool Kernel::weighted(void) const 124 { 125 return data_w_; 126 } 127 109 128 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/Kernel.h
r680 r720 105 105 /// @return const reference to the underlying data. 106 106 /// 107 inline const DataLookup2D& data(void) const { return *data_; } 108 109 /// 110 /// @brief number of samples 111 /// 112 inline size_t size(void) const { return data_->columns(); } 107 const DataLookup2D& data(void) const; 113 108 114 109 /// … … 164 159 virtual const Kernel* selected(const std::vector<size_t>& index) const=0; 165 160 161 /** 162 \brief number of samples 163 */ 164 size_t size(void) const; 165 166 166 /// 167 167 /// @return true if kernel is calculated using weights 168 168 /// 169 inline bool weighted(void) const { return data_w_; }169 bool weighted(void) const; 170 170 171 171 protected: -
trunk/yat/classifier/KernelLookup.cc
r680 r720 34 34 namespace theplu { 35 35 namespace yat { 36 namespace classifier { 36 namespace classifier { 37 37 38 38 KernelLookup::KernelLookup(const Kernel& kernel, const bool own) … … 44 44 row_index_=column_index_; 45 45 } 46 46 47 47 48 KernelLookup::KernelLookup(const Kernel& kernel, 48 49 const std::vector<size_t>& row, … … 114 115 } 115 116 116 const KernelLookup* 117 KernelLookup::training_data(const std::vector<size_t>& train) const 118 { 119 return new KernelLookup(*this,train,train); 120 } 121 122 123 const KernelLookup* 124 KernelLookup::validation_data(const std::vector<size_t>& train, 125 const std::vector<size_t>& validation) const 126 { 127 return new KernelLookup(*this,train,validation); 128 } 117 118 const DataLookup2D* KernelLookup::data(void) const 119 { 120 return kernel_->data().training_data(column_index_); 121 } 122 123 124 double KernelLookup::element(const DataLookup1D& vec, size_t i) const 125 { 126 return kernel_->element(vec, row_index_[i]); 127 } 128 129 130 double KernelLookup::element(const DataLookupWeighted1D& vec, size_t i) const 131 { 132 return kernel_->element(vec, row_index_[i]); 133 } 134 135 136 const Kernel* KernelLookup::kernel(void) const 137 { 138 return kernel_; 139 } 129 140 130 141 … … 263 274 } 264 275 276 277 const KernelLookup* 278 KernelLookup::training_data(const std::vector<size_t>& train) const 279 { 280 return new KernelLookup(*this,train,train); 281 } 282 283 284 const KernelLookup* 285 KernelLookup::validation_data(const std::vector<size_t>& train, 286 const std::vector<size_t>& validation) const 287 { 288 return new KernelLookup(*this,train,validation); 289 } 290 291 292 bool KernelLookup::weighted(void) const 293 { 294 return kernel_->weighted(); 295 } 296 297 298 double KernelLookup::operator()(size_t row, size_t column) const 299 { 300 return (*kernel_)(row_index_[row],column_index_[column]); 301 } 302 265 303 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/KernelLookup.h
r680 r720 63 63 64 64 public: 65 65 66 66 /// 67 67 /// @brief Constructor a Lookup into a Kernel … … 101 101 KernelLookup(const Kernel& kernel, const std::vector<size_t>& row, 102 102 const std::vector<size_t>& column, const bool owner=false); 103 103 104 104 /// 105 105 /// @brief Copy constructor. … … 128 128 KernelLookup(const KernelLookup& kl, const std::vector<size_t>& row, 129 129 const std::vector<size_t>& column); 130 130 131 131 /// 132 132 /// Constructor taking the column (default) or row index vector as … … 138 138 /// undefined. 139 139 /// 140 140 KernelLookup(const KernelLookup& kernel, const std::vector<size_t>&, 141 141 const bool row=false); 142 142 … … 148 148 virtual ~KernelLookup(void); 149 149 150 151 /// 152 /// Creates a sub-Kernel identical to the one created using 153 /// KernelLookup(*this, train, train). 154 /// 155 /// @return pointer to dynamically allocated sub-Lookup of the KernelLookup 156 /// 157 /// @Note Returns a dynamically allocated DataLookup2D, which has 150 /// 151 /// Each column in returned MatrixLookup corresponds to the column 152 /// in KernelLookup. 153 /// 154 /// @Note Returns a dynamically allocated MatrixLookup, which has 158 155 /// to be deleted by the caller to avoid memory leaks. 159 156 /// 160 const KernelLookup* training_data(const std::vector<size_t>& train) const; 161 162 163 /// 164 /// In returned kernel each row corresponds to a training sample 165 /// and each column corresponds to a validation sample. The 166 /// created sub-KernelLookup is equivalent to using 167 /// KernelLooup(*this, train, validation). 168 /// 169 /// @return sub-Lookup of the DataLookup2D 170 /// 171 /// @Note Returns a dynamically allocated DataLookup2D, which has 172 /// to be deleted by the caller to avoid memory leaks. 173 /// 174 const KernelLookup* 175 validation_data(const std::vector<size_t>& train, 176 const std::vector<size_t>& validation) const; 177 178 157 const DataLookup2D* data(void) const; 158 159 /** 160 Function to calculate a new Kernel element using the underlying 161 KernelFunction. The value is calulated between @a vec and the 162 data vector of the \f$ i \f$ th sample, in other words, the 163 sample corresponding to the \f$ i \f$ th row or \f$ i \f$ th 164 column. In case KernelLookup is a sub-Kernel and not symmetric, 165 the kernel value is calculated between @a vec and the data 166 vector corresponding to \f$ i \f$ th row. 167 */ 168 double element(const DataLookup1D& vec, size_t i) const; 169 170 /** 171 Function to calculate a new Kernel element using the underlying 172 KernelFunction. The value is calulated between @a vec and the 173 data vector of the \f$ i \f$ th sample, in other words, the 174 sample corresponding to the \f$ i \f$ th row or \f$ i \f$ th 175 column. In case KernelLookup is a sub-Kernel and not symmetric, 176 the kernel value is calculated between @a vec and the data 177 vector corresponding to \f$ i \f$ th row. 178 */ 179 double element(const DataLookupWeighted1D& vec, size_t i) const; 180 181 const Kernel* kernel(void) const; 182 183 /** 184 Each element in returned KernelLookup is calculated using only 185 selected features (defined by @a index). Each element 186 corresponds to the same pair of samples as in the original 187 KernelLookup. 188 189 \Note Returns a dynamically allocated KernelLookup, which has 190 to be deleted by the caller to avoid memory leaks. 191 */ 192 const KernelLookup* selected(const std::vector<size_t>& index) const; 193 179 194 /** 180 195 This function is useful when predicting on a independent data … … 192 207 const KernelLookup* test_kernel(const MatrixLookup& data) const; 193 208 194 195 209 /** 196 210 This function is useful when predicting on a independent data … … 208 222 const KernelLookup* test_kernel(const MatrixLookupWeighted& data) const; 209 223 210 211 /// 212 /// @return element at position (\a row, \a column) in the Kernel 213 /// matrix 214 /// 215 inline double operator()(const size_t row,const size_t column) const 216 { return (*kernel_)(row_index_[row],column_index_[column]); } 217 218 /// 219 /// Each column in returned MatrixLookup corresponds to the column 220 /// in KernelLookup. 221 /// 222 /// @Note Returns a dynamically allocated MatrixLookup, which has 223 /// to be deleted by the caller to avoid memory leaks. 224 /// 225 inline const DataLookup2D* data(void) const 226 { return kernel_->data().training_data(column_index_); } 227 228 229 /// 230 /// Function to calculate a new Kernel element using the 231 /// underlying KernelFunction. The value is calulated between @a 232 /// vec and the data vector of the \f$ i \f$ th sample, in other 233 /// words, the sample corresponding to the \f$ i \f$ th row or 234 /// \f$ i \f$ th column. In case KernelLookup is a sub-Kernel and not 235 /// symmetric, the kernel value is calculated between @a vec and 236 /// the data vector corresponding to \f$ i \f$ th row. 237 /// 238 inline double element(const DataLookup1D& vec, const size_t i) const 239 { return kernel_->element(vec, row_index_[i]); } 240 241 /// 242 /// Function to calculate a new Kernel element using the 243 /// underlying KernelFunction. The value is calulated between @a 244 /// vec and the data vector of the \f$ i \f$ th sample, in other 245 /// words, the sample corresponding to the \f$ i \f$ th row or 246 /// \f$ i \f$ th column. In case KernelLookup is a sub-Kernel and not 247 /// symmetric, the kernel value is calculated between @a vec and 248 /// the data vector corresponding to \f$ i \f$ th row. 249 /// 250 inline double element(const DataLookupWeighted1D& vec, const size_t i) const 251 { return kernel_->element(vec, row_index_[i]); } 252 253 /// 254 /// Each element in returned KernelLookup is calculated using only 255 /// selected features (defined by @a index). Each element 256 /// corresponds to the same pair of samples as in the original 257 /// KernelLookup. 258 /// 259 /// @Note Returns a dynamically allocated KernelLookup, which has 260 /// to be deleted by the caller to avoid memory leaks. 261 /// 262 const KernelLookup* selected(const std::vector<size_t>& index) const; 263 264 /// 265 /// @return true if underlying Kernel is weighted 266 /// 267 inline bool weighted(void) const { return kernel_->weighted(); } 268 269 inline const Kernel* kernel(void) const { return kernel_; } 270 224 /** 225 \brief Creates a sub-Kernel identical to the one created using 226 KernelLookup(*this, train, train). 227 228 \return pointer to dynamically allocated sub-Lookup of the 229 KernelLookup 230 231 \Note Returns a dynamically allocated DataLookup2D, which has 232 to be deleted by the caller to avoid memory leaks. 233 */ 234 const KernelLookup* training_data(const std::vector<size_t>& train) const; 235 236 /** 237 In returned kernel each row corresponds to a training sample 238 and each column corresponds to a validation sample. The created 239 sub-KernelLookup is equivalent to using KernelLooup(*this, 240 train, validation). 241 242 \return sub-Lookup of the DataLookup2D 243 244 \Note Returns a dynamically allocated DataLookup2D, which has 245 to be deleted by the caller to avoid memory leaks. 246 */ 247 const KernelLookup* 248 validation_data(const std::vector<size_t>& train, 249 const std::vector<size_t>& validation) const; 250 251 /** 252 \return true if underlying Kernel is weighted 253 */ 254 bool weighted(void) const; 255 256 /** 257 \return element at position (\a row, \a column) in the Kernel 258 matrix 259 */ 260 double operator()(size_t row, size_t column) const; 261 271 262 private: 272 263 const KernelLookup& operator=(const KernelLookup&); … … 274 265 const Kernel* kernel_; 275 266 276 267 }; // class KernelLookup 277 268 278 269 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/MatrixLookup.cc
r680 r720 191 191 192 192 193 double MatrixLookup::operator()(const size_t row, const size_t column) const 194 { 195 assert(row<rows()); 196 assert(column<columns()); 197 return (*data_)(row_index_[row], column_index_[column]); 198 } 199 200 201 193 202 const MatrixLookup& MatrixLookup::operator=(const MatrixLookup& other) 194 203 { -
trunk/yat/classifier/MatrixLookup.h
r680 r720 231 231 /// @return element 232 232 /// 233 inline double operator()(const size_t row, const size_t column) const 234 { 235 assert(row<rows()); 236 assert(column<columns()); 237 return (*data_)(row_index_[row], column_index_[column]); 238 } 233 double operator()(const size_t row, const size_t column) const; 239 234 240 235 /// -
trunk/yat/classifier/MatrixLookupWeighted.cc
r680 r720 231 231 232 232 233 234 double MatrixLookupWeighted::data(size_t row, size_t column) const 235 { 236 return (*data_)(row_index_[row], column_index_[column]); 237 } 238 239 240 233 241 const MatrixLookupWeighted* 234 242 MatrixLookupWeighted::selected(const std::vector<size_t>& i) const … … 256 264 257 265 266 double MatrixLookupWeighted::weight(size_t row, size_t column) const 267 { 268 return (*weights_)(row_index_[row], column_index_[column]); 269 } 270 271 272 258 273 bool MatrixLookupWeighted::weighted(void) const 259 274 { 260 275 return true; 276 } 277 278 279 280 double MatrixLookupWeighted::operator()(const size_t row, 281 const size_t column) const 282 { 283 return (weight(row,column) ? data(row,column)*weight(row,column) : 0); 261 284 } 262 285 -
trunk/yat/classifier/MatrixLookupWeighted.h
r680 r720 211 211 /// @return data value of element (@a row, @a column) 212 212 /// 213 inline double data(size_t row, size_t column) const 214 { return (*data_)(row_index_[row], column_index_[column]); } 213 double data(size_t row, size_t column) const; 215 214 216 215 /// … … 252 251 /// @return weight value of element (@a row, @a column) 253 252 /// 254 inline double weight(size_t row, size_t column) const 255 { return (*weights_)(row_index_[row], column_index_[column]); } 253 double weight(size_t row, size_t column) const; 256 254 257 255 /// … … 265 263 /// @return weight * data for element \f$ i j\f$ 266 264 /// 267 inline double operator()(const size_t row, const size_t column) const 268 { 269 return (weight(row,column) ? data(row,column)*weight(row,column) : 0); 270 } 265 double operator()(const size_t row, const size_t column) const; 271 266 272 267 /// -
trunk/yat/classifier/NCC.cc
r685 r720 56 56 NCC::~NCC() 57 57 { 58 } 59 60 61 const utility::matrix& NCC::centroids(void) const 62 { 63 return centroids_; 58 64 } 59 65 -
trunk/yat/classifier/NCC.h
r680 r720 75 75 /// @return the centroids for each class as columns in a matrix. 76 76 /// 77 inline const utility::matrix& centroids(void) const {return centroids_;}77 const utility::matrix& centroids(void) const; 78 78 79 79 SupervisedClassifier* make_classifier(const DataLookup2D&, -
trunk/yat/classifier/SVM.cc
r706 r720 78 78 } 79 79 80 const utility::vector& SVM::alpha(void) const 81 { 82 return alpha_; 83 } 84 85 double SVM::C(void) const 86 { 87 return 1.0/C_inverse_; 88 } 80 89 81 90 void SVM::calculate_margin(void) … … 89 98 } 90 99 100 double SVM::kernel_mod(const size_t i, const size_t j) const 101 { 102 return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; 103 } 91 104 92 105 SupervisedClassifier* SVM::make_classifier(const DataLookup2D& data, … … 110 123 } 111 124 125 long int SVM::max_epochs(void) const 126 { 127 return max_epochs_; 128 } 129 130 const theplu::yat::utility::vector& SVM::output(void) const 131 { 132 return output_; 133 } 134 112 135 void SVM::predict(const DataLookup2D& input, utility::matrix& prediction) const 113 136 { … … 153 176 trained_=false; 154 177 alpha_=utility::vector(target_.size(), 0); 178 } 179 180 int SVM::target(size_t i) const 181 { 182 return target_.binary(i) ? 1 : -1; 155 183 } 156 184 -
trunk/yat/classifier/SVM.h
r706 r720 76 76 /// @return \f$ \alpha \f$ 77 77 /// 78 inline const utility::vector& alpha(void) const { return alpha_; }78 const utility::vector& alpha(void) const; 79 79 80 80 /// … … 92 92 /// @returns mean of vector \f$ C_i \f$ 93 93 /// 94 inline double C(void) const { return 1.0/C_inverse_; }94 double C(void) const; 95 95 96 96 /// … … 99 99 /// @return number of maximal epochs 100 100 /// 101 inline long int max_epochs(void) const {return max_epochs_;}101 long int max_epochs(void) const; 102 102 103 103 /** … … 107 107 @return output 108 108 */ 109 inline const theplu::yat::utility::vector& 110 output(void) const { return output_; } 109 const theplu::yat::utility::vector& output(void) const; 111 110 112 111 /** … … 219 218 /// @return kernel modified with diagonal term (soft margin) 220 219 /// 221 inline double kernel_mod(const size_t i, const size_t j) const222 { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; } 223 220 double kernel_mod(const size_t i, const size_t j) const; 221 222 /// 224 223 /// @return 1 if i belong to binary target true else -1 225 inline int target(size_t i) const { return target_.binary(i) ? 1 : -1; } 224 /// 225 int target(size_t i) const; 226 226 227 227 utility::vector alpha_; -
trunk/yat/classifier/Sampler.cc
r680 r720 38 38 } 39 39 40 u_long Sampler::size(void) const 41 { 42 return training_index_.size(); 43 } 44 45 const Target& Sampler::target(void) const 46 { 47 return target_; 48 } 49 50 const std::vector<size_t>& 51 Sampler::training_index(std::vector<size_t>::size_type i) const 52 { 53 return training_index_[i]; 54 } 55 56 const Target& 57 Sampler::training_target(std::vector<Target>::size_type i) const 58 { 59 return training_target_[i]; 60 } 61 62 const std::vector<size_t>& 63 Sampler::validation_index(std::vector<size_t>::size_type i) const 64 { 65 return validation_index_[i]; 66 } 67 68 const Target& 69 Sampler::validation_target(std::vector<Target>::size_type i) const 70 { 71 return validation_target_[i]; 72 } 73 40 74 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/Sampler.h
r680 r720 56 56 /// @return number of partitions 57 57 /// 58 inline u_long size(void) const { return training_index_.size(); }58 u_long size(void) const; 59 59 60 60 /// 61 61 /// @return the targets for the total set 62 62 /// 63 inline const Target& target(void) const { return target_; }63 const Target& target(void) const; 64 64 65 65 /// 66 66 /// @return training indices 67 67 /// 68 inline const std::vector<size_t>& 69 training_index(std::vector<size_t>::size_type i) const 70 { return training_index_[i]; } 68 const std::vector<size_t>& 69 training_index(std::vector<size_t>::size_type i) const; 71 70 72 71 /// … … 75 74 /// @note if state is invalid the result is undefined 76 75 /// 77 inline const Target& 78 training_target(std::vector<Target>::size_type i) const 79 { return training_target_[i]; } 76 const Target& 77 training_target(std::vector<Target>::size_type i) const; 80 78 81 79 /// … … 84 82 /// @note if state is invalid the result is undefined 85 83 /// 86 inline const std::vector<size_t>& 87 validation_index(std::vector<size_t>::size_type i) const 88 { return validation_index_[i]; } 84 const std::vector<size_t>& 85 validation_index(std::vector<size_t>::size_type i) const; 89 86 90 87 /// … … 93 90 /// @note if state is invalid the result is undefined 94 91 /// 95 inline const Target& 96 validation_target(std::vector<Target>::size_type i) const 97 { return validation_target_[i]; } 98 92 const Target& validation_target(std::vector<Target>::size_type i) const; 99 93 100 94 protected: -
trunk/yat/classifier/SubsetGenerator.cc
r704 r720 205 205 } 206 206 207 208 u_long SubsetGenerator::size(void) const 209 { 210 return sampler_.size(); 211 } 212 213 214 const Target& SubsetGenerator::target(void) const 215 { 216 return sampler_.target(); 217 } 218 219 220 const DataLookup2D& 221 SubsetGenerator::training_data(std::vector<DataLookup2D*>::size_type i) const 222 { 223 return *(training_data_[i]); 224 } 225 226 227 const std::vector<size_t>& 228 SubsetGenerator::training_features(std::vector<size_t>::size_type i) const 229 { 230 return f_selector_ ? features_[i] : features_[0]; 231 } 232 233 234 const std::vector<size_t>& 235 SubsetGenerator::training_index(std::vector<size_t>::size_type i) const 236 { 237 return sampler_.training_index(i); 238 } 239 240 241 const Target& 242 SubsetGenerator::training_target(std::vector<Target>::size_type i) const 243 { 244 return training_target_[i]; 245 } 246 247 248 const DataLookup2D& 249 SubsetGenerator::validation_data(std::vector<DataLookup2D*>::size_type i) const 250 { 251 return *(validation_data_[i]); 252 } 253 254 255 const std::vector<size_t>& 256 SubsetGenerator::validation_index(std::vector<size_t>::size_type i) const 257 { 258 return sampler_.validation_index(i); 259 } 260 261 262 const Target& 263 SubsetGenerator::validation_target(std::vector<Target>::size_type i) const 264 { 265 return validation_target_[i]; 266 } 267 207 268 }}} // of namespace classifier, yat, and theplu -
trunk/yat/classifier/SubsetGenerator.h
r704 r720 72 72 /// @return number of subsets 73 73 /// 74 inline u_long size(void) const { return sampler_.size(); }74 u_long size(void) const; 75 75 76 76 /// 77 77 /// @return the target for the total set 78 78 /// 79 inline const Target& target(void) const { return sampler_.target(); } 80 79 const Target& target(void) const; 81 80 82 81 /// 83 82 /// @return the sampler for the total set 84 83 /// 85 // inline const Sampler& sampler(void) const { return sampler_; } 86 84 // const Sampler& sampler(void) const; 87 85 88 86 /// 89 87 /// @return training data 90 88 /// 91 inline const DataLookup2D& training_data(std::vector<DataLookup2D*>:: 92 size_type i) const 93 { return *(training_data_[i]); } 89 const DataLookup2D& 90 training_data(std::vector<DataLookup2D*>::size_type i) const; 94 91 95 92 /// 96 93 /// @return training features 97 94 /// 98 inline const std::vector<size_t>& training_features(std::vector<size_t>:: 99 size_type i) const 100 { return f_selector_ ? features_[i] : features_[0]; } 101 95 const std::vector<size_t>& 96 training_features(std::vector<size_t>::size_type i) const; 102 97 103 98 /// 104 99 /// @return training index 105 100 /// 106 inline const std::vector<size_t>& training_index(std::vector<size_t>:: 107 size_type i) const 108 { return sampler_.training_index(i); } 101 const std::vector<size_t>& 102 training_index(std::vector<size_t>::size_type i) const; 109 103 110 104 /// 111 105 /// @return training target 112 106 /// 113 inline const Target& training_target(std::vector<Target>:: 114 size_type i) const 115 { return training_target_[i]; } 107 const Target& training_target(std::vector<Target>::size_type i) const; 116 108 117 109 /// 118 110 /// @return validation data 119 111 /// 120 inline const DataLookup2D& validation_data(std::vector<DataLookup2D*>:: 121 size_type i) const 122 { return *(validation_data_[i]); } 112 const DataLookup2D& 113 validation_data(std::vector<DataLookup2D*>::size_type i) const; 123 114 124 115 /// 125 116 /// @return validation index 126 117 /// 127 inline const std::vector<size_t>& validation_index(std::vector<size_t>:: 128 size_type i) const 129 { return sampler_.validation_index(i); } 118 const std::vector<size_t>& 119 validation_index(std::vector<size_t>::size_type i) const; 130 120 131 121 /// 132 122 /// @return validation target 133 123 /// 134 inline const Target& validation_target(std::vector<Target>:: 135 size_type i) const 136 { return validation_target_[i]; } 124 const Target& validation_target(std::vector<Target>::size_type i) const; 137 125 138 126 /// 139 127 /// @return true if weighted 140 128 /// @todo remove this function 141 // inline bool weighted(void) const { return weighted_; }129 //bool weighted(void) const; 142 130 143 131 private: -
trunk/yat/classifier/Target.h
r714 r720 59 59 /// @brief Copy Constructor 60 60 /// 61 // inlineTarget(const Target& other)61 //Target(const Target& other) 62 62 // : classes_(other.classes_), class_map_(other.class_map_), 63 63 // labels_(other.labels_) {}
Note: See TracChangeset
for help on using the changeset viewer.