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

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

added feature selection for SVM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: KernelLookup.cc 545 2006-03-06 13:35:45Z 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  }
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  const MatrixLookup* KernelLookup::weights(void) const
74  { return new MatrixLookup(kernel_->weights(),column_index_); }
75
76  const KernelLookup* 
77  KernelLookup::selected(const std::vector<size_t>& index) const
78  {
79    const Kernel* kernel = kernel_->selected(index);
80    return new KernelLookup(*kernel, true);
81  }
82
83}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.