source: trunk/lib/classifier/KernelLookup.h @ 559

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

some changes in EB

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