Changeset 330
- Timestamp:
- Jun 1, 2005, 11:30:47 PM (18 years ago)
- Location:
- trunk/lib/svm
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/svm/Kernel_MEV.cc
r307 r330 10 10 namespace svm { 11 11 12 Kernel_MEV::Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf)13 : data_(data), kf_(&kf)14 {15 }12 Kernel_MEV::Kernel_MEV(const gslapi::matrix& data, const KernelFunction& kf) 13 : Kernel(data, kf) 14 { 15 } 16 16 17 17 18 Kernel_MEV::~Kernel_MEV(void)19 {20 }21 18 22 double Kernel_MEV::operator()(size_t row, size_t column) const 23 { 24 return (*kf_)(data_.TEMP_col_return(row),data_.TEMP_col_return(column)); 25 } 19 Kernel_MEV::~Kernel_MEV(void) 20 { 21 } 22 23 24 25 double Kernel_MEV::operator()(size_t row, size_t column) const 26 { 27 return (*kf_)(data_.TEMP_col_return(row),data_.TEMP_col_return(column)); 28 } 26 29 27 30 -
trunk/lib/svm/Kernel_MEV.h
r322 r330 4 4 #define _theplu_svm_kernel_mev 5 5 6 #include <c++_tools/svm/Kernel.h> 6 7 #include <c++_tools/gslapi/matrix.h> 7 8 … … 22 23 /// @see also Kernel_SEV 23 24 /// 24 class Kernel_MEV 25 class Kernel_MEV : public Kernel 25 26 { 26 27 27 28 public: 28 29 30 /// 31 /// Default constructor (not implemented) 32 /// 29 33 Kernel_MEV(); 30 34 … … 53 57 /// matrix 54 58 /// 55 virtualdouble operator()(const size_t row,const size_t column) const;59 double operator()(const size_t row,const size_t column) const; 56 60 57 ///58 /// @brief number of samples59 ///60 inline size_t size(void) const { return data_.columns(); }61 62 protected:63 const gslapi::matrix& data_;64 const KernelFunction* kf_;65 61 66 62 }; // class Kernel_MEV -
trunk/lib/svm/Kernel_SEV.cc
r307 r330 3 3 #include <c++_tools/svm/Kernel_SEV.h> 4 4 5 #include <c++_tools/svm/Kernel.h> 5 6 #include <c++_tools/svm/KernelFunction.h> 6 #include <c++_tools/svm/Kernel_MEV.h>7 7 #include <c++_tools/gslapi/matrix.h> 8 8 #include <c++_tools/gslapi/vector.h> … … 12 12 13 13 Kernel_SEV::Kernel_SEV(const gslapi::matrix& data, const KernelFunction& kf) 14 : Kernel _MEV(data,kf)14 : Kernel(data,kf) 15 15 { 16 kernel_ = gslapi::matrix(data.columns(),data.columns());17 for (size_t i=0; i<kernel_ .rows(); i++)18 for (size_t j=i; j<kernel_ .columns(); j++)19 kernel_ (i,j) = kernel_(j,i) =16 kernel_matrix_ = gslapi::matrix(data.columns(),data.columns()); 17 for (size_t i=0; i<kernel_matrix_.rows(); i++) 18 for (size_t j=i; j<kernel_matrix_.columns(); j++) 19 kernel_matrix_(i,j) = kernel_matrix_(j,i) = 20 20 (*kf_)(data_.TEMP_col_return(i),data_.TEMP_col_return(j)); 21 21 -
trunk/lib/svm/Kernel_SEV.h
r322 r330 5 5 6 6 #include <c++_tools/gslapi/matrix.h> 7 #include <c++_tools/svm/Kernel _MEV.h>7 #include <c++_tools/svm/Kernel.h> 8 8 9 9 … … 24 24 /// @see also Kernel_MEV 25 25 /// 26 class Kernel_SEV : public Kernel _MEV26 class Kernel_SEV : public Kernel 27 27 { 28 28 … … 51 51 /// 52 52 inline double operator()(const size_t row,const size_t column) const 53 { return kernel_ (row,column); }53 { return kernel_matrix_(row,column); } 54 54 55 55 private: 56 gslapi::matrix kernel_ ;56 gslapi::matrix kernel_matrix_; 57 57 58 58 }; // class Kernel_SEV -
trunk/lib/svm/Makefile.am
r319 r330 10 10 libsvm_la_SOURCES = \ 11 11 ConsensusInputRanker.cc CrossValidation.cc GaussianKernelFunction.cc \ 12 InputRanker.cc Kernel _MEV.cc Kernel_SEV.cc \12 InputRanker.cc Kernel.cc Kernel_MEV.cc Kernel_SEV.cc \ 13 13 PolynomialKernelFunction.cc SVM.cc 14 14 … … 17 17 include_svm_HEADERS = \ 18 18 ConsensusInputRanker.h CrossValidation.h GaussianKernelFunction.h \ 19 InputRanker.h Kernel Function.h Kernel_MEV.h Kernel_SEV.h \19 InputRanker.h Kernel.h KernelFunction.h Kernel_MEV.h Kernel_SEV.h \ 20 20 PolynomialKernelFunction.h SVM.h -
trunk/lib/svm/SVM.cc
r323 r330 4 4 #include <c++_tools/svm/SVM.h> 5 5 6 #include <c++_tools/svm/Kernel _MEV.h>6 #include <c++_tools/svm/Kernel.h> 7 7 #include <c++_tools/gslapi/matrix.h> 8 8 #include <c++_tools/gslapi/vector.h> … … 137 137 } 138 138 139 SVM::SVM(const Kernel_MEV& kernel, 140 const gslapi::vector& target) 139 SVM::SVM(const Kernel& kernel, const gslapi::vector& target) 141 140 142 141 : alpha_(target.size(),0), 143 142 bias_(0), 144 143 C_inverse_(0), 145 kernel_( kernel),144 kernel_(&kernel), 146 145 max_epochs_(10000000), 147 146 output_(target.size(),0), … … 160 159 { 161 160 // initializing variables for optimization 162 assert(target_.size()==kernel_ .size());161 assert(target_.size()==kernel_->size()); 163 162 assert(target_.size()==alpha_.size()); 164 163 … … 358 357 output_(i)=0; 359 358 for (size_t j=0; j<output_.size(); j++) 360 output_(i)+=alpha_(j)*target_(j)* kernel_(i,j);359 output_(i)+=alpha_(j)*target_(j)*(*kernel_)(i,j); 361 360 } 362 361 -
trunk/lib/svm/SVM.h
r323 r330 4 4 #define _theplu_svm_svm_ 5 5 6 #include <c++_tools/svm/Kernel _MEV.h>6 #include <c++_tools/svm/Kernel.h> 7 7 #include <c++_tools/gslapi/vector.h> 8 8 … … 13 13 namespace theplu { 14 14 namespace svm { 15 16 class Kernel; 15 17 16 18 // @internal Class keeping track of which samples are support vectors and … … 89 91 90 92 /// 91 /// Class for SVM using Keerthi's second modification of Platt's SMO. 93 /// Class for SVM using Keerthi's second modification of Platt's 94 /// Sequential Minimal Optimization. The SVM uses all data given for 95 /// training. If validation or testing is wanted this should be 96 /// taken care of outside (in the kernel). 92 97 /// 93 98 class SVM … … 101 106 102 107 /// 103 /// Constructor taking the kernel and the target vector as input. 104 /// 105 SVM(const Kernel_MEV&, 106 const gslapi::vector&); 108 /// Constructor taking the kernel and the target vector as 109 /// input. @note if the kernel or target is destroyed the SVM is 110 /// no longer defined 111 /// 112 SVM(const Kernel&, const gslapi::vector&); 107 113 108 114 /// … … 168 174 double bias_; 169 175 double C_inverse_; 170 const Kernel _MEV&kernel_;176 const Kernel* kernel_; 171 177 unsigned long int max_epochs_; 172 178 gslapi::vector output_; … … 202 208 203 209 /// 204 /// @return kernel modified inwith diagonal term (soft margin)210 /// @return kernel modified with diagonal term (soft margin) 205 211 /// 206 212 inline double kernel_mod(const size_t i, const size_t j) const 207 { return i!=j ? kernel_(i,j) : kernel_(i,j) + C_inverse_; }213 { return i!=j ? (*kernel_)(i,j) : (*kernel_)(i,j) + C_inverse_; } 208 214 209 215 };
Note: See TracChangeset
for help on using the changeset viewer.