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