source: trunk/yat/classifier/DataLookup2D.h @ 1000

Last change on this file since 1000 was 1000, checked in by Jari Häkkinen, 13 years ago

trac moved to new location.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 4.9 KB
Line 
1#ifndef _theplu_yat_classifier_DataLookup2D_
2#define _theplu_yat_classifier_DataLookup2D_
3
4// $Id$
5
6/*
7  Copyright (C) 2005 Markus Ringnér, Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
9  Copyright (C) 2007 Peter Johansson
10
11  This file is part of the yat library, http://trac.thep.lu.se/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 2 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include <vector>
30#include <iostream>
31
32namespace theplu {
33namespace yat {
34namespace classifier { 
35
36  ///
37  /// @brief Interface class for classifier data.
38  ///
39  /// This is the abstract base class defining a common interface for
40  /// MatrixLookup and KernelLookup. The general idea of the Lookup
41  /// classes is to: rather than copying the sub-matrix or sub-kernel,
42  /// to hold a pointer to the underlying matrix/kernel and a vector
43  /// of row indices and a vector of column indices. These indices
44  /// then define what element to look into.
45  ///
46  /// This allow fast construction of sub-matrices/sub-kernels and at
47  /// almost no extra memory usage.
48  ///
49  /// There is a possibility to set DataLookup2D as owner of the
50  /// underlying data. This implies that underlying data is deleted in
51  /// destructor of DataLookup2D (actually in destructor of inherited
52  /// class since underlying data is class specific), but only if
53  /// there is no other owner of the underlying data. A reference
54  /// counter is used to keep track of number of owners.
55  ///
56  class DataLookup2D
57  {
58 
59  public:
60   
61    ///
62    /// Default constructor.
63    ///
64    DataLookup2D(const bool own=false);
65
66
67    ///
68    /// Constructor taking the @a row index vector and @a column index
69    /// vector as input.
70    ///
71    DataLookup2D(const std::vector<size_t>& row, 
72                 const std::vector<size_t>& column,
73                 const bool own=false);
74
75    ///
76    /// @brief Copy constructor. Indices and pointer to underlying
77    /// data is copied, whereas owner is set to false.
78    ///
79    DataLookup2D(const DataLookup2D&);
80
81    ///
82    /// Copy the index such that new(i,j) = old(row[i],col[j])
83    ///
84    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& row, 
85                 const std::vector<size_t>& col);
86
87    ///
88    /// If row is true indices are copied so new(i,j)=old(index[i],j).
89    /// Else indices are copied so new(i,j)=old(i,index[j])
90    ///
91    DataLookup2D(const DataLookup2D&, const std::vector<size_t>& index, 
92                 const bool row);
93
94
95    ///
96    /// Indices are created all pointing to the zero-zero element
97    /// created in daughter classes.
98    ///
99    DataLookup2D(const size_t, const size_t);
100
101
102    ///
103    /// @brief Destructor
104    ///
105    virtual ~DataLookup2D() {};
106
107    ///
108    /// @return number of columns
109    ///
110    size_t columns(void) const;
111
112    ///
113    /// @return number of rows
114    ///
115    size_t rows(void) const;
116
117    ///
118    /// @return Data based on selected features.
119    ///
120    virtual const DataLookup2D* selected(const std::vector< size_t > &) 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    training_data(const std::vector<size_t>&) const=0; 
130
131    ///
132    /// @return sub-Lookup of the DataLookup2D
133    ///
134    /// @Note Returns a dynamically allocated DataLookup2D, which has
135    /// to be deleted by the caller to avoid memory leaks.
136    ///
137    virtual const DataLookup2D* 
138    validation_data(const std::vector<size_t>& train,
139                    const std::vector<size_t>& val) const=0; 
140
141    ///
142    /// Is lookup weighted?
143    ///
144    virtual bool weighted(void) const=0;
145
146    ///
147    /// @brief access operator
148    ///
149    /// @return value in that particular element
150    ///
151    virtual double operator()(const size_t row, const size_t column) const=0;
152
153  protected:
154    ///
155    /// @brief assignment operator
156    ///
157    const DataLookup2D& operator=(const DataLookup2D&); 
158
159    ///
160    /// @brief which rows to look into
161    ///
162    std::vector<size_t> row_index_;
163
164    ///
165    /// @brief which columns to look into
166    ///
167    std::vector<size_t> column_index_;
168
169    ///
170    /// poiter telling how many owners to underlying data. NULL if
171    /// this is not an owner.
172    ///
173    u_int* ref_count_;
174   
175  }; 
176 
177  ///
178  /// The output operator DataLookup2D
179  ///
180  std::ostream& operator<< (std::ostream& s, const DataLookup2D&);
181
182}}} // of namespace classifier, yat, and theplu
183
184#endif
Note: See TracBrowser for help on using the repository browser.