1 | // $Id$ |
---|
2 | |
---|
3 | #include <c++_tools/classifier/Kernel_SEV.h> |
---|
4 | |
---|
5 | #include <c++_tools/classifier/DataLookup1D.h> |
---|
6 | #include <c++_tools/classifier/DataLookupWeighted1D.h> |
---|
7 | #include <c++_tools/classifier/Kernel.h> |
---|
8 | #include <c++_tools/classifier/KernelFunction.h> |
---|
9 | #include <c++_tools/classifier/MatrixLookup.h> |
---|
10 | #include <c++_tools/utility/matrix.h> |
---|
11 | |
---|
12 | namespace theplu { |
---|
13 | namespace classifier { |
---|
14 | |
---|
15 | |
---|
16 | Kernel_SEV::Kernel_SEV(const MatrixLookup& data, const KernelFunction& kf, |
---|
17 | const bool own) |
---|
18 | : Kernel(data,kf, own) |
---|
19 | { |
---|
20 | build_kernel(); |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | Kernel_SEV::Kernel_SEV(const MatrixLookupWeighted& data, |
---|
25 | const KernelFunction& kf, const bool own) |
---|
26 | : Kernel(data,kf, own) |
---|
27 | { |
---|
28 | kernel_matrix_ = utility::matrix(data_->columns(),data_->columns()); |
---|
29 | for (size_t i=0; i<kernel_matrix_.rows(); i++) |
---|
30 | for (size_t j=i; j<kernel_matrix_.columns(); j++) |
---|
31 | kernel_matrix_(i,j) = kernel_matrix_(j,i) = |
---|
32 | (*kf_)(DataLookupWeighted1D(data,i,false), |
---|
33 | DataLookupWeighted1D(data,j,false)); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | Kernel_SEV::Kernel_SEV(const Kernel_SEV& other, |
---|
38 | const std::vector<size_t>& index) |
---|
39 | : Kernel(other, index) |
---|
40 | { |
---|
41 | build_kernel(); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | void Kernel_SEV::build_kernel(void) |
---|
46 | { |
---|
47 | kernel_matrix_ = utility::matrix(data_->columns(),data_->columns()); |
---|
48 | for (size_t i=0; i<kernel_matrix_.rows(); i++) |
---|
49 | for (size_t j=i; j<kernel_matrix_.columns(); j++) |
---|
50 | kernel_matrix_(i,j) = kernel_matrix_(j,i) = |
---|
51 | (*kf_)(DataLookup1D(*data_,i,false),DataLookup1D(*data_,j,false)); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | double Kernel_SEV::operator()(const size_t row,const size_t column) const |
---|
56 | { |
---|
57 | return kernel_matrix_(row,column); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookup& data, |
---|
62 | const bool own) const |
---|
63 | { |
---|
64 | return new Kernel_SEV(data, *kf_, own); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | const Kernel_SEV* Kernel_SEV::make_kernel(const MatrixLookupWeighted& data, |
---|
69 | const bool own) const |
---|
70 | { |
---|
71 | return new Kernel_SEV(data, *kf_, own); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | const Kernel* Kernel_SEV::selected(const std::vector<size_t>& index) const |
---|
76 | { |
---|
77 | return new Kernel_SEV(*this, index); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | }} // of namespace classifier and namespace theplu |
---|