source: trunk/lib/classifier/KernelLookup.cc @ 553

Last change on this file since 553 was 553, checked in by Peter, 17 years ago

added range check in KernelLookup? Constructor and clarified doc in EnsembleBuilder?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: KernelLookup.cc 553 2006-03-07 13:53:57Z 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
12namespace theplu {
13namespace classifier { 
14
15  KernelLookup::KernelLookup(const Kernel& kernel, const bool own)
16    : DataLookup2D(own), 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    // Checking that no index is out of range
51    assert(row_index_.empty() || 
52           *(max_element(row_index_.begin(), row_index_.end()))<kernel_->rows());
53    assert(column_index_.empty() || 
54           *(max_element(column_index_.begin(), column_index_.end()))<
55           kernel_->columns());
56
57  }
58 
59
60  KernelLookup::~KernelLookup(void)
61  {
62    if (owner_)
63      delete kernel_;
64  }
65
66  const KernelLookup* 
67  KernelLookup::training_data(const std::vector<size_t>& train) const
68  { 
69    return new KernelLookup(*this,train,train); 
70  } 
71
72
73  const KernelLookup* 
74  KernelLookup::validation_data(const std::vector<size_t>& train, 
75                                const std::vector<size_t>& validation) const
76  { 
77    return new KernelLookup(*this,train,validation); 
78  } 
79
80
81  const KernelLookup* 
82  KernelLookup::selected(const std::vector<size_t>& index) const
83  {
84    const Kernel* kernel = kernel_->selected(index);
85    return new KernelLookup(*kernel, true);
86  }
87
88}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.