HistoStats.hpp
1 #ifndef OPALS_HISTO_STATS_HPP_INCLUDED
2 #define OPALS_HISTO_STATS_HPP_INCLUDED
3 
4 #pragma once
5 
6 #include "opals/config.hpp"
7 #include "opals/String.hpp"
8 #include "opals/Array.hpp"
9 #include "opals/Vector.hpp"
10 #include "opals/HistoMode.hpp"
11 
12 namespace opals {
13 
14  /// \brief HistoStats provides a histogram and additional statistical measures.
15  ///
16  /// HistoStats provides a histogram and additional statistical measures like
17  /// min, max, mean, median ... of certain data sample.
18  /// The histogram in particular is stored as a std::vector of std:pairs, each of which
19  /// stores the data of a single histogram bin (class) with its lower
20  /// boundary (first) and relative frequency (second). The first bin
21  /// contains all underflow values, followed by the regular bins of
22  /// constant width. The last class contains all overflow values. Absolute
23  /// frequencies can be obtained by multiplying the relative frequancies
24  /// with the total numer of samples (countUsed). Additionally, several
25  /// standard statistical values are provided (min, max, mean, median...)
26  ///
27  /// \author GM
28  /// \date 12.06.2010
29  class OPALS_API HistoStats
30  {
31  public:
32  /// vector of double pairs
35 
36  /// vector of histogram bins stored as std::pair
37  /** first: lower bound of bin, second: absolute or relative frequency */
39  typedef PairOfDblVec RelBinVector;
40 
41  typedef RelBinVector BinVector; ///deprecated: use AbsBinVector or RelBinVector instead
42 
43 
44 
45  /// vector of quantiles
46  /** first: probabilities (double: 0 <= p <= 1), second: according quantiles */
48 
49  public:
50  HistoStats();
51  virtual ~HistoStats();
52 
53  /// access functions
54  void setHistoStats( const long long &CountData,
55  const long long &CountUsed,
56  const double &Min, const double &Max, const double &Mean,
57  const double &Median, const double &Mode,
58  const double &StdDev, const double &Rms,
59  const double &StdDevMAD, const double &Skewness,
60  const opals::HistoMode::Type &CalcMode,
61  const QuantileVector &Quantiles, const AbsBinVector &Bins );
62  void setCountData( const double &Count ) { countData = Count; }
63  void setCountUsed( const double &Count ) { countUsed = Count; }
64  void setMin( const double &Min ) { min = Min; }
65  void setMax( const double &Max ) { max = Max; }
66  void setMean( const double &Mean ) { mean = Mean; }
67  void setMedian( const double &Median ) { median = Median; }
68  void setMode(const double &Mode) { mode = Mode; }
69  void setStdDev( const double &StdDev) { stdDev = StdDev; }
70  void setRms( const double &Rms) { rms = Rms; }
71  void setStdDevMAD( const double &StdDev) { stdDev = StdDev; }
72  void setSkewness( const double &Skewness ) { skewness = Skewness; }
73  void setQuantiles( const QuantileVector &Quantiles ) { quantiles = Quantiles; }
74  void setAbsBins( const AbsBinVector &Bins ) { bins = Bins; }
75  void setCalcMode( const opals::HistoMode::Type CalcMode) { calcMode = CalcMode; }
76  void setLabel( const opals::String &Label ) { label = Label; }
77 
78  /// query functions
79  long long getCountData() const { return countData; }
80  long long getCountUsed() const { return countUsed; }
81  double getMin() const { return min; }
82  double getMax() const { return max; }
83  double getMean() const{ return mean; }
84  double getMedian() const { return median; }
85  double getMode() const { return mode; }
86  double getStdDev() const { return stdDev; }
87  double getRms() const { return rms; }
88  double getStdDevMAD() const { return stdDevMAD; }
89  double getSkewness() const { return skewness; }
90  QuantileVector getQuantiles() const { return quantiles; }
91  AbsBinVector getAbsBins() const { return bins; } ///< get bin vector with absolute frequency values
92  RelBinVector getRelBins() const; ///< get bin vector with relative frequency values
93  opals::HistoMode::Type getCalcMode() const { return calcMode; }
94  const opals::String& getLabel() const { return label; }
95 
96  BinVector getBins() const { return getRelBins(); } ///deprecated: use getRelBins instead
97 
98 
99  /// output functions
100  String logHistoStats(bool absBins = true) const; /// for xml output
101  String printHistoStats(bool absBins = true) const; /// for log output (in more readable format)
102 
103  private:
104  long long countUsed, countData;
105  double count, min, max, mean, median, mode, stdDev, rms, stdDevMAD, skewness;
106  QuantileVector quantiles;
107  AbsBinVector bins;
108  opals::String label;
109  HistoMode::Type calcMode;
110  };
111 }
112 
113 #endif //OPALS_HISTO_STATS_HPP_INCLUDED