1 | // $Id: KernelLookup.cc 537 2006-03-05 09:30:03Z peter $ |
---|
2 | |
---|
3 | #include <c++_tools/classifier/KernelLookup.h> |
---|
4 | #include <c++_tools/classifier/DataLookup2D.h> |
---|
5 | |
---|
6 | |
---|
7 | #include <cassert> |
---|
8 | #ifndef NDEBUG |
---|
9 | #include <algorithm> |
---|
10 | #endif |
---|
11 | |
---|
12 | namespace theplu { |
---|
13 | namespace classifier { |
---|
14 | |
---|
15 | KernelLookup::KernelLookup(const Kernel& kernel) |
---|
16 | : DataLookup2D(), kernel_(&kernel) |
---|
17 | { |
---|
18 | column_index_.reserve(kernel.size()); |
---|
19 | for(size_t i=0; i<kernel.size(); i++) |
---|
20 | column_index_.push_back(i); |
---|
21 | row_index_=column_index_; |
---|
22 | } |
---|
23 | |
---|
24 | KernelLookup::KernelLookup(const Kernel& kernel, |
---|
25 | const std::vector<size_t>& row, |
---|
26 | const std::vector<size_t>& column) |
---|
27 | : DataLookup2D(row,column), kernel_(&kernel) |
---|
28 | { |
---|
29 | // Checking that each row index is less than kernel.rows() |
---|
30 | assert(row.empty() || |
---|
31 | *(std::max_element(row.begin(),row.end()))<kernel.rows()); |
---|
32 | // Checking that each column index is less than kernel.column() |
---|
33 | assert(column.empty() || |
---|
34 | *(std::max_element(column.begin(),column.end()))<kernel.columns()); |
---|
35 | |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | KernelLookup::KernelLookup(const KernelLookup& kernel, |
---|
40 | const std::vector<size_t>& row, |
---|
41 | const std::vector<size_t>& column) |
---|
42 | : DataLookup2D(kernel,row,column), kernel_(kernel.kernel_) |
---|
43 | { |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | KernelLookup::KernelLookup(const KernelLookup& kernel) |
---|
48 | : DataLookup2D(kernel), kernel_(kernel.kernel_) |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | KernelLookup::~KernelLookup(void) |
---|
54 | { |
---|
55 | if (owner_) |
---|
56 | delete kernel_; |
---|
57 | } |
---|
58 | |
---|
59 | const KernelLookup* |
---|
60 | KernelLookup::training_data(const std::vector<size_t>& train) const |
---|
61 | { |
---|
62 | return new KernelLookup(*this,train,train); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | const KernelLookup* |
---|
67 | KernelLookup::validation_data(const std::vector<size_t>& train, |
---|
68 | const std::vector<size_t>& validation) const |
---|
69 | { |
---|
70 | return new KernelLookup(*this,train,validation); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | }} // of namespace classifier and namespace theplu |
---|