1 | // $Id$ |
---|
2 | |
---|
3 | #ifndef _theplu_classifier_kernel_sev_ |
---|
4 | #define _theplu_classifier_kernel_sev_ |
---|
5 | |
---|
6 | #include <c++_tools/classifier/Kernel.h> |
---|
7 | #include <c++_tools/gslapi/matrix.h> |
---|
8 | |
---|
9 | |
---|
10 | namespace theplu { |
---|
11 | namespace classifier { |
---|
12 | |
---|
13 | class DataLookup1D; |
---|
14 | class KernelFunction; |
---|
15 | |
---|
16 | /// |
---|
17 | /// @brief Speed Efficient Kernel |
---|
18 | /// Class taking care of the \f$ NxN \f$ kernel matrix, where |
---|
19 | /// \f$ N \f$ is number of samples. Type of Kernel is defined by a |
---|
20 | /// KernelFunction. This Speed Efficient Version (SEV) calculated |
---|
21 | /// the kernel matrix once by construction and the kernel is stored in |
---|
22 | /// memory. When \f$ N \f$ is large and the kernel matrix cannot be |
---|
23 | /// stored in memory, use Kernel_MEV instead. |
---|
24 | /// |
---|
25 | /// @see also Kernel_MEV KernelWeighted_SEV |
---|
26 | /// |
---|
27 | class Kernel_SEV : public Kernel |
---|
28 | { |
---|
29 | |
---|
30 | public: |
---|
31 | |
---|
32 | /// |
---|
33 | /// Constructor taking the data matrix and KernelFunction as |
---|
34 | /// input. @note Can not handle NaNs. When dealing with missing values, |
---|
35 | /// use KernelWeighted_SEV instead. |
---|
36 | /// |
---|
37 | Kernel_SEV(const MatrixLookup&, const KernelFunction&); |
---|
38 | |
---|
39 | /// |
---|
40 | /// @todo remove |
---|
41 | /// |
---|
42 | Kernel_SEV(const Kernel_SEV& kernel, const std::vector<size_t>& index); |
---|
43 | |
---|
44 | /// |
---|
45 | /// @return element at position (\a row, \a column) in the Kernel |
---|
46 | /// matrix |
---|
47 | /// |
---|
48 | inline double operator()(const size_t row,const size_t column) const |
---|
49 | { return kernel_matrix_(row,column); } |
---|
50 | |
---|
51 | /// |
---|
52 | /// Calculates the scalar product using the KernelFunction between |
---|
53 | /// data vector @a vec and column \f$ i \f$ in data matrix. |
---|
54 | /// |
---|
55 | /// @return kernel element between data @a vec and training sample @a i |
---|
56 | /// |
---|
57 | double element(const DataLookup1D& vec, const size_t i) const; |
---|
58 | |
---|
59 | /// |
---|
60 | /// Using the KernelFunction this function calculates the scalar |
---|
61 | /// product between vector @a vec and the column \f$ i \f$ in data |
---|
62 | /// matrix. The KernelFunction expects a weight vector for each of |
---|
63 | /// the two data vectors and as this Kernel is non-weighted each |
---|
64 | /// value in the data matrix is associated to a unity weight. |
---|
65 | /// |
---|
66 | /// @return weighted kernel element between data @a vec and |
---|
67 | /// training sample @a i |
---|
68 | /// |
---|
69 | double element(const DataLookup1D& vec, const DataLookup1D& w, |
---|
70 | const size_t i) const; |
---|
71 | |
---|
72 | /// |
---|
73 | /// @todo remove this function |
---|
74 | /// |
---|
75 | const Kernel* selected(const std::vector<size_t>& index) const; |
---|
76 | |
---|
77 | /// |
---|
78 | /// @return false |
---|
79 | /// |
---|
80 | inline bool weighted(void) const { return false; } |
---|
81 | |
---|
82 | private: |
---|
83 | /// |
---|
84 | /// Copy constructor (not implemented) |
---|
85 | /// |
---|
86 | Kernel_SEV(const Kernel_SEV&); |
---|
87 | const Kernel_SEV& operator=(const Kernel_SEV&); |
---|
88 | |
---|
89 | void build_kernel(void); |
---|
90 | |
---|
91 | gslapi::matrix kernel_matrix_; |
---|
92 | |
---|
93 | }; // class Kernel_SEV |
---|
94 | |
---|
95 | }} // of namespace classifier and namespace theplu |
---|
96 | |
---|
97 | #endif |
---|