source: branches/0.4-stable/yat/classifier/DataLookupWeighted1D.h @ 1392

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

trac has moved

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1#ifndef _theplu_yat_classifier_dataLookup_weighted_1D_
2#define _theplu_yat_classifier_dataLookup_weighted_1D_
3
4// $Id: DataLookupWeighted1D.h 1392 2008-07-28 19:35:30Z peter $
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 2 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 this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "MatrixLookupWeighted.h"
30#include "yat/utility/Container2DIterator.h"
31#include "yat/utility/IteratorPolicy.h"
32#include "yat/utility/StrideIterator.h"
33
34#include <iostream>
35#include <utility>
36#include <vector>
37
38namespace theplu {
39namespace yat {
40namespace classifier { 
41
42  ///
43  /// @brief Class for general weighted vector view.
44  ///
45  /// @see MatrixLookupWeighted
46  ///
47  class DataLookupWeighted1D
48  {
49 
50  public:
51    /// 'Read Only' iterator
52    typedef utility::StrideIterator<
53    utility::Container2DIterator<const MatrixLookupWeighted, 
54                                 const std::pair<double, double>, void, 
55                                 const std::pair<double, double>,
56             utility::IteratorPolicyWeighted<const MatrixLookupWeighted,
57                                             const double,
58                                             const double> > >
59    const_iterator;
60
61    ///
62    /// Constructor.
63    ///
64    /// \param m MatrixLookupWeighted to look into
65    /// @param row_vector if true (default) DataLookup1D is
66    /// looking into a row of MatrixLookupWeighted, otherwise looking into
67    /// a column. @param index which row/column to look into.
68    ///
69    DataLookupWeighted1D(const MatrixLookupWeighted& m, const size_t index, 
70                         const bool row_vector);
71
72    ///
73    /// Copy constructor
74    ///
75    DataLookupWeighted1D(const DataLookupWeighted1D&);
76
77    ///
78    /// Construct DataLookup1D that owns its underlying matrix. Object
79    /// has size \a size and all its element is equal to \a value.
80    ///
81    DataLookupWeighted1D(const size_t size, double value=0, double weight=1); 
82
83    ///
84    /// @brief Destructor
85    ///
86    virtual ~DataLookupWeighted1D();
87
88    /**
89       \return 'Read Only' iterator to beginning of DataLookupWeighted1D.
90     */
91    const_iterator begin() const;
92
93    /**
94       \return data(i)
95    */
96    double data(const size_t i) const;
97   
98    /**
99       \return 'Read Only' iterator to end of DataLookupWeighted1D.
100     */
101    const_iterator end() const;
102
103    ///
104    /// @return number of elements
105    ///
106    size_t size(void) const;
107
108    ///
109    /// @return weight(i)
110    ///
111    double weight(const size_t i) const;
112
113    ///
114    /// @return data(i) * weight(i)
115    ///
116    std::pair<double, double> operator()(const size_t i) const;
117
118  private:
119    const DataLookupWeighted1D& operator=(const DataLookupWeighted1D&);
120
121    const bool column_vector_;
122    const size_t index_;
123    const MatrixLookupWeighted* matrix_;
124    const bool owner_;
125   
126  };
127
128  ///
129  /// @return sum of weights
130  ///
131  double sum_weight(const DataLookupWeighted1D&);
132
133}}} // of namespace classifier, yat, and theplu
134
135#endif
Note: See TracBrowser for help on using the repository browser.