casacore
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 
29 #include <casacore/casa/Utilities/DataType.h>
30 #include <casacore/casa/aips.h>
31 #include <casacore/casa/Exceptions/Error.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 
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
casacore::StatsHistogram::_getUInt
static uInt _getUInt(const AccumType &v)
This does the obvious conversions.
Definition: StatsHistogram.h:89
casacore::StatsHistogram::_minMaxIdxRange
void _minMaxIdxRange(Int &minIdx, Int &maxIdx, AccumType value, Bool higher) const
Complexfwd_global_functions_Complexfwd::casacore::DComplex
std::complex< Double > DComplex
Definition: Complexfwd.h:50
casacore::StatsHistogram::_maxHistLimit
AccumType _maxHistLimit
Definition: StatsHistogram.h:80
casacore::StatsHistogram::_binWidth
AccumType _binWidth
Definition: StatsHistogram.h:80
casacore::StatsHistogram::_maxBinLimits
std::vector< AccumType > _maxBinLimits
maximum values for all bins
Definition: StatsHistogram.h:83
casacore::StatsHistogram::getIndex
uInt getIndex(AccumType value) const
get the index of the bin containing the specified value
casacore::StatsHistogram::~StatsHistogram
~StatsHistogram()
casacore::StatsHistogram::getMaxHistLimit
AccumType getMaxHistLimit() const
max limit value of entire histogram (ie max limit value of last bin)
casacore::value
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::StatsHistogram::getMaxBinLimits
const std::vector< AccumType > & getMaxBinLimits() const
max limit values for all bins
casacore::StatsHistogram::_nBins
uInt _nBins
Definition: StatsHistogram.h:81
casacore::StatsHistogram::getMinHistLimit
AccumType getMinHistLimit() const
min limit value of entire histogram (ie min limit value of first bin)
casacore::StatsHistogram
Represents an unfilled histogram with equal width bins for binning used for quantile computations.
Definition: StatsHistogram.h:47
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::StatsHistogram::StatsHistogram
StatsHistogram()=delete
ThrowCc
#define ThrowCc(m)
Definition: Error.h:85
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Complexfwd_global_functions_Complexfwd::casacore::Complex
std::complex< Float > Complex
Definition: Complexfwd.h:49
casacore::operator<<
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
casacore::StatsHistogram::_minHistLimit
AccumType _minHistLimit
Definition: StatsHistogram.h:80
casacore::StatsHistogram::getBinWidth
AccumType getBinWidth() const
get the binWidth.
casacore::StatsHistogram::getNBins
uInt getNBins() const
get the number of bins
casacore::StatsHistogram::StatsHistogram
StatsHistogram(AccumType minLimit, AccumType maxLimit, uInt nBins)
Construct a histogram by specifying its minimum and maximum values and the number of desired bins.