casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StatsHistogram.h
Go to the documentation of this file.
1 //# Copyright (C) 2000,2001
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 
26 #ifndef SCIMATH_STATSHISTOGRAM_H
27 #define SCIMATH_STATSHISTOGRAM_H
28 
30 #include <casacore/casa/aips.h>
32 
33 #include <iostream>
34 #include <casacore/casa/iosfwd.h>
35 
36 #include <vector>
37 
38 namespace casacore {
39 
40 // Represents an unfilled histogram with equal width bins for binning used for
41 // quantile computations. It is necessary to store the min/max values of the bin
42 // limits, because machine precision issues when the bin width is sufficiently
43 // small can cause slightly different results for these when different methods
44 // are used to compute them, leading to accounting errors when the histogram is
45 // filled with data.
46 
47 template <class AccumType> class StatsHistogram {
48 public:
49 
50  StatsHistogram() = delete;
51 
52  // Construct a histogram by specifying its minimum and maximum values and
53  // the number of desired bins. No padding of the min/max values is done
54  // internally, so the caller should do that prior to construction if
55  // necessary.
56  StatsHistogram(AccumType minLimit, AccumType maxLimit, uInt nBins);
57 
59 
60  // get the binWidth.
61  AccumType getBinWidth() const;
62 
63  // get the index of the bin containing the specified value
64  uInt getIndex(AccumType value) const;
65 
66  // max limit values for all bins
67  const std::vector<AccumType>& getMaxBinLimits() const;
68 
69  // max limit value of entire histogram (ie max limit value of last bin)
70  AccumType getMaxHistLimit() const;
71 
72  // min limit value of entire histogram (ie min limit value of first bin)
73  AccumType getMinHistLimit() const;
74 
75  // get the number of bins
76  uInt getNBins() const;
77 
78 private:
79 
80  AccumType _binWidth{0}, _minHistLimit{0}, _maxHistLimit{0};
82  // maximum values for all bins
83  std::vector<AccumType> _maxBinLimits{};
84 
85  // This does the obvious conversions. The Complex and DComplex
86  // specializations (implemented below after the close of the class
87  // definition) are used solely to permit compilation. In general, those
88  // versions should never actually be called
89  inline static uInt _getUInt(const AccumType& v) {
90  return (uInt)v;
91  }
92 
93  void _minMaxIdxRange(
94  Int& minIdx, Int& maxIdx, AccumType value, Bool higher
95  ) const;
96 
97 };
98 
99 // <group>
100 // The Complex and DComplex versions are used solely to permit compilation. In
101 // general, these versions should never actually be called
102 
103 template<>
105  const casacore::Complex&
106 ) {
107  ThrowCc(
108  "Logic Error: This version for complex "
109  "data types should never be called"
110  );
111 }
112 
113 template<>
115  const casacore::DComplex&
116 ) {
117  ThrowCc(
118  "Logic Error: This version for complex "
119  "data types should never be called"
120  );
121 }
122 // </group>
123 
124 // for use in debugging
125 template <class AccumType>
126 ostream &operator<<(ostream &os, const StatsHistogram<AccumType> &hist) {
127  os << "min limit " << hist.getMinHistLimit() << " max limit "
128  << hist.getMaxHistLimit() << " bin width "
129  << hist.getBinWidth() << " nbins " << hist.getNBins();
130  return os;
131 }
132 
133 }
134 
135 #ifndef CASACORE_NO_AUTO_TEMPLATES
136 #include "StatsHistogram.tcc"
137 #endif //# CASACORE_NO_AUTO_TEMPLATES
138 
139 #endif
const std::vector< AccumType > & getMaxBinLimits() const
max limit values for all bins
int Int
Definition: aipstype.h:50
Represents an unfilled histogram with equal width bins for binning used for quantile computations...
uInt getIndex(AccumType value) const
get the index of the bin containing the specified value
AccumType getMinHistLimit() const
min limit value of entire histogram (ie min limit value of first bin)
AccumType getBinWidth() const
get the binWidth.
void _minMaxIdxRange(Int &minIdx, Int &maxIdx, AccumType value, Bool higher) const
std::vector< AccumType > _maxBinLimits
maximum values for all bins
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
uInt getNBins() const
get the number of bins
static uInt _getUInt(const AccumType &v)
This does the obvious conversions.
#define ThrowCc(m)
Definition: Error.h:85
AccumType getMaxHistLimit() const
max limit value of entire histogram (ie max limit value of last bin)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51