casacore
Loading...
Searching...
No Matches
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: casa-feedback@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
38namespace 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
47template <class AccumType>
49 public:
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:
81 // maximum values for all bins
82 std::vector<AccumType> _maxBinLimits{};
83
84 // This does the obvious conversions. The Complex and DComplex
85 // specializations (implemented below after the close of the class
86 // definition) are used solely to permit compilation. In general, those
87 // versions should never actually be called
88 inline static uInt _getUInt(const AccumType& v) { return (uInt)v; }
89
90 void _minMaxIdxRange(Int& minIdx, Int& maxIdx, AccumType value, Bool higher) const;
91};
92
93// <group>
94// The Complex and DComplex versions are used solely to permit compilation. In
95// general, these versions should never actually be called
96
97template <>
98inline uInt StatsHistogram<casacore::Complex>::_getUInt(const casacore::Complex&) {
99 ThrowCc(
100 "Logic Error: This version for complex "
101 "data types should never be called");
102}
103
104template <>
105inline uInt StatsHistogram<casacore::DComplex>::_getUInt(const casacore::DComplex&) {
106 ThrowCc(
107 "Logic Error: This version for complex "
108 "data types should never be called");
109}
110// </group>
111
112// for use in debugging
113template <class AccumType>
114ostream& operator<<(ostream& os, const StatsHistogram<AccumType>& hist) {
115 os << "min limit " << hist.getMinHistLimit() << " max limit " << hist.getMaxHistLimit()
116 << " bin width " << hist.getBinWidth() << " nbins " << hist.getNBins();
117 return os;
118}
119
120} // namespace casacore
121
122#ifndef CASACORE_NO_AUTO_TEMPLATES
123#include "StatsHistogram.tcc"
124#endif // # CASACORE_NO_AUTO_TEMPLATES
125
126#endif
#define ThrowCc(m)
Definition Error.h:96
Represents an unfilled histogram with equal width bins for binning used for quantile computations.
std::vector< AccumType > _maxBinLimits
maximum values for all bins
const std::vector< AccumType > & getMaxBinLimits() const
max limit values for all bins
AccumType getMinHistLimit() const
min limit value of entire histogram (ie min limit value of first bin)
AccumType getMaxHistLimit() const
max limit value of entire histogram (ie max limit value of last bin)
static uInt _getUInt(const AccumType &v)
This does the obvious conversions.
uInt getNBins() const
get the number of bins
uInt getIndex(AccumType value) const
get the index of the bin containing the specified value
StatsHistogram(AccumType minLimit, AccumType maxLimit, uInt nBins)
Construct a histogram by specifying its minimum and maximum values and the number of desired bins.
void _minMaxIdxRange(Int &minIdx, Int &maxIdx, AccumType value, Bool higher) const
AccumType getBinWidth() const
get the binWidth.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360