source: trunk/yat/classifier/DataLookupWeighted1D.h @ 1088

Last change on this file since 1088 was 1088, checked in by Peter, 13 years ago

Closes #247. Removed IteratorWeighted? iterators over weighted container instead can use Iterator with a special Policy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1#ifndef _theplu_yat_classifier_dataLookup_weighted_1D_
2#define _theplu_yat_classifier_dataLookup_weighted_1D_
3
4// $Id: DataLookupWeighted1D.h 1088 2008-02-14 14:26:19Z 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 "DataLookup2D.h"
29#include "yat/utility/Iterator.h"
30#include "yat/utility/IteratorPolicy.h"
31#include "yat/utility/StrideIterator.h"
32
33#include <iostream>
34#include <utility>
35#include <vector>
36
37namespace theplu {
38namespace yat {
39namespace classifier { 
40
41  class MatrixLookupWeighted;
42
43  ///
44  /// @brief Class for general weighted vector view.
45  ///
46  /// @see MatrixLookupWeighted
47  ///
48  class DataLookupWeighted1D
49  {
50 
51  public:
52    /// 'Read Only' iterator
53    typedef utility::StrideIterator<
54    utility::Iterator<const DataLookup2D, const std::pair<double, double>, 
55                      void, const std::pair<double, double>,
56                      utility::IteratorPolicyWeighted<const DataLookup2D,
57                                                      const double,
58                                                      const double> > >
59    const_iterator;
60
61    ///
62    /// Constructor.
63    ///
64    /// @param row_vector if true (default) DataLookup1D is
65    /// looking into a row of DataLookup2D, otherwise looking into
66    /// a column. @param index which row/column to look into.
67    ///
68    DataLookupWeighted1D(const MatrixLookupWeighted&, 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 @ 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    double operator()(const size_t i) const;
116
117    ///
118    /// @return data(i) * weight(i)
119    ///
120    double operator[](const size_t i) const;
121
122  private:
123    const DataLookupWeighted1D& operator=(const DataLookupWeighted1D&);
124
125    const bool column_vector_;
126    const size_t index_;
127    const MatrixLookupWeighted* matrix_;
128    const bool owner_;
129   
130  };
131
132  ///
133  /// @return sum of weights
134  ///
135  double sum_weight(const DataLookupWeighted1D&);
136
137}}} // of namespace classifier, yat, and theplu
138
139#endif
Note: See TracBrowser for help on using the repository browser.