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

Last change on this file since 1134 was 1134, checked in by Peter, 14 years ago

using Index class instead of std::vector<size_t>

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 5.0 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 "yat/utility/Index.h"
30
31#include <vector>
32#include <iostream>
33
34namespace theplu {
35namespace yat {
36namespace classifier { 
37
38  ///
39  /// @brief Interface class for classifier data.
40  ///
41  /// This is the abstract base class defining a common interface for
42  /// MatrixLookup and KernelLookup. The general idea of the Lookup
43  /// classes is to: rather than copying the sub-matrix or sub-kernel,
44  /// to hold a pointer to the underlying matrix/kernel and a vector
45  /// of row indices and a vector of column indices. These indices
46  /// then define what element to look into.
47  ///
48  /// This allow fast construction of sub-matrices/sub-kernels and at
49  /// almost no extra memory usage.
50  ///
51  /// There is a possibility to set DataLookup2D as owner of the
52  /// underlying data. This implies that underlying data is deleted in
53  /// destructor of DataLookup2D (actually in destructor of inherited
54  /// class since underlying data is class specific), but only if
55  /// there is no other owner of the underlying data. A reference
56  /// counter is used to keep track of number of owners.
57  ///
58  class DataLookup2D
59  {
60 
61  public:
62   
63    ///
64    /// Default constructor.
65    ///
66    DataLookup2D(const bool own=false);
67
68
69    ///
70    /// Constructor taking the @a row index vector and @a column index
71    /// vector as input.
72    ///
73    DataLookup2D(const utility::Index& row, 
74                 const utility::Index& column,
75                 const bool own=false);
76
77    ///
78    /// @brief Copy constructor. Indices and pointer to underlying
79    /// data is copied, whereas owner is set to false.
80    ///
81    DataLookup2D(const DataLookup2D&);
82
83    ///
84    /// Copy the index such that new(i,j) = old(row[i],col[j])
85    ///
86    DataLookup2D(const DataLookup2D&, const utility::Index& row, 
87                 const utility::Index& col);
88
89    ///
90    /// If row is true indices are copied so new(i,j)=old(index[i],j).
91    /// Else indices are copied so new(i,j)=old(i,index[j])
92    ///
93    DataLookup2D(const DataLookup2D&, const utility::Index& index, 
94                 const bool row);
95
96
97    ///
98    /// Indices are created all pointing to the zero-zero element
99    /// created in daughter classes.
100    ///
101    DataLookup2D(const size_t, const size_t);
102
103
104    ///
105    /// @brief Destructor
106    ///
107    virtual ~DataLookup2D() {};
108
109    ///
110    /// @return number of columns
111    ///
112    size_t columns(void) const;
113
114   
115    /**
116       \return data
117    */
118    virtual double data(size_t i, size_t j) const;
119   
120    ///
121    /// @return number of rows
122    ///
123    size_t rows(void) const;
124
125    ///
126    /// @return Data based on selected features.
127    ///
128    virtual const DataLookup2D* selected(const utility::Index&) const=0;
129
130    ///
131    /// @return sub-Lookup of the DataLookup2D
132    ///
133    /// @note Returns a dynamically allocated DataLookup2D, which has
134    /// to be deleted by the caller to avoid memory leaks.
135    ///
136    virtual const DataLookup2D* 
137    training_data(const utility::Index&) const=0; 
138
139    ///
140    /// @return sub-Lookup of the DataLookup2D
141    ///
142    /// @note Returns a dynamically allocated DataLookup2D, which has
143    /// to be deleted by the caller to avoid memory leaks.
144    ///
145    virtual const DataLookup2D* 
146    validation_data(const utility::Index& train,
147                    const utility::Index& val) const=0; 
148
149    /**
150       \return data
151    */
152    virtual double weight(size_t i, size_t j) const;
153   
154    ///
155    /// Is lookup weighted?
156    ///
157    virtual bool weighted(void) const=0;
158
159    ///
160    /// @brief access operator
161    ///
162    /// @return value in that particular element
163    ///
164    virtual double operator()(const size_t row, const size_t column) const=0;
165
166  protected:
167    ///
168    /// @brief assignment operator
169    ///
170    const DataLookup2D& operator=(const DataLookup2D&); 
171
172    ///
173    /// @brief which rows to look into
174    ///
175    utility::Index row_index_;
176
177    ///
178    /// @brief which columns to look into
179    ///
180    utility::Index column_index_;
181
182    ///
183    /// poiter telling how many owners to underlying data. NULL if
184    /// this is not an owner.
185    ///
186    u_int* ref_count_;
187   
188  }; 
189 
190  ///
191  /// The output operator DataLookup2D
192  ///
193  std::ostream& operator<< (std::ostream& s, const DataLookup2D&);
194
195}}} // of namespace classifier, yat, and theplu
196
197#endif
Note: See TracBrowser for help on using the repository browser.