source: trunk/lib/classifier/MatrixLookup.cc @ 526

Last change on this file since 526 was 526, checked in by Markus Ringnér, 17 years ago

Fixed bug in tScore and in MatrixLookup?. Added support for scoring inputs in SupervisedClassifier? and for using this in training and prediction in NCC.

File size: 2.1 KB
Line 
1// $Id$
2
3#include <c++_tools/classifier/MatrixLookup.h>
4
5namespace theplu {
6namespace 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& data, 
29                     const std::vector<size_t>& row, 
30                     const std::vector<size_t>& col)
31    : DataLookup2D(row,col), data_(data.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& data, 
47                     const std::vector<size_t>& index, bool row)
48    : DataLookup2D(index, row), data_(data.data_)
49  {
50    if(row){
51      row_index_=index;
52      column_index_.reserve((*data_).columns());
53      for(size_t i=0;i<(*data_).columns();i++)
54        column_index_.push_back(i);
55    }
56    else{
57      column_index_=index;
58      row_index_.reserve((*data_).rows());
59      for(size_t i=0;i<(*data_).rows();i++)
60        row_index_.push_back(i);
61    }
62
63  }
64 
65
66
67  MatrixLookup::MatrixLookup(const MatrixLookup& dv)
68    : DataLookup2D(dv), data_(dv.data_)
69  {
70  }
71
72
73
74  const MatrixLookup* 
75  MatrixLookup::training_data(const std::vector<size_t>& i) const
76  { 
77    return new MatrixLookup(*this,i); 
78  }
79
80
81
82  const MatrixLookup* 
83  MatrixLookup::validation_data(const std::vector<size_t>& train,
84                                const std::vector<size_t>& val) const
85  { 
86    return new MatrixLookup(*this,val); 
87  }
88
89
90
91  std::ostream& operator<<(std::ostream& s, const MatrixLookup& m)
92  {
93    s.setf(std::ios::dec);
94    s.precision(12);
95    for(size_t i=0, j=0; i<m.rows(); i++)
96      for (j=0; j<m.columns(); j++) {
97        s << m(i,j);
98        if (j<m.columns()-1)
99          s << "\t";
100        else if (i<m.rows()-1)
101          s << "\n";
102      }
103    return s;
104  }
105
106
107
108}} // of namespace classifier and namespace theplu
Note: See TracBrowser for help on using the repository browser.