1 | #ifndef _theplu_yat_statistics_vector_function_ |
---|
2 | #define _theplu_yat_statistics_vector_function_ |
---|
3 | |
---|
4 | // $Id: VectorFunction.h 1275 2008-04-11 06:10:12Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
8 | |
---|
9 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
10 | |
---|
11 | The yat library is free software; you can redistribute it and/or |
---|
12 | modify it under the terms of the GNU General Public License as |
---|
13 | published by the Free Software Foundation; either version 2 of the |
---|
14 | License, or (at your option) any later version. |
---|
15 | |
---|
16 | The yat library is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | 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 <vector> |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | namespace yat { |
---|
31 | namespace statistics { |
---|
32 | |
---|
33 | /// |
---|
34 | /// \brief Interface Class for vector functors. |
---|
35 | /// |
---|
36 | struct VectorFunction |
---|
37 | { |
---|
38 | /** |
---|
39 | \brief Destructor |
---|
40 | */ |
---|
41 | virtual ~VectorFunction(); |
---|
42 | |
---|
43 | /** |
---|
44 | \brief abstract interface |
---|
45 | */ |
---|
46 | virtual double operator()(const std::vector<double>&) const=0; |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | /// |
---|
51 | /// @brief Larget element |
---|
52 | /// |
---|
53 | struct Max : public VectorFunction |
---|
54 | { |
---|
55 | /// |
---|
56 | /// \return Largest element |
---|
57 | /// |
---|
58 | double operator()(const std::vector<double>&) const; |
---|
59 | }; |
---|
60 | |
---|
61 | |
---|
62 | /// |
---|
63 | /// @brief Median element |
---|
64 | /// |
---|
65 | struct Median : public VectorFunction |
---|
66 | { |
---|
67 | /// |
---|
68 | /// \see statistics::median(std::vector<double>, bool) |
---|
69 | /// |
---|
70 | /// \return Median |
---|
71 | /// |
---|
72 | double operator()(const std::vector<double>&) const; |
---|
73 | }; |
---|
74 | |
---|
75 | /// |
---|
76 | /// \brief Mean element |
---|
77 | /// |
---|
78 | struct Mean : public VectorFunction |
---|
79 | { |
---|
80 | /// |
---|
81 | /// \return Mean |
---|
82 | /// |
---|
83 | double operator()(const std::vector<double>&) const; |
---|
84 | }; |
---|
85 | |
---|
86 | |
---|
87 | /// |
---|
88 | /// \brief Smallest element |
---|
89 | /// |
---|
90 | struct Min : public VectorFunction |
---|
91 | { |
---|
92 | /// |
---|
93 | /// \return Smallest element |
---|
94 | /// |
---|
95 | double operator()(const std::vector<double>&) const; |
---|
96 | }; |
---|
97 | |
---|
98 | /** |
---|
99 | Functor that picks Nth smalles element in a vector. |
---|
100 | */ |
---|
101 | class Nth_Element : public VectorFunction |
---|
102 | { |
---|
103 | public: |
---|
104 | /// |
---|
105 | /// \param N equal to 1 gives identical object as Min (but less |
---|
106 | /// efficient) |
---|
107 | /// |
---|
108 | Nth_Element(size_t N); |
---|
109 | |
---|
110 | /// |
---|
111 | /// \return Nth smallest element |
---|
112 | /// |
---|
113 | double operator()(const std::vector<double>&) const; |
---|
114 | |
---|
115 | private: |
---|
116 | size_t N_; |
---|
117 | }; |
---|
118 | |
---|
119 | }}} // of namespace statistics, yat, and theplu |
---|
120 | |
---|
121 | #endif |
---|