Changeset 353
- Timestamp:
- Jun 9, 2005, 1:28:35 AM (18 years ago)
- Location:
- trunk/lib/svm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/svm/GaussianKernelFunction.cc
r295 r353 34 34 35 35 36 const theplu::gslapi::matrix&37 GaussianKernelFunction::operator()(theplu::gslapi::matrix& k,38 const theplu::gslapi::matrix& data) const39 {40 theplu::gslapi::matrix data_transposed(data);41 data_transposed.transpose();42 k = data_transposed*data;43 // Working with the linear linear kernel in order to avoid copying44 // row vectors from data matrix (many times) and calculate the45 // kernel element in a more transparent way.46 for (size_t i=0; i<k.rows()-1; i++)47 for (size_t j=i+1; j<k.columns(); j++)48 k(i,j)=k(j,i)=exp(-(k(i,i)+k(j,j)-2*k(i,j))/(2*sigma_));49 for (size_t i=0; i<k.rows(); i++)50 k(i,i)=1;51 return k;52 }53 36 54 37 }} // of namespace svn and namespace theplu -
trunk/lib/svm/GaussianKernelFunction.h
r345 r353 50 50 const gslapi::vector& w2) const; 51 51 52 ///53 /// @return kernel matrix54 ///55 const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel,56 const theplu::gslapi::matrix& data) const;57 58 52 private: 59 53 double sigma_; -
trunk/lib/svm/KernelFunction.h
r295 r353 44 44 const gslapi::vector&) const = 0; 45 45 46 ///47 /// @return kernel matrix48 ///49 virtual const theplu::gslapi::matrix& operator()50 (theplu::gslapi::matrix& k, const gslapi::matrix& data) const = 0;51 52 46 }; // class KernelFunction 53 47 -
trunk/lib/svm/PolynomialKernelFunction.cc
r345 r353 36 36 } 37 37 38 const theplu::gslapi::matrix&39 PolynomialKernelFunction::operator()(theplu::gslapi::matrix& kernel,40 const theplu::gslapi::matrix& data) const41 {42 gslapi::matrix data_transposed(data.transpose());43 kernel = data_transposed*data;44 if (order_>1)45 for (size_t i=0; i<kernel.rows(); i++)46 for (size_t j=i; j<kernel.rows(); j++)47 kernel(i,j)=kernel(j,i)=pow(1+kernel(i,j),order_);48 return kernel;49 }50 38 }} // of namespace cpptools and namespace theplu -
trunk/lib/svm/PolynomialKernelFunction.h
r345 r353 55 55 const gslapi::vector&, const gslapi::vector&) const; 56 56 57 ///58 /// @return kernel matrix59 ///60 const gslapi::matrix& operator()(theplu::gslapi::matrix& kernel,61 const theplu::gslapi::matrix& data) const;62 63 57 private: 64 58 int order_;
Note: See TracChangeset
for help on using the changeset viewer.