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

Last change on this file since 1487 was 1487, checked in by Jari Häkkinen, 14 years ago

Addresses #436. GPL license copy reference should also be updated.

  • 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 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2008 Peter Johansson, Markus Ringnér
10
11  This file is part of the yat library, http://dev.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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#include "MatrixLookupWeighted.h"
28#include "yat/utility/Container2DIterator.h"
29#include "yat/utility/IteratorPolicy.h"
30#include "yat/utility/StrideIterator.h"
31
32#include <iostream>
33#include <utility>
34#include <vector>
35
36namespace theplu {
37namespace yat {
38namespace classifier { 
39
40  ///
41  /// @brief Class for general weighted vector view.
42  ///
43  /// @see MatrixLookupWeighted
44  ///
45  class DataLookupWeighted1D
46  {
47 
48  public:
49    /// 'Read Only' iterator
50    typedef utility::StrideIterator<
51    utility::Container2DIterator<const MatrixLookupWeighted, 
52                                 const std::pair<double, double>, void, 
53                                 const std::pair<double, double>,
54             utility::IteratorPolicyWeighted<const MatrixLookupWeighted,
55                                             const double,
56                                             const double> > >
57    const_iterator;
58
59    ///
60    /// Constructor.
61    ///
62    /// \param m MatrixLookupWeighted to look into
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& m, 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
Note: See TracBrowser for help on using the repository browser.