Changeset 1163
- Timestamp:
- Feb 26, 2008, 6:15:43 PM (16 years ago)
- Location:
- trunk/yat/classifier
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/Kernel.cc
r1146 r1163 30 30 #include "MatrixLookupWeighted.h" 31 31 32 #include <cassert> 32 33 #include <vector> 33 34 … … 38 39 Kernel::Kernel(const MatrixLookup& data, const KernelFunction& kf, 39 40 const bool own) 40 : data_(&data), data_w_(0), kf_(&kf), ref_count_w_(NULL)41 : ml_(&data), mlw_(0), kf_(&kf), ref_count_w_(NULL) 41 42 { 42 43 if (own) … … 49 50 Kernel::Kernel(const MatrixLookupWeighted& data, const KernelFunction& kf, 50 51 const bool own) 51 : data_(&data), data_w_(&data), kf_(&kf)52 : ml_(NULL), mlw_(&data), kf_(&kf) 52 53 { 53 54 if (own){ 54 ref_count_ = new u_int(1);55 55 ref_count_w_ = new u_int(1); 56 56 } 57 57 else { 58 ref_count_ = NULL;59 58 ref_count_w_ = NULL; 60 59 } 60 ref_count_ = NULL; 61 61 } 62 62 … … 65 65 : kf_(other.kf_) 66 66 { 67 data_ = other.data_->selected(utility::Index(index));68 ref_count_ = new u_int(1);69 67 70 if (other. data_w_){71 data_w_ = other.data_w_->selected(utility::Index(index));68 if (other.weighted()){ 69 mlw_ = other.mlw_->selected(utility::Index(index)); 72 70 ref_count_w_ = new u_int(1); 71 ml_=NULL; 72 ref_count_ = NULL; 73 73 } 74 74 else{ 75 data_w_=NULL; 75 ml_ = other.ml_->selected(utility::Index(index)); 76 ref_count_ = new u_int(1); 77 mlw_=NULL; 76 78 ref_count_w_ = NULL; 77 79 } … … 84 86 if (ref_count_) 85 87 if (!--(*ref_count_)) 86 delete data_;88 delete ml_; 87 89 88 90 if (ref_count_w_) 89 91 if (!--(*ref_count_w_)) 90 delete data_w_;92 delete mlw_; 91 93 92 94 } … … 95 97 const DataLookup2D& Kernel::data(void) const 96 98 { 97 return *data_; 99 if (weighted()) 100 return *mlw_; 101 return *ml_; 98 102 } 99 103 … … 101 105 double Kernel::element(const DataLookup1D& vec, const size_t i) const 102 106 { 103 if ( data_w_)104 return kf_->operator()(vec, DataLookupWeighted1D(* data_w_,i, false));107 if (weighted()) 108 return kf_->operator()(vec, DataLookupWeighted1D(*mlw_,i, false)); 105 109 else 106 return kf_->operator()(vec,DataLookup1D(dynamic_cast<const MatrixLookup&> 107 (*data_),i, false)); 110 return kf_->operator()(vec,DataLookup1D(*ml_,i, false)); 108 111 } 109 112 … … 111 114 double Kernel::element(const DataLookupWeighted1D& vec, const size_t i) const 112 115 { 113 if ( data_w_)114 return kf_->operator()(vec, DataLookupWeighted1D(* data_w_,i, false));116 if (weighted()) 117 return kf_->operator()(vec, DataLookupWeighted1D(*mlw_,i, false)); 115 118 else 116 return kf_->operator()(vec, DataLookup1D(dynamic_cast<const MatrixLookup&> 117 (*data_),i, false)); 119 return kf_->operator()(vec, DataLookup1D(*ml_,i, false)); 118 120 } 119 121 … … 121 123 size_t Kernel::size(void) const 122 124 { 123 return data_->columns(); 125 if (weighted()) 126 return mlw_->columns(); 127 assert(ml_); 128 return ml_->columns(); 124 129 } 125 130 … … 127 132 bool Kernel::weighted(void) const 128 133 { 129 return data_w_;134 return mlw_; 130 135 } 131 136 -
trunk/yat/classifier/Kernel.h
r1125 r1163 162 162 protected: 163 163 /// underlying data 164 const DataLookup2D* data_;164 const MatrixLookup* ml_; 165 165 /// same as data_ if weifghted otherwise a NULL pointer 166 const MatrixLookupWeighted* data_w_;166 const MatrixLookupWeighted* mlw_; 167 167 /// type of Kernel Function e.g. Gaussian (aka RBF) 168 168 const KernelFunction* kf_; -
trunk/yat/classifier/Kernel_MEV.cc
r1146 r1163 68 68 double Kernel_MEV::operator()(const size_t row, const size_t column) const 69 69 { 70 if ( data_w_)71 return (*kf_)(DataLookupWeighted1D(* data_w_,row,false),72 DataLookupWeighted1D(* data_w_,column,false));70 if (weighted()) 71 return (*kf_)(DataLookupWeighted1D(*mlw_,row,false), 72 DataLookupWeighted1D(*mlw_,column,false)); 73 73 else 74 return (*kf_)(DataLookup1D(dynamic_cast<const MatrixLookup&> 75 (*data_),row,false), 76 DataLookup1D(dynamic_cast<const MatrixLookup&> 77 (*data_),column,false)); 74 return (*kf_)(DataLookup1D(*ml_,row,false), 75 DataLookup1D(*ml_,column,false)); 78 76 } 79 77 -
trunk/yat/classifier/Kernel_SEV.cc
r1146 r1163 47 47 : Kernel(data,kf, own) 48 48 { 49 kernel_matrix_.resize(data _->columns(),data_->columns());49 kernel_matrix_.resize(data.columns(),data.columns()); 50 50 for (size_t i=0; i<kernel_matrix_.rows(); i++) 51 51 for (size_t j=i; j<kernel_matrix_.columns(); j++) … … 66 66 void Kernel_SEV::build_kernel(void) 67 67 { 68 kernel_matrix_.resize( data_->columns(),data_->columns());68 kernel_matrix_.resize(size(),size()); 69 69 for (size_t i=0; i<kernel_matrix_.rows(); i++) 70 70 for (size_t j=i; j<kernel_matrix_.columns(); j++) 71 71 kernel_matrix_(i,j) = kernel_matrix_(j,i) = 72 (*kf_)(DataLookup1D( dynamic_cast<const MatrixLookup&>(*data_),i,false),73 DataLookup1D( dynamic_cast<const MatrixLookup&>(*data_),j,false));72 (*kf_)(DataLookup1D(*ml_,i,false), 73 DataLookup1D(*ml_,j,false)); 74 74 } 75 75
Note: See TracChangeset
for help on using the changeset viewer.