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

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

fixing Doxygen parsing

  • 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 <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    /**
114       \return data
115    */
116    virtual double data(size_t i, size_t j) const;
117   
118    ///
119    /// @return number of rows
120    ///
121    size_t rows(void) const;
122
123    ///
124    /// @return Data based on selected features.
125    ///
126    virtual const DataLookup2D* selected(const std::vector< size_t > &) const=0;
127
128    ///
129    /// @return sub-Lookup of the DataLookup2D
130    ///
131    /// @note Returns a dynamically allocated DataLookup2D, which has
132    /// to be deleted by the caller to avoid memory leaks.
133    ///
134    virtual const DataLookup2D* 
135    training_data(const std::vector<size_t>&) const=0; 
136
137    ///
138    /// @return sub-Lookup of the DataLookup2D
139    ///
140    /// @note Returns a dynamically allocated DataLookup2D, which has
141    /// to be deleted by the caller to avoid memory leaks.
142    ///
143    virtual const DataLookup2D* 
144    validation_data(const std::vector<size_t>& train,
145                    const std::vector<size_t>& val) const=0; 
146
147    /**
148       \return data
149    */
150    virtual double weight(size_t i, size_t j) const;
151   
152    ///
153    /// Is lookup weighted?
154    ///
155    virtual bool weighted(void) const=0;
156
157    ///
158    /// @brief access operator
159    ///
160    /// @return value in that particular element
161    ///
162    virtual double operator()(const size_t row, const size_t column) const=0;
163
164  protected:
165    ///
166    /// @brief assignment operator
167    ///
168    const DataLookup2D& operator=(const DataLookup2D&); 
169
170    ///
171    /// @brief which rows to look into
172    ///
173    std::vector<size_t> row_index_;
174
175    ///
176    /// @brief which columns to look into
177    ///
178    std::vector<size_t> column_index_;
179
180    ///
181    /// poiter telling how many owners to underlying data. NULL if
182    /// this is not an owner.
183    ///
184    u_int* ref_count_;
185   
186  }; 
187 
188  ///
189  /// The output operator DataLookup2D
190  ///
191  std::ostream& operator<< (std::ostream& s, const DataLookup2D&);
192
193}}} // of namespace classifier, yat, and theplu
194
195#endif
Note: See TracBrowser for help on using the repository browser.