1 | // $Id$ |
---|
2 | |
---|
3 | #ifndef _theplu_classifier_kernel_weighted_mev_ |
---|
4 | #define _theplu_classifier_kernel_weighted_mev_ |
---|
5 | |
---|
6 | #include <c++_tools/classifier/Kernel.h> |
---|
7 | |
---|
8 | #include <c++_tools/classifier/DataLookup1D.h> |
---|
9 | #include <c++_tools/classifier/KernelFunction.h> |
---|
10 | #include <c++_tools/classifier/MatrixLookup.h> |
---|
11 | |
---|
12 | namespace theplu { |
---|
13 | namespace classifier { |
---|
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 matrix |
---|
20 | /// in memory, but calculates an element when it is needed. When |
---|
21 | /// memory allows do always use KernelWeighted_SEV instead. |
---|
22 | /// |
---|
23 | /// @see Kernel_MEV KernelWeighted_SEV |
---|
24 | /// |
---|
25 | class KernelWeighted_MEV : public Kernel |
---|
26 | { |
---|
27 | |
---|
28 | public: |
---|
29 | |
---|
30 | /// |
---|
31 | /// Constructor taking the \a data matrix, the KernelFunction and a |
---|
32 | /// \a weight matrix as input. Each column in the data matrix |
---|
33 | /// corresponds to one sample. |
---|
34 | /// |
---|
35 | /// @note if @a data, @a kf, or @a weights is destroyed the |
---|
36 | /// behaviour of the object is undefined |
---|
37 | /// |
---|
38 | KernelWeighted_MEV(const MatrixLookup& data, |
---|
39 | const KernelFunction& kf, |
---|
40 | const MatrixLookup& weights); |
---|
41 | |
---|
42 | /// |
---|
43 | /// @todo remove |
---|
44 | /// |
---|
45 | KernelWeighted_MEV(const KernelWeighted_MEV& other, |
---|
46 | const std::vector<size_t>& index); |
---|
47 | |
---|
48 | /// |
---|
49 | /// @return Element at position (\a row, \a column) of the Kernel |
---|
50 | /// matrix |
---|
51 | /// |
---|
52 | double operator()(const size_t row, const size_t column) const; |
---|
53 | |
---|
54 | /// |
---|
55 | /// Calculates the scalar product using the weighted |
---|
56 | /// KernelFunction between data vector @a vec and column \f$ i \f$ |
---|
57 | /// in data matrix. For @a vec a vector of unity weights is used. |
---|
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,false), |
---|
64 | DataLookup1D(vec.size(),1.0), |
---|
65 | DataLookup1D(*weights_,i,false)); |
---|
66 | } |
---|
67 | |
---|
68 | /// |
---|
69 | /// Calculates the scalar product using the weighted |
---|
70 | /// KernelFunction between data vector @a vec and column \f$ i \f$ |
---|
71 | /// in data matrix. For @a vec a vector of unity weights is used. |
---|
72 | /// |
---|
73 | /// @return kernel element between data @a ve and training sample @a i |
---|
74 | /// |
---|
75 | inline double element(const DataLookup1D& vec, const DataLookup1D& w, |
---|
76 | const size_t i) const |
---|
77 | { |
---|
78 | return (*kf_)(vec, DataLookup1D(*data_,i, false), |
---|
79 | w,DataLookup1D(*weights_,i, false)); |
---|
80 | } |
---|
81 | |
---|
82 | /// |
---|
83 | /// @todo remove |
---|
84 | /// |
---|
85 | const Kernel* selected(const std::vector<size_t>& index) const; |
---|
86 | |
---|
87 | /// |
---|
88 | /// @return true |
---|
89 | /// |
---|
90 | inline bool weighted(void) const { return true; } |
---|
91 | |
---|
92 | private: |
---|
93 | /// |
---|
94 | /// Copy constructor (not implemented) |
---|
95 | /// |
---|
96 | KernelWeighted_MEV(const KernelWeighted_MEV&); |
---|
97 | const KernelWeighted_MEV& operator=(const KernelWeighted_MEV&); |
---|
98 | |
---|
99 | |
---|
100 | }; |
---|
101 | |
---|
102 | }} // of namespace classifier and namespace theplu |
---|
103 | |
---|
104 | #endif |
---|