1 | #ifndef _theplu_yat_normalization_column_normalizer_ |
---|
2 | #define _theplu_yat_normalization_column_normalizer_ |
---|
3 | |
---|
4 | /* |
---|
5 | Copyright (C) 2008 Peter Johansson |
---|
6 | |
---|
7 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
8 | |
---|
9 | The yat library is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License as |
---|
11 | published by the Free Software Foundation; either version 2 of the |
---|
12 | License, or (at your option) any later version. |
---|
13 | |
---|
14 | The yat library is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
22 | 02111-1307, USA. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "yat/utility/matrix.h" |
---|
26 | |
---|
27 | namespace theplu { |
---|
28 | namespace yat { |
---|
29 | namespace normalization { |
---|
30 | |
---|
31 | /** |
---|
32 | \brief Normalize each column |
---|
33 | |
---|
34 | Using a functor T to normalize each column. |
---|
35 | |
---|
36 | \since New in yat 0.5 |
---|
37 | */ |
---|
38 | template<class T> |
---|
39 | class ColumnNormalizer |
---|
40 | { |
---|
41 | public: |
---|
42 | /** |
---|
43 | functor used to normalize each column |
---|
44 | */ |
---|
45 | typedef T normalizer_type; |
---|
46 | |
---|
47 | /** |
---|
48 | \brief Default constructor |
---|
49 | */ |
---|
50 | ColumnNormalizer(void) {} |
---|
51 | |
---|
52 | /** |
---|
53 | \brief Constructor taking a functor \a norm |
---|
54 | */ |
---|
55 | ColumnNormalizer(T norm) |
---|
56 | : normalizer_(norm) {} |
---|
57 | |
---|
58 | /** |
---|
59 | Each column in \a result is normalized using class T. |
---|
60 | |
---|
61 | \note matrix is ignored |
---|
62 | */ |
---|
63 | void operator()(const utility::Matrix& matrix, |
---|
64 | utility::Matrix& result) const; |
---|
65 | private: |
---|
66 | T normalizer_; |
---|
67 | }; |
---|
68 | |
---|
69 | template<class T> |
---|
70 | void ColumnNormalizer<T>::operator()(const utility::Matrix& matrix, |
---|
71 | utility::Matrix& result) const |
---|
72 | { |
---|
73 | for (size_t i=0; i<matrix.rows(); ++i) |
---|
74 | normalizer_(result.begin_column(i), result.end_column(i), |
---|
75 | result.begin_column(i)); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | }}} // end of namespace normalization, yat and thep |
---|
81 | #endif |
---|