1 | // $Id: KernelWeighted_SEV.h 542 2006-03-05 15:46:47Z 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 | |
---|
13 | namespace theplu { |
---|
14 | namespace 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 | /// |
---|
47 | /// @return element at position (\a row, \a column) in the Kernel |
---|
48 | /// matrix |
---|
49 | /// |
---|
50 | inline double operator()(const size_t row,const size_t column) const |
---|
51 | { return kernel_matrix_(row,column); } |
---|
52 | |
---|
53 | /// |
---|
54 | /// @return kernel element between data @a ve and training sample @a i |
---|
55 | /// |
---|
56 | inline double element(const DataLookup1D& vec, const size_t i) const |
---|
57 | { |
---|
58 | return (*kf_)(vec, DataLookup1D(data_,i), |
---|
59 | DataLookup1D(vec.size(),1.0), |
---|
60 | DataLookup1D(weights_,i)); |
---|
61 | } |
---|
62 | |
---|
63 | inline double element(const DataLookup1D& vec, const DataLookup1D& w, |
---|
64 | const size_t i) const |
---|
65 | { |
---|
66 | return (*kf_)(vec, DataLookup1D(data_,i),w,DataLookup1D(weights_,i)); |
---|
67 | } |
---|
68 | |
---|
69 | private: |
---|
70 | /// Copy constructor (not implemented) |
---|
71 | KernelWeighted_SEV(const KernelWeighted_SEV&); |
---|
72 | |
---|
73 | gslapi::matrix kernel_matrix_; |
---|
74 | const MatrixLookup& weights_; |
---|
75 | |
---|
76 | }; // class Kernel_SEV |
---|
77 | |
---|
78 | }} // of namespace classifier and namespace theplu |
---|
79 | |
---|
80 | #endif |
---|