source: trunk/c++_tools/classifier/DataLookupWeighted1D.h @ 622

Last change on this file since 622 was 622, checked in by Peter, 15 years ago

fixes #111

File size: 2.9 KB
Line 
1#ifndef _theplu_classifier_dataLookup_weighted_1D_
2#define _theplu_classifier_dataLookup_weighted_1D_
3
4// $Id$
5/*
6  Copyright (C) 2006 Peter Johansson
7
8  This file is part of the thep c++ tools library,
9                                http://lev.thep.lu.se/trac/c++_tools
10
11  The c++ tools library is free software; you can redistribute it
12  and/or modify it under the terms of the GNU General Public License
13  as published by the Free Software Foundation; either version 2 of
14  the License, or (at your option) any later version.
15
16  The c++ tools library is distributed in the hope that it will be
17  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
18  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include <c++_tools/classifier/MatrixLookupWeighted.h>
28
29#include <iostream>
30#include <vector>
31
32namespace theplu {
33namespace classifier { 
34
35  ///
36  /// Class for general weighted vector view.
37  ///
38  /// @see MatrixLookupWeighted
39  ///
40  class DataLookupWeighted1D
41  {
42 
43  public:
44
45    ///
46    /// Constructor.
47    ///
48    /// @parameter row_vector if true (default) DataLookup1D is
49    /// looking into a row of DataLookup2D, otherwise looking into
50    /// a column. @parameter index which row/column to look into.
51    ///
52    DataLookupWeighted1D(const MatrixLookupWeighted&, const size_t index, 
53                         const bool row_vector);
54
55    ///
56    /// Copy constructor
57    ///
58    DataLookupWeighted1D(const DataLookupWeighted1D&);
59
60    ///
61    /// Construct DataLookup1D that owns its underlying matrix. Object
62    /// has size @ size and all its element is equal to @a value.
63    ///
64    DataLookupWeighted1D(const size_t size, double value=0, double weight=1); 
65
66    ///
67    ///
68    ///
69    virtual ~DataLookupWeighted1D();
70
71    ///
72    ///
73    ///
74    inline size_t size(void) const
75      { return column_vector_ ? matrix_->rows() : matrix_->columns(); }
76
77    ///
78    /// @return data(i)
79    ///
80    inline double data(const size_t i) const 
81    { 
82      return column_vector_? matrix_->data(i,index_) : matrix_->data(index_,i); 
83    }
84
85    ///
86    /// @return weight(i)
87    ///
88    inline double weight(const size_t i) const 
89    { 
90      return column_vector_? matrix_->weight(i,index_) : 
91        matrix_->weight(index_,i); 
92    }
93
94    ///
95    /// @return data(i) * weight(i)
96    ///
97    inline double operator()(const size_t i) const 
98    { 
99      return column_vector_ ? (*matrix_)(i,index_) : (*matrix_)(index_,i); 
100    }
101
102    ///
103    ///
104    ///
105    inline double operator[](const size_t i) const 
106    { 
107      return this->operator()(i);
108    }
109
110
111  private:
112    const DataLookupWeighted1D& operator=(const DataLookupWeighted1D&);
113
114    const bool column_vector_;
115    const size_t index_;
116    const MatrixLookupWeighted* matrix_;
117    const bool owner_;
118   
119  };
120
121}} // of namespace classifier and namespace theplu
122
123#endif
Note: See TracBrowser for help on using the repository browser.