1 | #ifndef _theplu_yat_classifier_kernel_sev_ |
---|
2 | #define _theplu_yat_classifier_kernel_sev_ |
---|
3 | |
---|
4 | // $Id$ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
---|
9 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
10 | Copyright (C) 2022 Peter Johansson |
---|
11 | |
---|
12 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
13 | |
---|
14 | The yat library is free software; you can redistribute it and/or |
---|
15 | modify it under the terms of the GNU General Public License as |
---|
16 | published by the Free Software Foundation; either version 3 of the |
---|
17 | License, or (at your option) any later version. |
---|
18 | |
---|
19 | The yat library is distributed in the hope that it will be useful, |
---|
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
22 | General Public License for more details. |
---|
23 | |
---|
24 | You should have received a copy of the GNU General Public License |
---|
25 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "Kernel.h" |
---|
29 | #include "yat/utility/Matrix.h" |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace classifier { |
---|
34 | |
---|
35 | class DataLookup1D; |
---|
36 | class KernelFunction; |
---|
37 | |
---|
38 | /// |
---|
39 | /// @brief Speed Efficient Kernel |
---|
40 | /// |
---|
41 | /// Class taking care of the \f$ NxN \f$ kernel matrix, where |
---|
42 | /// \f$ N \f$ is number of samples. Type of Kernel is defined by a |
---|
43 | /// KernelFunction. This Speed Efficient Version (SEV) calculates |
---|
44 | /// the kernel matrix once by construction and the kernel is stored in |
---|
45 | /// memory. When \f$ N \f$ is large and the kernel matrix cannot be |
---|
46 | /// stored in memory, use Kernel_MEV instead. |
---|
47 | /// |
---|
48 | class Kernel_SEV : public Kernel |
---|
49 | { |
---|
50 | |
---|
51 | public: |
---|
52 | |
---|
53 | /// |
---|
54 | /// Constructor taking the data matrix and KernelFunction as |
---|
55 | /// input. @note Can not handle NaNs. When dealing with missing values, |
---|
56 | /// use KernelWeighted_SEV instead. |
---|
57 | /// |
---|
58 | Kernel_SEV(const MatrixLookup&, const KernelFunction&,const bool own=false); |
---|
59 | |
---|
60 | /// |
---|
61 | /// Constructor taking the data matrix and KernelFunction as |
---|
62 | /// input. @note Can not handle NaNs. When dealing with missing values, |
---|
63 | /// use KernelWeighted_SEV instead. |
---|
64 | /// |
---|
65 | Kernel_SEV(const MatrixLookupWeighted&, const KernelFunction&, |
---|
66 | const bool own=false); |
---|
67 | |
---|
68 | /// |
---|
69 | /// Constructs a Kernel based on selected features defined by @a index |
---|
70 | /// |
---|
71 | Kernel_SEV(const Kernel_SEV& kernel, const std::vector<size_t>& index); |
---|
72 | |
---|
73 | |
---|
74 | /// |
---|
75 | /// An interface for making new classifier objects. This function |
---|
76 | /// allows for specification at run-time of which kernel to |
---|
77 | /// instatiate (see 'Prototype' in Design Patterns). |
---|
78 | /// |
---|
79 | /// @note Returns a dynamically allocated Kernel, which has |
---|
80 | /// to be deleted by the caller to avoid memory leaks. |
---|
81 | /// |
---|
82 | const Kernel_SEV* make_kernel(const MatrixLookup&, |
---|
83 | const bool own=false) const; |
---|
84 | |
---|
85 | |
---|
86 | /// |
---|
87 | /// An interface for making new classifier objects. This function |
---|
88 | /// allows for specification at run-time of which kernel to |
---|
89 | /// instatiate (see 'Prototype' in Design Patterns). |
---|
90 | /// |
---|
91 | /// @note Returns a dynamically allocated Kernel, which has |
---|
92 | /// to be deleted by the caller to avoid memory leaks. |
---|
93 | /// |
---|
94 | const Kernel_SEV* make_kernel(const MatrixLookupWeighted&, |
---|
95 | const bool own=false) const; |
---|
96 | |
---|
97 | |
---|
98 | /// |
---|
99 | /// @return element at position (\a row, \a column) in the Kernel |
---|
100 | /// matrix |
---|
101 | /// |
---|
102 | double operator()(const size_t row,const size_t column) const; |
---|
103 | |
---|
104 | |
---|
105 | private: |
---|
106 | /// |
---|
107 | /// Copy constructor (not implemented) |
---|
108 | /// |
---|
109 | Kernel_SEV(const Kernel_SEV&); |
---|
110 | const Kernel_SEV& operator=(const Kernel_SEV&); |
---|
111 | |
---|
112 | void build_kernel(void); |
---|
113 | |
---|
114 | utility::Matrix kernel_matrix_; |
---|
115 | |
---|
116 | }; // class Kernel_SEV |
---|
117 | |
---|
118 | }}} // of namespace classifier, yat, and theplu |
---|
119 | |
---|
120 | #endif |
---|