1 | // $Id$ |
---|
2 | |
---|
3 | #ifndef _theplu_classifier_matrix_lookup_ |
---|
4 | #define _theplu_classifier_matrix_lookup_ |
---|
5 | |
---|
6 | #include <c++_tools/classifier/DataLookup2D.h> |
---|
7 | #include <c++_tools/gslapi/matrix.h> |
---|
8 | |
---|
9 | #include <cassert> |
---|
10 | |
---|
11 | namespace theplu { |
---|
12 | namespace classifier { |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | /// |
---|
17 | /// Interface class for classifier data |
---|
18 | /// |
---|
19 | /// @todo document, especially describe when object becomes invalid, |
---|
20 | /// as now documentation is conservative. |
---|
21 | class MatrixLookup : public DataLookup2D |
---|
22 | { |
---|
23 | |
---|
24 | public: |
---|
25 | |
---|
26 | |
---|
27 | /// |
---|
28 | /// Constructor creating a lookup into the whole matrix. |
---|
29 | /// |
---|
30 | /// @note If @a matrix goes out of scope or is deleted, the |
---|
31 | /// MatrixLookup becomes invalid and the result of further use is |
---|
32 | /// undefined. |
---|
33 | /// |
---|
34 | explicit MatrixLookup(const gslapi::matrix& matrix); |
---|
35 | |
---|
36 | /// |
---|
37 | /// Constructor creating a lookup into parts of matrix. 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 matrix goes out of scope or is deleted, the |
---|
43 | /// MatrixLookup becomes invalid and the result of further use is |
---|
44 | /// undefined. |
---|
45 | /// |
---|
46 | MatrixLookup(const gslapi::matrix& matrix, const std::vector<size_t>& row, |
---|
47 | const std::vector<size_t>& column); |
---|
48 | |
---|
49 | /// |
---|
50 | /// Constructor taking rows or columns |
---|
51 | /// |
---|
52 | /// @parameter row_vectors if true (default) the new MatrixLookup |
---|
53 | /// will look into a sub-matrix defined by all columns and rows |
---|
54 | /// defined by @a index. If not true the new MatrixLookup will |
---|
55 | /// look into a sub-matrix defined by all rows and columns defined |
---|
56 | /// by @a index. |
---|
57 | /// |
---|
58 | /// @note If @a matrix goes out of scope or is deleted, the |
---|
59 | /// MatrixLookup becomes invalid and the result of further use is |
---|
60 | /// undefined. |
---|
61 | /// |
---|
62 | MatrixLookup(const gslapi::matrix& matrix, |
---|
63 | const std::vector<size_t>& index, |
---|
64 | const bool row_vectors); |
---|
65 | |
---|
66 | /// |
---|
67 | /// @brief Copy constructor. |
---|
68 | /// |
---|
69 | /// @note If underlying matrix goes out of scope or is deleted, the |
---|
70 | /// MatrixLookup becomes invalid and the result of further use is |
---|
71 | /// undefined. |
---|
72 | /// |
---|
73 | MatrixLookup(const MatrixLookup&); |
---|
74 | |
---|
75 | /// |
---|
76 | /// Constructor taking the row index vector and column index vector |
---|
77 | /// as input. |
---|
78 | /// |
---|
79 | /// @note If underlying matrix goes out of scope or is deleted, the |
---|
80 | /// MatrixLookup becomes invalid and the result of further use is |
---|
81 | /// undefined. |
---|
82 | /// |
---|
83 | MatrixLookup(const MatrixLookup& matrix, const std::vector<size_t>&, |
---|
84 | const std::vector<size_t>&); |
---|
85 | |
---|
86 | /// |
---|
87 | /// Constructor taking the column or row index vector (default) as |
---|
88 | /// input. If @a row is false the created MatrixLookup will have |
---|
89 | /// equally many rows as @a matrix. |
---|
90 | /// |
---|
91 | /// @note If underlying matrix goes out of scope or is deleted, the |
---|
92 | /// MatrixLookup becomes invalid and the result of further use is |
---|
93 | /// undefined. |
---|
94 | /// |
---|
95 | MatrixLookup(const MatrixLookup& matrix, const std::vector<size_t>&, |
---|
96 | const bool row_vectors); |
---|
97 | |
---|
98 | /// |
---|
99 | /// Constructor creating a MatrixLookup with @a rows rows, @a |
---|
100 | /// columns columns, and all values are set to @a value. Created |
---|
101 | /// object owns its underlying matrix. |
---|
102 | /// |
---|
103 | MatrixLookup(const size_t rows, const size_t columns, const double value=0); |
---|
104 | |
---|
105 | /// |
---|
106 | /// Destructor |
---|
107 | /// |
---|
108 | virtual ~MatrixLookup(); |
---|
109 | |
---|
110 | |
---|
111 | /// |
---|
112 | /// @return pointer to sub-Lookup of the MatrixLookup |
---|
113 | /// |
---|
114 | /// @note If underlying matrix goes out of scope or is deleted, the |
---|
115 | /// returned pointer becomes invalid and the result of further use is |
---|
116 | /// undefined. |
---|
117 | /// |
---|
118 | const MatrixLookup* training_data(const std::vector<size_t>& i) const; |
---|
119 | |
---|
120 | /// |
---|
121 | /// @return pointer to sub-Lookup of the MatrixLookup |
---|
122 | /// |
---|
123 | /// @note If underlying matrix goes out of scope or is deleted, the |
---|
124 | /// returned pointer becomes invalid and the result of further use is |
---|
125 | /// undefined. |
---|
126 | /// |
---|
127 | const MatrixLookup* validation_data(const std::vector<size_t>&, |
---|
128 | const std::vector<size_t>&) const; |
---|
129 | /// |
---|
130 | /// Access operator |
---|
131 | /// |
---|
132 | /// @return element |
---|
133 | /// |
---|
134 | inline double operator()(const size_t row, const size_t column) const |
---|
135 | { |
---|
136 | assert(row<rows()); |
---|
137 | assert(columns()); |
---|
138 | return (*data_)(row_index_[row], column_index_[column]); |
---|
139 | } |
---|
140 | |
---|
141 | /// |
---|
142 | /// @brief assigment operator |
---|
143 | /// |
---|
144 | const MatrixLookup& operator=(const MatrixLookup&); |
---|
145 | |
---|
146 | private: |
---|
147 | const gslapi::matrix* data_; |
---|
148 | }; |
---|
149 | |
---|
150 | /// |
---|
151 | /// The output operator MatrixLookup |
---|
152 | /// |
---|
153 | std::ostream& operator<< (std::ostream& s, const MatrixLookup&); |
---|
154 | |
---|
155 | }} // of namespace classifier and namespace theplu |
---|
156 | |
---|
157 | #endif |
---|