1 | // $Id$ |
---|
2 | |
---|
3 | #include <c++_tools/classifier/MatrixLookup.h> |
---|
4 | |
---|
5 | namespace theplu { |
---|
6 | namespace classifier { |
---|
7 | |
---|
8 | MatrixLookup::MatrixLookup(const gslapi::matrix& data) |
---|
9 | : DataLookup2D(), data_(&data) |
---|
10 | { |
---|
11 | for(size_t i=0;i<(*data_).rows();i++) |
---|
12 | row_index_.push_back(i); |
---|
13 | for(size_t i=0;i<(*data_).columns();i++) |
---|
14 | column_index_.push_back(i); |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | MatrixLookup::MatrixLookup(const gslapi::matrix& data, |
---|
20 | const std::vector<size_t>& row, |
---|
21 | const std::vector<size_t>& col) |
---|
22 | : DataLookup2D(row,col), data_(&data) |
---|
23 | { |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | MatrixLookup::MatrixLookup(const MatrixLookup& ml, |
---|
29 | const std::vector<size_t>& row, |
---|
30 | const std::vector<size_t>& col) |
---|
31 | : DataLookup2D(ml,row,col), data_(ml.data_) |
---|
32 | { |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | MatrixLookup::MatrixLookup(const gslapi::matrix& data, |
---|
38 | const std::vector<size_t>& index, |
---|
39 | const bool row) |
---|
40 | : DataLookup2D(index, row), data_(&data) |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | MatrixLookup::MatrixLookup(const MatrixLookup& ml, |
---|
47 | const std::vector<size_t>& index, bool row) |
---|
48 | : DataLookup2D(ml,index,row), data_(ml.data_) |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | MatrixLookup::MatrixLookup(const MatrixLookup& dv) |
---|
55 | : DataLookup2D(dv), data_(dv.data_) |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | const MatrixLookup* |
---|
62 | MatrixLookup::training_data(const std::vector<size_t>& i) const |
---|
63 | { |
---|
64 | return new MatrixLookup(*this,i); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | const MatrixLookup* |
---|
70 | MatrixLookup::validation_data(const std::vector<size_t>& train, |
---|
71 | const std::vector<size_t>& val) const |
---|
72 | { |
---|
73 | return new MatrixLookup(*this,val); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | std::ostream& operator<<(std::ostream& s, const MatrixLookup& m) |
---|
79 | { |
---|
80 | s.setf(std::ios::dec); |
---|
81 | s.precision(12); |
---|
82 | for(size_t i=0, j=0; i<m.rows(); i++) |
---|
83 | for (j=0; j<m.columns(); j++) { |
---|
84 | s << m(i,j); |
---|
85 | if (j<m.columns()-1) |
---|
86 | s << "\t"; |
---|
87 | else if (i<m.rows()-1) |
---|
88 | s << "\n"; |
---|
89 | } |
---|
90 | return s; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | }} // of namespace classifier and namespace theplu |
---|