1 | // $Id: KernelWeighted_MEV.h 542 2006-03-05 15:46:47Z peter $ |
---|
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 | //#include <c++_tools/gslapi/matrix.h> |
---|
12 | |
---|
13 | namespace theplu { |
---|
14 | namespace classifier { |
---|
15 | |
---|
16 | /// |
---|
17 | /// @brief Memory 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 Memory Efficient Version (MEV) does not |
---|
21 | /// store the kernel matrix in memory, but calculates each element |
---|
22 | /// when it is needed. When memory allows do always use Kernel_SEV |
---|
23 | /// instead. |
---|
24 | /// |
---|
25 | /// @see also KernelWeighted_SEV |
---|
26 | /// |
---|
27 | class KernelWeighted_MEV : public Kernel |
---|
28 | { |
---|
29 | |
---|
30 | public: |
---|
31 | |
---|
32 | /// |
---|
33 | /// Constructor taking the \a data matrix, the KernelFunction and a |
---|
34 | /// \a weight matrix as input. Each column in the data matrix |
---|
35 | /// corresponds to one sample. |
---|
36 | /// |
---|
37 | /// @note if @a data, @a kf, or @a weights is destroyed the |
---|
38 | /// behaviour of the object is undefined |
---|
39 | /// |
---|
40 | inline KernelWeighted_MEV(const MatrixLookup& data, |
---|
41 | const KernelFunction& kf, |
---|
42 | const MatrixLookup& weights) |
---|
43 | : Kernel(data,kf), weights_(weights) {} |
---|
44 | |
---|
45 | /// |
---|
46 | /// @return Element at position (\a row, \a column) of the Kernel |
---|
47 | /// matrix |
---|
48 | /// |
---|
49 | double operator()(const size_t row, const size_t column) const; |
---|
50 | |
---|
51 | /// |
---|
52 | /// @return kernel element between data @a ve and training sample @a i |
---|
53 | /// |
---|
54 | inline double element(const DataLookup1D& vec, const size_t i) const |
---|
55 | { |
---|
56 | return (*kf_)(vec, DataLookup1D(data_,i), |
---|
57 | DataLookup1D(vec.size(),1.0), |
---|
58 | DataLookup1D(weights_,i)); |
---|
59 | } |
---|
60 | |
---|
61 | inline double element(const DataLookup1D& vec, const DataLookup1D& w, |
---|
62 | const size_t i) const |
---|
63 | { |
---|
64 | return (*kf_)(vec, DataLookup1D(data_,i),w,DataLookup1D(weights_,i)); |
---|
65 | } |
---|
66 | |
---|
67 | private: |
---|
68 | /// |
---|
69 | /// Copy constructor (not implemented) |
---|
70 | /// |
---|
71 | KernelWeighted_MEV(const KernelWeighted_MEV&); |
---|
72 | |
---|
73 | const MatrixLookup& weights_; |
---|
74 | |
---|
75 | }; |
---|
76 | |
---|
77 | }} // of namespace classifier and namespace theplu |
---|
78 | |
---|
79 | #endif |
---|