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

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

inserted private operator=

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1// $Id: KernelLookup.h 555 2006-03-08 08:48:29Z 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    /// @brief Destructor
72    ///
73    /// Deletes underlying Kernel if KernelLookup owns it.
74    ///
75    virtual ~KernelLookup(void);
76
77
78    ///
79    /// @return sub-Lookup of the DataLookup2D
80    ///
81    /// @Note Returns a dynamically allocated DataLookup2D, which has
82    /// to be deleted by the caller to avoid memory leaks.
83    ///
84    const KernelLookup* training_data(const std::vector<size_t>& train) const;
85
86
87    ///
88    /// In returned kernel each row corresponds to a training sample
89    /// and each column corresponds to a validation sample.
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* 
97    validation_data(const std::vector<size_t>& train, 
98                    const std::vector<size_t>& validation) const;
99
100
101    ///
102    /// @return element at position (\a row, \a column) in the Kernel
103    /// matrix
104    ///
105    inline double operator()(const size_t row,const size_t column) const
106    { return (*kernel_)(row_index_[row],column_index_[column]); }
107
108    ///
109    /// Each column in returned MatrixLook corresponds to the column
110    /// in KernelLookup.
111    ///
112    /// @Note Returns a dynamically allocated MatrixLookup2D, which has
113    /// to be deleted by the caller to avoid memory leaks.
114    ///
115    inline const MatrixLookup* data(void) const
116    { return new MatrixLookup(kernel_->data(),column_index_); }
117
118
119    ///
120    /// @todo doc
121    ///
122    inline double element(const DataLookup1D& vec, const size_t i) const
123    { return kernel_->element(vec, row_index_[i]); }
124
125    ///
126    /// @todo doc
127    ///
128    inline double element(const DataLookup1D& vec, const DataLookup1D& w, 
129                          const size_t i) const
130    { return kernel_->element(vec, w, row_index_[i]); }
131
132    ///
133    /// @todo doc
134    ///
135    /// @Note Returns a dynamically allocated KernelLookup, which has
136    /// to be deleted by the caller to avoid memory leaks.
137    ///
138    const KernelLookup* selected(const std::vector<size_t>&) const;
139   
140    ///
141    /// @return true if underlying Kernel is weighted
142    ///
143    inline bool weighted(void) const { return kernel_->weighted(); }
144
145    ///
146    /// @todo doc
147    ///
148    /// @Note Returns a dynamically allocated KernelLookup, which has
149    /// to be deleted by the caller to avoid memory leaks.
150    ///
151    inline const MatrixLookup* weights(void) const
152    { return new MatrixLookup(kernel_->weights(),column_index_); }
153
154  private:
155    const KernelLookup& operator=(const KernelLookup&);
156
157    const Kernel* kernel_;
158   
159  }; // class KernelLookup
160
161}} // of namespace classifier and namespace theplu
162
163#endif
Note: See TracBrowser for help on using the repository browser.