fullstats.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_fullstats_hh
22 #define mia_core_fullstats_hh
23 
24 #include <vector>
25 #include <iosfwd>
26 #include <mia/core/defines.hh>
27 
29 
40 public:
41 
48  template <typename InputIterator>
49  CFullStats(InputIterator begin, InputIterator end);
50 
52  void print(std::ostream& os) const;
53 
55  double mean()const;
57  double sigma()const;
59  double median()const;
61  double max()const;
63  double min()const;
64 
65 private:
66  typedef std::vector<double> Vector;
67  void evaluate(Vector& tmp);
68  double m_mean;
69  double m_sigma;
70  double m_median;
71  double m_max;
72  double m_min;
73 };
74 
75 template <typename InputIterator>
76 CFullStats::CFullStats(InputIterator begin, InputIterator end):
77  m_mean(0.0),
78  m_sigma(0.0),
79  m_median(0.0),
80  m_max(*begin),
81  m_min(*begin)
82 {
83 
84  Vector tmp;
85  while (begin != end) {
86  if (m_min > *begin)
87  m_min = *begin;
88 
89  if (m_max < *begin)
90  m_max = *begin;
91 
92  m_mean += *begin;
93  m_sigma += *begin * *begin;
94 
95  tmp.push_back(*begin);
96  ++begin;
97  }
98  evaluate(tmp);
99 }
100 
107 std::ostream& operator << (std::ostream& os, const CFullStats& stats)
108 {
109  stats.print(os);
110  return os;
111 }
112 
114 
115 #endif
std::ostream & operator<<(std::ostream &os, const CFullStats &stats)
Definition: fullstats.hh:107
CFullStats(InputIterator begin, InputIterator end)
Definition: fullstats.hh:76
This class is used to evaluate the statistics of a series of input data.
Definition: fullstats.hh:39
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
void print(std::ostream &os) const
Print the statistics to some output file.
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36