1 | #ifndef _theplu_yat_classifier_dataLookup_weighted_1D_ |
---|
2 | #define _theplu_yat_classifier_dataLookup_weighted_1D_ |
---|
3 | |
---|
4 | // $Id: DataLookupWeighted1D.h 1268 2008-04-09 14:13:49Z 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 m MatrixLookupWeighted to look into |
---|
64 | /// @param row_vector if true (default) DataLookup1D is |
---|
65 | /// looking into a row of MatrixLookupWeighted, otherwise looking into |
---|
66 | /// a column. @param index which row/column to look into. |
---|
67 | /// |
---|
68 | DataLookupWeighted1D(const MatrixLookupWeighted& m, const size_t index, |
---|
69 | const bool row_vector); |
---|
70 | |
---|
71 | /// |
---|
72 | /// Copy constructor |
---|
73 | /// |
---|
74 | DataLookupWeighted1D(const DataLookupWeighted1D&); |
---|
75 | |
---|
76 | /// |
---|
77 | /// Construct DataLookup1D that owns its underlying matrix. Object |
---|
78 | /// has size \a size and all its element is equal to \a value. |
---|
79 | /// |
---|
80 | DataLookupWeighted1D(const size_t size, double value=0, double weight=1); |
---|
81 | |
---|
82 | /// |
---|
83 | /// @brief Destructor |
---|
84 | /// |
---|
85 | virtual ~DataLookupWeighted1D(); |
---|
86 | |
---|
87 | /** |
---|
88 | \return 'Read Only' iterator to beginning of DataLookupWeighted1D. |
---|
89 | */ |
---|
90 | const_iterator begin() const; |
---|
91 | |
---|
92 | /** |
---|
93 | \return data(i) |
---|
94 | */ |
---|
95 | double data(const size_t i) const; |
---|
96 | |
---|
97 | /** |
---|
98 | \return 'Read Only' iterator to end of DataLookupWeighted1D. |
---|
99 | */ |
---|
100 | const_iterator end() const; |
---|
101 | |
---|
102 | /// |
---|
103 | /// @return number of elements |
---|
104 | /// |
---|
105 | size_t size(void) const; |
---|
106 | |
---|
107 | /// |
---|
108 | /// @return weight(i) |
---|
109 | /// |
---|
110 | double weight(const size_t i) const; |
---|
111 | |
---|
112 | /// |
---|
113 | /// @return data(i) * weight(i) |
---|
114 | /// |
---|
115 | std::pair<double, double> operator()(const size_t i) const; |
---|
116 | |
---|
117 | private: |
---|
118 | const DataLookupWeighted1D& operator=(const DataLookupWeighted1D&); |
---|
119 | |
---|
120 | const bool column_vector_; |
---|
121 | const size_t index_; |
---|
122 | const MatrixLookupWeighted* matrix_; |
---|
123 | const bool owner_; |
---|
124 | |
---|
125 | }; |
---|
126 | |
---|
127 | /// |
---|
128 | /// @return sum of weights |
---|
129 | /// |
---|
130 | double sum_weight(const DataLookupWeighted1D&); |
---|
131 | |
---|
132 | }}} // of namespace classifier, yat, and theplu |
---|
133 | |
---|
134 | #endif |
---|