source: trunk/lib/classifier/Kernel.h @ 542

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

added predict function in SVM supporting weight

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: Kernel.h 542 2006-03-05 15:46:47Z peter $
2
3#ifndef _theplu_classifier_kernel_
4#define _theplu_classifier_kernel_
5
6#include <c++_tools/gslapi/matrix.h>
7#include <c++_tools/gslapi/vector.h>
8#include <c++_tools/classifier/KernelFunction.h>
9#include <c++_tools/classifier/MatrixLookup.h>
10
11#include <cctype>
12
13namespace theplu {
14namespace classifier {
15
16  ///
17  ///   @brief Base Class for Kernels.
18  ///
19  ///   Class taking care of the \f$NxN\f$ kernel matrix, where
20  ///   \f$N\f$ is number of samples. Each element in the Kernel
21  ///   matrix is the scalar product of the corresponding pair of
22  ///   samples. Type of Kernel is defined by a KernelFunction.
23  ///   
24  ///   @note If the KernelFunction is destroyed, the Kernel is no
25  ///   longer defined.
26  ///
27  class Kernel
28  {
29   
30  public:
31
32    ///
33    ///   Constructor taking the data matrix and KernelFunction as
34    ///   input.Each column in the data matrix corresponds to one
35    ///   sample.
36    ///
37    ///   @note Can not handle NaNs.
38    ///
39    Kernel(const MatrixLookup& data, const KernelFunction& kf) 
40      : data_(data), kf_(&kf) {};
41   
42    ///
43    ///   Destructor
44    ///
45    virtual ~Kernel(void) {};
46
47    ///
48    /// @return element at position (\a row, \a column) of the Kernel
49    /// matrix
50    ///
51    virtual double operator()(const size_t row, const size_t column) const=0;
52
53    ///
54    /// @return number columns in Kernel
55    ///
56    inline size_t columns(void) const { return size(); } 
57
58    ///
59    /// @return number of rows in Kernel
60    ///
61    inline size_t rows(void) const { return size(); } 
62
63    ///
64    /// @brief number of samples
65    ///
66    inline size_t size(void) const { return data_.columns(); } 
67
68   
69    virtual double element(const DataLookup1D& vec, const size_t i) const=0;
70    virtual double element(const DataLookup1D& vec, const DataLookup1D& w,
71                           const size_t i) const=0;
72
73  protected:
74    // Peter should be a copy
75    const MatrixLookup& data_;
76    const KernelFunction* kf_;
77
78  private:
79    ///
80    /// Copy constructor (not implemented)
81    ///
82    Kernel(const Kernel&);
83
84
85  }; // class Kernel
86
87}} // of namespace classifier and namespace theplu
88
89#endif
Note: See TracBrowser for help on using the repository browser.