1 | // $Id$ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "Kernel_SEV.h" |
---|
25 | #include "DataLookup1D.h" |
---|
26 | #include "DataLookupWeighted1D.h" |
---|
27 | #include "Kernel.h" |
---|
28 | #include "KernelFunction.h" |
---|
29 | #include "MatrixLookup.h" |
---|
30 | #include "yat/utility/Matrix.h" |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace classifier { |
---|
35 | |
---|
36 | |
---|
37 | Kernel_SEV::Kernel_SEV(const MatrixLookup& data, const KernelFunction& kf, |
---|
38 | const bool own) |
---|
39 | : Kernel(data,kf, own) |
---|
40 | { |
---|
41 | build_kernel(); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | Kernel_SEV::Kernel_SEV(const MatrixLookupWeighted& data, |
---|
46 | const KernelFunction& kf, const bool own) |
---|
47 | : Kernel(data,kf, own) |
---|
48 | { |
---|
49 | kernel_matrix_.resize(data.columns(),data.columns()); |
---|
50 | for (size_t i=0; i<kernel_matrix_.rows(); i++) |
---|
51 | for (size_t j=i; j<kernel_matrix_.columns(); j++) |
---|
52 | kernel_matrix_(i,j) = kernel_matrix_(j,i) = |
---|
53 | (*kf_)(DataLookupWeighted1D(data,i,false), |
---|
54 | DataLookupWeighted1D(data,j,false)); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | Kernel_SEV::Kernel_SEV(const Kernel_SEV& other, |
---|
59 | const std::vector<size_t>& index) |
---|
60 | : Kernel(other, index) |
---|
61 | { |
---|
62 | build_kernel(); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | void Kernel_SEV::build_kernel(void) |
---|
67 | { |
---|
68 | kernel_matrix_.resize(size(),size()); |
---|
69 | for (size_t i=0; i<kernel_matrix_.rows(); i++) |
---|
70 | for (size_t j=i; j<kernel_matrix_.columns(); j++) |
---|
71 | kernel_matrix_(i,j) = kernel_matrix_(j,i) = |
---|
72 | (*kf_)(DataLookup1D(*ml_,i,false), |
---|
73 | DataLookup1D(*ml_,j,false)); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | double Kernel_SEV::operator()(const size_t row,const size_t column) const |
---|
78 | { |
---|
79 | return kernel_matrix_(row,column); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookup& data, |
---|
84 | const bool own) const |
---|
85 | { |
---|
86 | return new Kernel_SEV(data, *kf_, own); |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookupWeighted& data, |
---|
91 | const bool own) const |
---|
92 | { |
---|
93 | return new Kernel_SEV(data, *kf_, own); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | }}} // of namespace classifier, yat, and theplu |
---|