source: trunk/lib/classifier/Kernel_SEV.cc @ 545

Last change on this file since 545 was 545, checked in by Peter, 17 years ago

added feature selection for SVM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1// $Id: Kernel_SEV.cc 545 2006-03-06 13:35:45Z peter $
2
3#include <c++_tools/classifier/Kernel_SEV.h>
4
5#include <c++_tools/classifier/DataLookup1D.h>
6#include <c++_tools/classifier/Kernel.h>
7#include <c++_tools/classifier/KernelFunction.h>
8#include <c++_tools/classifier/MatrixLookup.h>
9#include <c++_tools/gslapi/matrix.h>
10#include <c++_tools/gslapi/vector.h>
11
12namespace theplu {
13namespace classifier { 
14
15
16  Kernel_SEV::Kernel_SEV(const MatrixLookup& data, const KernelFunction& kf)
17    : Kernel(data,kf)
18  {
19    kernel_matrix_ = gslapi::matrix(data.columns(),data.columns());
20    for (size_t i=0; i<kernel_matrix_.rows(); i++) 
21      for (size_t j=i; j<kernel_matrix_.columns(); j++)
22        kernel_matrix_(i,j) = kernel_matrix_(j,i) =
23          (*kf_)(DataLookup1D(*data_,i,false),DataLookup1D(*data_,j,false));
24  }
25
26  Kernel_SEV::Kernel_SEV(const Kernel_SEV& other, 
27                         const std::vector<size_t>& index)
28    : Kernel(other, index)
29  {
30  }
31
32  double Kernel_SEV::element(const DataLookup1D& vec, const size_t i) const
33  { 
34    return kf_->operator()(vec, DataLookup1D(*data_,i)); 
35  }
36
37  double Kernel_SEV::element(const DataLookup1D& vec, const DataLookup1D& w,
38                             const size_t i) const
39  { 
40    return (*kf_)(vec, DataLookup1D(*data_,i), w, DataLookup1D(w.size(),1.0));
41  }
42
43  const Kernel* Kernel_SEV::selected(const std::vector<size_t>& index) const
44  {
45    return new Kernel_SEV(*this, index);
46  }
47
48
49}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.