1 | #ifndef _theplu_yat_classifier_dataLookup_weighted_1D_ |
---|
2 | #define _theplu_yat_classifier_dataLookup_weighted_1D_ |
---|
3 | |
---|
4 | // $Id: DataLookupWeighted1D.h 1193 2008-02-29 19:48:45Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2007 Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 2 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "MatrixLookupWeighted.h" |
---|
29 | #include "yat/utility/Container2DIterator.h" |
---|
30 | #include "yat/utility/IteratorPolicy.h" |
---|
31 | #include "yat/utility/StrideIterator.h" |
---|
32 | |
---|
33 | #include <iostream> |
---|
34 | #include <utility> |
---|
35 | #include <vector> |
---|
36 | |
---|
37 | namespace theplu { |
---|
38 | namespace yat { |
---|
39 | namespace classifier { |
---|
40 | |
---|
41 | /// |
---|
42 | /// @brief Class for general weighted vector view. |
---|
43 | /// |
---|
44 | /// @see MatrixLookupWeighted |
---|
45 | /// |
---|
46 | class DataLookupWeighted1D |
---|
47 | { |
---|
48 | |
---|
49 | public: |
---|
50 | /// 'Read Only' iterator |
---|
51 | typedef utility::StrideIterator< |
---|
52 | utility::Container2DIterator<const MatrixLookupWeighted, |
---|
53 | const std::pair<double, double>, void, |
---|
54 | const std::pair<double, double>, |
---|
55 | utility::IteratorPolicyWeighted<const MatrixLookupWeighted, |
---|
56 | const double, |
---|
57 | const double> > > |
---|
58 | const_iterator; |
---|
59 | |
---|
60 | /// |
---|
61 | /// Constructor. |
---|
62 | /// |
---|
63 | /// @param row_vector if true (default) DataLookup1D is |
---|
64 | /// looking into a row of MatrixLookupWeighted, otherwise looking into |
---|
65 | /// a column. @param index which row/column to look into. |
---|
66 | /// |
---|
67 | DataLookupWeighted1D(const MatrixLookupWeighted&, const size_t index, |
---|
68 | const bool row_vector); |
---|
69 | |
---|
70 | /// |
---|
71 | /// Copy constructor |
---|
72 | /// |
---|
73 | DataLookupWeighted1D(const DataLookupWeighted1D&); |
---|
74 | |
---|
75 | /// |
---|
76 | /// Construct DataLookup1D that owns its underlying matrix. Object |
---|
77 | /// has size \a size and all its element is equal to \a value. |
---|
78 | /// |
---|
79 | DataLookupWeighted1D(const size_t size, double value=0, double weight=1); |
---|
80 | |
---|
81 | /// |
---|
82 | /// @brief Destructor |
---|
83 | /// |
---|
84 | virtual ~DataLookupWeighted1D(); |
---|
85 | |
---|
86 | /** |
---|
87 | \return 'Read Only' iterator to beginning of DataLookupWeighted1D. |
---|
88 | */ |
---|
89 | const_iterator begin() const; |
---|
90 | |
---|
91 | /** |
---|
92 | \return data(i) |
---|
93 | */ |
---|
94 | double data(const size_t i) const; |
---|
95 | |
---|
96 | /** |
---|
97 | \return 'Read Only' iterator to end of DataLookupWeighted1D. |
---|
98 | */ |
---|
99 | const_iterator end() const; |
---|
100 | |
---|
101 | /// |
---|
102 | /// @return number of elements |
---|
103 | /// |
---|
104 | size_t size(void) const; |
---|
105 | |
---|
106 | /// |
---|
107 | /// @return weight(i) |
---|
108 | /// |
---|
109 | double weight(const size_t i) const; |
---|
110 | |
---|
111 | /// |
---|
112 | /// @return data(i) * weight(i) |
---|
113 | /// |
---|
114 | std::pair<double, double> operator()(const size_t i) const; |
---|
115 | |
---|
116 | private: |
---|
117 | const DataLookupWeighted1D& operator=(const DataLookupWeighted1D&); |
---|
118 | |
---|
119 | const bool column_vector_; |
---|
120 | const size_t index_; |
---|
121 | const MatrixLookupWeighted* matrix_; |
---|
122 | const bool owner_; |
---|
123 | |
---|
124 | }; |
---|
125 | |
---|
126 | /// |
---|
127 | /// @return sum of weights |
---|
128 | /// |
---|
129 | double sum_weight(const DataLookupWeighted1D&); |
---|
130 | |
---|
131 | }}} // of namespace classifier, yat, and theplu |
---|
132 | |
---|
133 | #endif |
---|