1 | // $Id$ |
---|
2 | |
---|
3 | #ifndef _theplu_classifier_DataLookup2D_ |
---|
4 | #define _theplu_classifier_DataLookup2D_ |
---|
5 | |
---|
6 | #include <vector> |
---|
7 | #include <iostream> |
---|
8 | |
---|
9 | namespace theplu { |
---|
10 | namespace 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 | /// |
---|
85 | /// |
---|
86 | virtual const DataLookup2D* selected(const std::vector< size_t > &) const=0; |
---|
87 | |
---|
88 | /// |
---|
89 | /// @return sub-Lookup of the DataLookup2D |
---|
90 | /// |
---|
91 | /// @Note Returns a dynamically allocated DataLookup2D, which has |
---|
92 | /// to be deleted by the caller to avoid memory leaks. |
---|
93 | /// |
---|
94 | virtual const DataLookup2D* |
---|
95 | training_data(const std::vector<size_t>&) const=0; |
---|
96 | |
---|
97 | /// |
---|
98 | /// @return sub-Lookup of the DataLookup2D |
---|
99 | /// |
---|
100 | /// @Note Returns a dynamically allocated DataLookup2D, which has |
---|
101 | /// to be deleted by the caller to avoid memory leaks. |
---|
102 | /// |
---|
103 | virtual const DataLookup2D* |
---|
104 | training_data(const std::vector<size_t>& features, |
---|
105 | const std::vector<size_t>& samples) const=0; |
---|
106 | |
---|
107 | /// |
---|
108 | /// @return number of rows |
---|
109 | /// |
---|
110 | inline size_t rows(void) const { return row_index_.size(); } |
---|
111 | |
---|
112 | /// |
---|
113 | /// @return sub-Lookup of the DataLookup2D |
---|
114 | /// |
---|
115 | /// @Note Returns a dynamically allocated DataLookup2D, which has |
---|
116 | /// to be deleted by the caller to avoid memory leaks. |
---|
117 | /// |
---|
118 | virtual const DataLookup2D* |
---|
119 | validation_data(const std::vector<size_t>& train, |
---|
120 | const std::vector<size_t>& val) const=0; |
---|
121 | |
---|
122 | /// |
---|
123 | /// @return sub-Lookup of the DataLookup2D |
---|
124 | /// |
---|
125 | /// @Note Returns a dynamically allocated DataLookup2D, which has |
---|
126 | /// to be deleted by the caller to avoid memory leaks. |
---|
127 | /// |
---|
128 | virtual const DataLookup2D* |
---|
129 | validation_data(const std::vector<size_t>& features, |
---|
130 | const std::vector<size_t>& train, |
---|
131 | const std::vector<size_t>& val) const=0; |
---|
132 | |
---|
133 | /// |
---|
134 | /// Is lookup weighted? |
---|
135 | /// |
---|
136 | virtual bool weighted(void) const=0; |
---|
137 | |
---|
138 | /// |
---|
139 | /// @brief access operator |
---|
140 | /// |
---|
141 | /// @return value in that particular element |
---|
142 | /// |
---|
143 | virtual double operator()(const size_t row, const size_t column) const=0; |
---|
144 | |
---|
145 | protected: |
---|
146 | const DataLookup2D& operator=(const DataLookup2D&); |
---|
147 | |
---|
148 | std::vector<size_t> row_index_; |
---|
149 | std::vector<size_t> column_index_; |
---|
150 | bool owner_; |
---|
151 | }; |
---|
152 | |
---|
153 | }} // of namespace classifier and namespace theplu |
---|
154 | |
---|
155 | #endif |
---|