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> class StatsHistogram {
48public:
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
78private:
79
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
103template<>
105 const casacore::Complex&
106) {
107 ThrowCc(
108 "Logic Error: This version for complex "
109 "data types should never be called"
110 );
111}
112
113template<>
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
125template <class AccumType>
126ostream &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
#define ThrowCc(m)
Definition Error.h:83
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.
this file contains all the compiler specific defines
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
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.