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

Last change on this file since 1090 was 1090, checked in by Peter, 16 years ago

adding const_iterator typedef for MatrixLookupWeighted? refs #267

  • 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 1090 2008-02-14 15:22:54Z 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/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  ///
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::Iterator<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    double operator()(const size_t i) const;
115
116    ///
117    /// @return data(i) * weight(i)
118    ///
119    double operator[](const size_t i) const;
120
121  private:
122    const DataLookupWeighted1D& operator=(const DataLookupWeighted1D&);
123
124    const bool column_vector_;
125    const size_t index_;
126    const MatrixLookupWeighted* matrix_;
127    const bool owner_;
128   
129  };
130
131  ///
132  /// @return sum of weights
133  ///
134  double sum_weight(const DataLookupWeighted1D&);
135
136}}} // of namespace classifier, yat, and theplu
137
138#endif
Note: See TracBrowser for help on using the repository browser.