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