Changeset 1165 for trunk/yat/classifier
- Timestamp:
- Feb 26, 2008, 8:06:28 PM (15 years ago)
- Location:
- trunk/yat/classifier
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/Kernel.cc
r1163 r1165 95 95 96 96 97 const DataLookup2D& Kernel::data(void) const97 const MatrixLookup& Kernel::data(void) const 98 98 { 99 99 if (weighted()) 100 return *mlw_; 100 throw std::runtime_error("Kernel:data when Kernel is weighted"); 101 assert(ml_); 101 102 return *ml_; 103 } 104 105 106 const MatrixLookupWeighted& Kernel::data_weighted(void) const 107 { 108 if (!weighted()) 109 throw std::runtime_error("Kernel:data when Kernel is weighted"); 110 assert(mlw_); 111 return *mlw_; 102 112 } 103 113 -
trunk/yat/classifier/Kernel.h
r1163 r1165 36 36 namespace classifier { 37 37 38 class DataLookup2D;39 38 class MatrixLookup; 40 39 class MatrixLookupWeighted; … … 109 108 /// @return const reference to the underlying data. 110 109 /// 111 const DataLookup2D& data(void) const; 110 /// \throw if data in weighted 111 /// 112 const MatrixLookup& data(void) const; 113 114 /// 115 /// @return const reference to the underlying data. 116 /// 117 /// \throw if data in unweighted 118 /// 119 const MatrixLookupWeighted& data_weighted(void) const; 112 120 113 121 /// -
trunk/yat/classifier/KernelLookup.cc
r1134 r1165 135 135 136 136 137 const DataLookup2D* KernelLookup::data(void) const 138 { 139 return kernel_->data().training_data(column_index_); 137 utility::SmartPtr<const MatrixLookup> KernelLookup::data(void) const 138 { 139 return utility::SmartPtr<const MatrixLookup> 140 (kernel_->data().training_data(column_index_)); 141 } 142 143 144 utility::SmartPtr<const MatrixLookupWeighted> 145 KernelLookup::data_weighted(void) const 146 { 147 return utility::SmartPtr<const MatrixLookupWeighted> 148 (kernel_->data_weighted().training_data(column_index_)); 140 149 } 141 150 … … 184 193 const Kernel* kernel; 185 194 if (kernel_->weighted()){ 186 const MatrixLookupWeighted* ml = 187 dynamic_cast<const MatrixLookupWeighted*>(data()); 188 assert(ml); 195 utility::SmartPtr<const MatrixLookupWeighted> ml = data_weighted(); 189 196 const MatrixLookupWeighted* ms = 190 197 new MatrixLookupWeighted(*ml,inputs,true); … … 192 199 } 193 200 else { 194 const MatrixLookup* m = 195 dynamic_cast<const MatrixLookup*>(data()); 196 assert(m); 201 utility::SmartPtr<const MatrixLookup> m = data(); 197 202 // matrix with selected features 198 203 const MatrixLookup* ms = new MatrixLookup(*m,inputs,true); … … 206 211 { 207 212 208 assert(data.rows()==kernel_->data().rows());209 213 if (!weighted()){ 214 assert(data.rows()==kernel_->data().rows()); 210 215 utility::Matrix* data_all = 211 216 new utility::Matrix(data.rows(), row_index_.size()+data.columns()); … … 242 247 } 243 248 249 assert(data.rows()==kernel_->data_weighted().rows()); 244 250 // kernel_ holds MatrixLookupWeighted, hence new Kernel also 245 251 // should hold a MatrixLookupweighted. … … 248 254 utility::Matrix* weight_all = 249 255 new utility::Matrix(data.rows(), rows()+data.columns(), 1.0); 250 const MatrixLookupWeighted& kernel_data = 251 dynamic_cast<const MatrixLookupWeighted&>(kernel_->data()); 256 const MatrixLookupWeighted& kernel_data = kernel_->data_weighted(); 252 257 253 258 for (size_t i=0; i<data.rows(); ++i){ … … 292 297 293 298 if (weighted()){ 294 const MatrixLookupWeighted& kernel_data = 295 dynamic_cast<const MatrixLookupWeighted&>(kernel_->data()); 299 const MatrixLookupWeighted& kernel_data = kernel_->data_weighted(); 296 300 297 301 for (size_t i=0; i<data.rows(); ++i){ … … 305 309 else { 306 310 307 dynamic_cast<const MatrixLookupWeighted&>(kernel_->data());308 309 311 for (size_t i=0; i<data.rows(); ++i){ 310 312 // first columns are equal to data in kernel_ -
trunk/yat/classifier/KernelLookup.h
r1134 r1165 38 38 namespace classifier { 39 39 40 class DataLookup2D;41 40 class KernelFunction; 42 41 class MatrixLookup; … … 210 209 /// \return data that KernelLookup is built upon. 211 210 /// 212 /// @note Returns a dynamically allocated MatrixLookup, which has 213 /// to be deleted by the caller to avoid memory leaks. 214 /// 215 const DataLookup2D* data(void) const; 211 /// \throw if KernelLookup is weighted 212 /// 213 utility::SmartPtr<const MatrixLookup> data(void) const; 214 215 /// 216 /// Each column in returned DataLookup corresponds to the column 217 /// in KernelLookup. 218 /// 219 /// \return data that KernelLookup is built upon. 220 /// 221 /// \throw if KernelLookup is unweighted 222 /// 223 utility::SmartPtr<const MatrixLookupWeighted> data_weighted(void) const; 216 224 217 225 /** … … 275 283 this was built from. 276 284 277 @note Returns a dynamically allocated DataLookup2D, which has285 @note Returns a dynamically allocated KernelLookup, which has 278 286 to be deleted by the caller to avoid memory leaks. 279 287 */ -
trunk/yat/classifier/SubsetGenerator.h
r1134 r1165 26 26 */ 27 27 28 #include "DataLookup2D.h"29 28 #include "FeatureSelector.h" 30 29 #include "KernelLookup.h" … … 280 279 training_target_.push_back(Target(target(),training_index(k))); 281 280 validation_target_.push_back(Target(target(),validation_index(k))); 282 const DataLookup2D* matrix = kernel.data(); 283 // dynamically allocated must be deleted 284 const DataLookup2D* training_matrix = 285 matrix->training_data(training_index(k)); 286 if (matrix->weighted()){ 287 const MatrixLookupWeighted& ml = 288 dynamic_cast<const MatrixLookupWeighted&>(*matrix); 289 f_selector_->update(MatrixLookupWeighted(ml,training_index(k),false), 281 282 if (kernel.weighted()){ 283 utility::SmartPtr<const MatrixLookupWeighted> ml=kernel.data_weighted(); 284 f_selector_->update(MatrixLookupWeighted(*ml,training_index(k),false), 290 285 training_target(k)); 291 286 } 292 287 else { 293 const MatrixLookup& ml = 294 dynamic_cast<const MatrixLookup&>(*matrix); 295 f_selector_->update(MatrixLookup(ml,training_index(k), false), 288 utility::SmartPtr<const MatrixLookup> ml=kernel.data(); 289 f_selector_->update(MatrixLookup(*ml,training_index(k), false), 296 290 training_target(k)); 297 291 } … … 300 294 //features_.push_back(f_selector_->features()); 301 295 const KernelLookup* kl = kernel.selected(features_.back()); 302 utility::yat_assert<std::runtime_error>(training_matrix);303 delete training_matrix;304 296 305 297 // Dynamically allocated. Must be deleted in destructor.
Note: See TracChangeset
for help on using the changeset viewer.