source: trunk/lib/classifier/KernelLookup.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: 3.3 KB
Line 
1// $Id: KernelLookup.h 542 2006-03-05 15:46:47Z peter $
2
3#ifndef _theplu_classifier_kernel_lookup_
4#define _theplu_classifier_kernel_lookup_
5
6#include <c++_tools/classifier/Kernel.h>
7#include <c++_tools/classifier/DataLookup2D.h>
8#include <vector>
9
10namespace theplu {
11namespace classifier {
12
13  class KernelFunction;
14
15  ///
16  /// @brief View into sub Kernel
17  ///
18  class KernelLookup : public DataLookup2D
19  {
20
21  public:
22   
23    ///
24    /// Constructor
25    ///
26    /// @note If underlying Kernel goes out of scope or is deleted, the
27    /// returned pointer becomes invalid and the result of further use is
28    /// undefined.
29    ///
30    KernelLookup(const Kernel& kernel);
31
32    ///
33    /// Constructor creating a subKernel. The
34    /// \f$i\f$th row in constructed lookup is identical to row number
35    /// row[i] in matrix. The \f$i\f$th column in constructed lookup
36    /// is identical to column number column[i] in matrix.
37    ///
38    /// @note If @a kernel goes out of scope or is deleted, the
39    /// returned pointer becomes invalid and the result of further use is
40    /// undefined.
41    ///
42    /// @note For training usage row index shall always be equal to
43    /// column index.
44    ///
45    KernelLookup(const Kernel& kernel, const std::vector<size_t>& row, 
46                 const std::vector<size_t>& column);
47   
48    ///
49    /// Copy constructor
50    ///
51    KernelLookup(const KernelLookup&);
52
53
54    ///
55    /// Contructor building a sub-KernelLookup from a KernelLookup
56    /// defined by row index vector and column index vector. The
57    /// resulting KernelLookup is independent of the old KernelLookup,
58    /// but is undefined in case underlying Kernel is destroyed.
59    ///
60    /// @note For training usage row index shall always be equal to
61    /// column index.
62    ///
63    KernelLookup(const KernelLookup& kernel, const std::vector<size_t>& row, 
64                 const std::vector<size_t>& column);
65   
66    ///
67    /// @brief Destructor
68    ///
69    /// Deletes underlying Kernel if KernelLookup owns it.
70    ///
71    virtual ~KernelLookup(void);
72
73
74    ///
75    /// @return sub-Lookup of the DataLookup2D
76    ///
77    /// @Note Returns a dynamically allocated DataLookup2D, which has
78    /// to be deleted by the caller to avoid memory leaks.
79    ///
80    const KernelLookup* training_data(const std::vector<size_t>& train) const;
81
82
83    ///
84    /// In returned kernel each row corresponds to a training sample
85    /// and each column corresponds to a validation sample.
86    ///
87    /// @return sub-Lookup of the DataLookup2D
88    ///
89    /// @Note Returns a dynamically allocated DataLookup2D, which has
90    /// to be deleted by the caller to avoid memory leaks.
91    ///
92    const KernelLookup* 
93    validation_data(const std::vector<size_t>& train, 
94                    const std::vector<size_t>& validation) const;
95
96
97    ///
98    /// @return element at position (\a row, \a column) in the Kernel
99    /// matrix
100    ///
101    inline double operator()(const size_t row,const size_t column) const
102    { return (*kernel_)(row_index_[row],column_index_[column]); }
103
104    inline double element(const DataLookup1D& vec, const size_t i) const
105    { return kernel_->element(vec, row_index_[i]); }
106
107    inline double element(const DataLookup1D& vec, const DataLookup1D& w, 
108                          const size_t i) const
109    { return kernel_->element(vec, w, row_index_[i]); }
110
111  private:
112    ///
113    /// Default constructor. Not implemented.
114    ///
115    KernelLookup(void);
116
117    const Kernel* kernel_;
118
119  }; // class KernelLookup
120
121}} // of namespace classifier and namespace theplu
122
123#endif
Note: See TracBrowser for help on using the repository browser.