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

Last change on this file since 658 was 658, checked in by Peter, 16 years ago

added function in KernelLookup? to create a KernelLookup? from inner data and outer (passed) data.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.5 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    DataLookup2D(const bool own=false);
34
35
36    ///
37    /// Constructor taking the @a row index vector and @a column index
38    /// vector as input.
39    ///
40    DataLookup2D(const std::vector<size_t>& row, 
41                 const std::vector<size_t>& column);
42
43    ///
44    /// @brief Copy constructor. Indices and pointer to underlying
45    /// data is copied, whereas owner is set to false.
46    ///
47    DataLookup2D(const DataLookup2D&);
48
49    ///
50    /// Copy the index such that new(i,j) = old(row[i],col[j])
51    ///
52    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& row, 
53                 const std::vector<size_t>& col);
54
55    ///
56    /// If row is true indices are copied so new(i,j)=old(index[i],j).
57    /// Else indices are copied so new(i,j)=old(i,index[j])
58    ///
59    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& index, 
60                 const bool row);
61
62
63    ///
64    /// Indices are created all pointing to the zero-zero element
65    /// created in daughter classes.
66    ///
67    DataLookup2D(const size_t, const size_t);
68
69
70    ///
71    /// @brief Destructor
72    ///
73    virtual ~DataLookup2D() {};
74
75    ///
76    /// @return number of columns
77    ///
78    inline size_t columns(void) const { return column_index_.size(); } 
79
80    ///
81    /// @return number of rows
82    ///
83    inline size_t rows(void) const { return row_index_.size(); } 
84
85    ///
86    /// @return Data based on selected features.
87    ///
88    virtual const DataLookup2D* selected(const std::vector< size_t > &) const=0;
89
90    ///
91    /// @return sub-Lookup of the DataLookup2D
92    ///
93    /// @Note Returns a dynamically allocated DataLookup2D, which has
94    /// to be deleted by the caller to avoid memory leaks.
95    ///
96    virtual const DataLookup2D* 
97    training_data(const std::vector<size_t>&) const=0; 
98
99    ///
100    /// @return sub-Lookup of the DataLookup2D
101    ///
102    /// @Note Returns a dynamically allocated DataLookup2D, which has
103    /// to be deleted by the caller to avoid memory leaks.
104    ///
105    virtual const DataLookup2D* 
106    validation_data(const std::vector<size_t>& train,
107                    const std::vector<size_t>& val) const=0; 
108
109    ///
110    /// Is lookup weighted?
111    ///
112    virtual bool weighted(void) const=0;
113
114    ///
115    /// @brief access operator
116    ///
117    /// @return value in that particular element
118    ///
119    virtual double operator()(const size_t row, const size_t column) const=0;
120
121  protected:
122    ///
123    /// @brief assignment operator
124    ///
125    const DataLookup2D& operator=(const DataLookup2D&); 
126
127    ///
128    /// @brief which rows to look into
129    ///
130    std::vector<size_t> row_index_;
131
132    ///
133    /// @brief which columns to look into
134    ///
135    std::vector<size_t> column_index_;
136
137    ///
138    /// poiter telling how many owners to underlying data. NULL if
139    /// this is not an owner.
140    ///
141    u_int* ref_count_;
142   
143  }; 
144 
145}} // of namespace classifier and namespace theplu
146
147#endif
Note: See TracBrowser for help on using the repository browser.