source: trunk/lib/classifier/KernelLookup.h @ 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: 4.4 KB
Line 
1// $Id: KernelLookup.h 545 2006-03-06 13:35:45Z 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    /// @brief Constructor from a Kernel
25    ///
26    /// @parameter own if true @a kernel is deleted in destructor,
27    /// i.e., it must be dynamically allocated.
28    ///
29    /// @note If underlying Kernel goes out of scope or is deleted, the
30    /// returned pointer becomes invalid and the result of further use is
31    /// undefined.
32    ///
33    KernelLookup(const Kernel& kernel, const bool own=false);
34
35    ///
36    /// Constructor creating a subKernel. The
37    /// \f$i\f$th row in constructed lookup is identical to row number
38    /// row[i] in matrix. The \f$i\f$th column in constructed lookup
39    /// is identical to column number column[i] in matrix.
40    ///
41    /// @note If @a kernel goes out of scope or is deleted, the
42    /// returned pointer becomes invalid and the result of further use is
43    /// undefined.
44    ///
45    /// @note For training usage row index shall always be equal to
46    /// column index.
47    ///
48    KernelLookup(const Kernel& kernel, const std::vector<size_t>& row, 
49                 const std::vector<size_t>& column);
50   
51    ///
52    /// Copy constructor
53    ///
54    KernelLookup(const KernelLookup&);
55
56
57    ///
58    /// Contructor building a sub-KernelLookup from a KernelLookup
59    /// defined by row index vector and column index vector. The
60    /// resulting KernelLookup is independent of the old KernelLookup,
61    /// but is undefined in case underlying Kernel is destroyed.
62    ///
63    /// @note For training usage row index shall always be equal to
64    /// column index.
65    ///
66    KernelLookup(const KernelLookup& kernel, const std::vector<size_t>& row, 
67                 const std::vector<size_t>& column);
68   
69    ///
70    /// @brief Destructor
71    ///
72    /// Deletes underlying Kernel if KernelLookup owns it.
73    ///
74    virtual ~KernelLookup(void);
75
76
77    ///
78    /// @return sub-Lookup of the DataLookup2D
79    ///
80    /// @Note Returns a dynamically allocated DataLookup2D, which has
81    /// to be deleted by the caller to avoid memory leaks.
82    ///
83    const KernelLookup* training_data(const std::vector<size_t>& train) const;
84
85
86    ///
87    /// In returned kernel each row corresponds to a training sample
88    /// and each column corresponds to a validation sample.
89    ///
90    /// @return sub-Lookup of the DataLookup2D
91    ///
92    /// @Note Returns a dynamically allocated DataLookup2D, which has
93    /// to be deleted by the caller to avoid memory leaks.
94    ///
95    const KernelLookup* 
96    validation_data(const std::vector<size_t>& train, 
97                    const std::vector<size_t>& validation) const;
98
99
100    ///
101    /// @return element at position (\a row, \a column) in the Kernel
102    /// matrix
103    ///
104    inline double operator()(const size_t row,const size_t column) const
105    { return (*kernel_)(row_index_[row],column_index_[column]); }
106
107    ///
108    /// Each column in returned MatrixLook corresponds to the column
109    /// in KernelLookup.
110    ///
111    /// @Note Returns a dynamically allocated MatrixLookup2D, which has
112    /// to be deleted by the caller to avoid memory leaks.
113    ///
114    inline const MatrixLookup* data(void) const
115    { return new MatrixLookup(kernel_->data(),column_index_); }
116
117
118    ///
119    /// @todo doc
120    ///
121    inline double element(const DataLookup1D& vec, const size_t i) const
122    { return kernel_->element(vec, row_index_[i]); }
123
124    ///
125    /// @todo doc
126    ///
127    inline double element(const DataLookup1D& vec, const DataLookup1D& w, 
128                          const size_t i) const
129    { return kernel_->element(vec, w, row_index_[i]); }
130
131    ///
132    /// @todo doc
133    ///
134    /// @Note Returns a dynamically allocated KernelLookup, which has
135    /// to be deleted by the caller to avoid memory leaks.
136    ///
137    const KernelLookup* selected(const std::vector<size_t>&) const;
138   
139    ///
140    /// @return true if underlying Kernel is weighted
141    ///
142    inline bool weighted(void) const { return kernel_->weighted(); }
143
144    ///
145    /// @todo doc
146    ///
147    /// @Note Returns a dynamically allocated KernelLookup, which has
148    /// to be deleted by the caller to avoid memory leaks.
149    ///
150    const MatrixLookup* weights(void) const;
151
152
153  private:
154    ///
155    /// Default constructor. Not implemented.
156    ///
157    KernelLookup(void);
158
159    const Kernel* kernel_;
160
161  }; // class KernelLookup
162
163}} // of namespace classifier and namespace theplu
164
165#endif
Note: See TracBrowser for help on using the repository browser.