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 #pragma once
10
11 namespace opals {
12
13  /// \brief HistoStats provides a histogram and additional statistical measures.
14  ///
15  /// HistoStats provides a histogram and additional statistical measures like
16  /// min, max, mean, median ... of certain data sample.
17  /// The histogram in particular is stored as a std::vector of std:pairs, each of which
18  /// stores the data of a single histogram bin (class) with its lower
19  /// boundary (first) and relative frequency (second). The first bin
20  /// contains all underflow values, followed by the regular bins of
21  /// constant width. The last class contains all overflow values. Absolute
22  /// frequencies can be obtained by multiplying the relative frequencies
23  /// with the total number of samples (countUsed). Additionally, several
24  /// standard statistical values are provided (min, max, mean, median...)
25  ///
26  /// \author GM
27  /// \date 12.06.2010
28  class OPALS_API HistoStats
29  {
30  public:
31  /// vector of double pairs
34
35  /// vector of histogram bins stored as std::pair
36  /** first: lower bound of bin, second: absolute or relative frequency */
38  typedef PairOfDblVec RelBinVector;
39
40  typedef RelBinVector BinVector; ///deprecated: use AbsBinVector or RelBinVector instead
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; }
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; }
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  RelBinVector getCumulatedBins() const; ///< get bin vector with cumulated frequency values
93  double getBinWidth() const { return binWidth; }
94  opals::HistoMode getCalcMode() const { return calcMode; }
95  const opals::String& getLabel() const { return label; }
96  bool getExactComputation() const { return exactComputation; }
97
98  BinVector getBins() const { return getRelBins(); } ///deprecated: use getRelBins instead
99
100  /// output functions
101  String logHistoStats(bool absBins = true, int precision = 3) const; /// for xml output
102  String printHistoStats(bool absBins = true, unsigned maxBins = 0) const; /// for log output (in more readable format)
103  String printRelBins(unsigned maxBins = 0, double lowerQuantile = 0.05, double upperQuantile = 0.95) const;
104  String printRelAbsBins(unsigned precision = 3, bool outputCumulatedBins = false) const;
105
106  unsigned estimateOutputPrecision(unsigned defaultPrec = 3) const;
107
108  private:
109  long long countUsed, countData;
110  double min, max, mean, median, mode, stdDev, rms, stdDevMAD, skewness;
111  QuantileVector quantiles;
112  AbsBinVector bins;
113  double binWidth;
114  opals::String label;
115  HistoMode calcMode;
116  bool exactComputation;
117  };
118 }
119
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:37
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
@ exactComputation
flag for exact median computation (opalsHisto)
opals::Vector< std::pair< double, double > > PairOfDblVec
vector of double pairs
Definition: HistoStats.hpp:32
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:28