source: trunk/c++_tools/classifier/DataLookup2D.h @ 604

Last change on this file since 604 was 604, checked in by Peter, 15 years ago

ref #96 Changed InputRanker? to return vector of index rather than element. Also added draft to FeatureSelection? class.

File size: 3.3 KB
Line 
1// $Id$
2
3#ifndef _theplu_classifier_DataLookup2D_
4#define _theplu_classifier_DataLookup2D_
5
6#include <vector>
7#include <iostream>
8
9namespace theplu {
10namespace classifier { 
11
12  ///
13  /// @brief Interface class for classifier data.
14  ///
15  /// This is the abstract base class defining a common interface for
16  /// MatrixLookup and KernelLookup. The general idea o the Lookup
17  /// classes is to: rather than copying the sub-matrix or sub-kernel,
18  /// to hold a pointer to the underlying matrix/kernel and a vector
19  /// of row indices and a vector of column indices. These indices
20  /// then define what element to look into.
21  ///
22  /// This allow fast construction of sub-matrices/sub-kernels and at
23  /// almost no extra memory usage.
24  ///
25  class DataLookup2D
26  {
27 
28  public:
29   
30    ///
31    /// Default constructor.
32    ///
33    inline DataLookup2D(const bool owner=false) : owner_(owner){};
34
35
36    ///
37    /// Constructor taking the @a row index vector and @a column index
38    /// vector as input. If @a owner is set true, the object is
39    /// consider as owner of the underlying data (and the data is
40    /// deleted at destruction).
41    ///
42    DataLookup2D(const std::vector<size_t>& row, 
43                 const std::vector<size_t>& column, 
44                 const bool owner = false);
45
46    ///
47    /// @brief Copy constructor. Indices and pointer to underlying
48    /// data is copied, whereas owner is set to false.
49    ///
50    DataLookup2D(const DataLookup2D&);
51
52    ///
53    /// Copy the index such that new(i,j) = old(row[i],col[j])
54    ///
55    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& row, 
56                 const std::vector<size_t>& col);
57
58    ///
59    /// If row is true indices are copied so new(i,j)=old(index[i],j).
60    /// Else indices are copied so new(i,j)=old(i,index[j])
61    ///
62    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& index, 
63                 const bool row);
64
65
66    ///
67    /// Indices are created all pointing to the zero-zero element
68    /// created in daughter classes.
69    ///
70    DataLookup2D(const size_t, const size_t, const bool owner);
71
72
73    ///
74    /// @brief Destructor
75    ///
76    virtual ~DataLookup2D() {};
77
78    ///
79    /// @return number of columns
80    ///
81    inline size_t columns(void) const { return column_index_.size(); } 
82
83    ///
84    /// @return sub-Lookup of the DataLookup2D
85    ///
86    /// @Note Returns a dynamically allocated DataLookup2D, which has
87    /// to be deleted by the caller to avoid memory leaks.
88    ///
89    virtual const DataLookup2D* 
90    training_data(const std::vector<size_t>&) const=0; 
91
92    ///
93    /// @return number of rows
94    ///
95    inline size_t rows(void) const { return row_index_.size(); } 
96
97    ///
98    /// @todo doc
99    ///
100    virtual const DataLookup2D* selected(const std::vector< size_t > &) const=0;
101
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    virtual const DataLookup2D* 
109    validation_data(const std::vector<size_t>& train,
110                    const std::vector<size_t>& val) const=0; 
111
112    ///
113    /// @brief access operator
114    ///
115    /// @return value in that particular element
116    ///
117    virtual double operator()(const size_t row, const size_t column) const=0;
118
119  protected:
120    const DataLookup2D& operator=(const DataLookup2D&); 
121
122    std::vector<size_t> row_index_;
123    std::vector<size_t> column_index_;
124    bool owner_;
125  }; 
126 
127}} // of namespace classifier and namespace theplu
128
129#endif
Note: See TracBrowser for help on using the repository browser.