source: trunk/lib/classifier/KernelWeighted_SEV.h @ 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: 2.5 KB
Line 
1// $Id: KernelWeighted_SEV.h 545 2006-03-06 13:35:45Z peter $
2
3#ifndef _theplu_classifier_kernel_weighted_sev_
4#define _theplu_classifier_kernel_weighted_sev_
5
6#include <c++_tools/classifier/DataLookup1D.h>
7#include <c++_tools/classifier/Kernel.h>
8#include <c++_tools/classifier/MatrixLookup.h>
9#include <c++_tools/gslapi/matrix.h>
10#include <c++_tools/gslapi/vector.h>
11
12
13namespace theplu {
14namespace classifier {
15
16  class KernelFunction;
17
18  ///
19  ///   @brief Speed Efficient Kernel
20  ///   Class taking care of the \f$NxN\f$ kernel matrix, where
21  ///   \f$N\f$ is number of samples. Type of Kernel is defined by a
22  ///   KernelFunction. This Speed Efficient Version (SEV) calculated
23  ///   the kernel matrix once and the kernel is stored in
24  ///   memory. When \f$N\f$ is large and the kernel matrix cannot be
25  ///   stored in memory, use Kernel_MEV instead.
26  ///   
27  ///   @see also Kernel_MEV
28  ///
29  class KernelWeighted_SEV : public Kernel
30  {
31   
32  public:
33
34    ///
35    ///   Constructor taking the data matrix and KernelFunction as
36    ///   input. @note Can not handle NaNs. When dealing with missing values,
37    ///   use constructor taking a weight matrix.
38    ///
39    /// @note if @a data, @a kf, or @a weights is destroyed the
40    /// behaviour of the object is undefined
41    ///
42    KernelWeighted_SEV(const MatrixLookup& data, const KernelFunction& kf, 
43                       const MatrixLookup& weights);
44
45    ///
46    /// @todo doc
47    ///
48    KernelWeighted_SEV(const KernelWeighted_SEV& other, 
49                       const std::vector<size_t>& index);
50   
51    ///
52    /// @return element at position (\a row, \a column) in the Kernel
53    /// matrix
54    ///
55    inline double operator()(const size_t row,const size_t column) const
56    { return kernel_matrix_(row,column); }
57
58    ///
59    /// @return kernel element between data @a ve and training sample @a i
60    ///
61    inline double element(const DataLookup1D& vec, const size_t i) const
62    { 
63      return (*kf_)(vec, DataLookup1D(*data_,i), 
64                    DataLookup1D(vec.size(),1.0),
65                    DataLookup1D(*weights_,i)); 
66    }
67
68    inline double element(const DataLookup1D& vec, const DataLookup1D& w, 
69                          const size_t i) const
70    { 
71      return (*kf_)(vec, DataLookup1D(*data_,i),w,DataLookup1D(*weights_,i)); 
72    }
73
74    ///
75    /// @todo doc
76    ///
77    const KernelWeighted_SEV* selected(const std::vector<size_t>& index) const;
78
79    ///
80    /// @return true
81    ///
82    inline bool weighted(void) const { return true; }
83
84  private:
85    /// Copy constructor (not implemented)
86    KernelWeighted_SEV(const KernelWeighted_SEV&);
87
88    gslapi::matrix kernel_matrix_;
89
90  }; // class Kernel_SEV
91
92}} // of namespace classifier and namespace theplu
93
94#endif
Note: See TracBrowser for help on using the repository browser.