source: trunk/c++_tools/classifier/Kernel.cc @ 628

Last change on this file since 628 was 628, checked in by Peter, 15 years ago

fixes #116 and #90 removed classes KernelWeighted_SEV and KernelWeighted_MEV and they're now absorbed into Kernel_SEV and Kernel_MEV, respectively.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 1.7 KB
Line 
1// $Id$
2
3#include <c++_tools/classifier/Kernel.h>
4
5#include <c++_tools/classifier/DataLookup1D.h>
6#include <c++_tools/classifier/DataLookupWeighted1D.h>
7#include <c++_tools/classifier/KernelFunction.h>
8#include <c++_tools/classifier/MatrixLookup.h>
9
10#include <vector>
11
12namespace theplu {
13namespace classifier {
14
15  Kernel::Kernel(const MatrixLookup& data, const KernelFunction& kf) 
16    : data_(&data), data_w_(0), kf_(&kf), data_owner_(false), 
17      weight_owner_(false)
18  {
19  }
20
21
22  Kernel::Kernel(const MatrixLookupWeighted& data, const KernelFunction& kf) 
23    : data_(&data), data_w_(&data), kf_(&kf), data_owner_(false), 
24      weight_owner_(false)
25  {
26  }
27
28
29  Kernel::Kernel(const Kernel& other, const std::vector<size_t>& index)
30    : kf_(other.kf_), data_owner_(true)
31  {
32    // Peter go through this code; look fishy!
33    data_ = other.data_->selected(index);
34    if (data_w_){
35      data_w_ = other.data_w_->selected(index);
36      weight_owner_=true;
37    }
38    else{
39      data_w_=NULL;
40      weight_owner_=false;
41    }
42
43  }
44
45  Kernel::~Kernel()
46  {
47    if (data_owner_)
48      delete data_;
49     
50    if (weight_owner_)
51      if (data_w_)
52        delete data_w_;
53      else 
54        std::cerr << "Error in Kernel implementation: probably a constructor"
55                  << std::endl;
56   
57  }
58
59 
60  double Kernel::element(const DataLookup1D& vec, const size_t i) const
61  {
62    if (data_w_)
63      return kf_->operator()(vec, DataLookupWeighted1D(*data_w_,i, false)); 
64    else
65      return kf_->operator()(vec, DataLookup1D(*data_,i, false)); 
66  }
67
68
69  double Kernel::element(const DataLookupWeighted1D& vec, const size_t i) const
70  {
71    if (data_w_)
72      return kf_->operator()(vec, DataLookupWeighted1D(*data_w_,i, false)); 
73    else
74      return kf_->operator()(vec, DataLookup1D(*data_,i, false)); 
75  }
76
77}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.