casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HingesFencesStatistics.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_HINGESFENCESSTATISTICS_H
27 #define SCIMATH_HINGESFENCESSTATISTICS_H
28 
29 #include <casacore/casa/aips.h>
30 
32 
33 #include <set>
34 #include <vector>
35 #include <utility>
36 
37 namespace casacore {
38 
39 // Class to calculate statistics using the so-called hinges and fences
40 // algorithm. In this algorithm, the data on which the statistics are computed
41 // from is limited to the range of values between Q1 - f*D and Q3 + f*D,
42 // inclusive, where D = Q3 - Q1 and Q1 and Q3 are the first and third quartiles,
43 // respectively.
44 //
45 // This class uses a HingesFencesQuantileComputer object for computing quantile-
46 // like statistics. See class documentation for StatisticsAlgorithm for details
47 // regarding QuantileComputer classes.
48 
49 template <
50  class AccumType, class DataIterator, class MaskIterator=const Bool *,
51  class WeightsIterator=DataIterator
52 >
54  : public ConstrainedRangeStatistics<CASA_STATP> {
55 public:
56 
57  // If <src>f</src> is negative, the full dataset is used; ie the object has
58  // the same behavior as a ClassicalStatistics object
60 
61  // copy semantics
63 
64  virtual ~HingesFencesStatistics();
65 
66  // copy semantics
69  );
70 
71  // Clone this instance. Caller is responsible for deleting the returned
72  // pointer.
73  virtual StatisticsAlgorithm<CASA_STATP>* clone() const;
74 
75  // get the algorithm that this object uses for computing stats
78  };
79 
80  // reset object to initial state. Clears all private fields including data,
81  // accumulators, global range. It does not affect the fence factor (_f),
82  // which was set at object construction.
83  virtual void reset();
84 
85  // This class does not allow statistics to be calculated as datasets are
86  // added, so an exception will be thrown if <src>c</src> is True.
88 
89 protected:
90  // <group>
91  // scan through the data set to determine the number of good (unmasked,
92  // weight > 0, within range) points. The first with no mask, no ranges, and
93  // no weights is trivial with npts = nr in this class, but is implemented
94  // here so that derived classes may override it.
95  virtual void _accumNpts(
96  uInt64& npts, const DataIterator& dataStart, uInt64 nr, uInt dataStride
97  ) const;
98 
99  virtual void _accumNpts(
100  uInt64& npts, const DataIterator& dataStart, uInt64 nr, uInt dataStride,
101  const DataRanges& ranges, Bool isInclude
102  ) const;
103 
104  virtual void _accumNpts(
105  uInt64& npts, const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
106  const MaskIterator& maskBegin, uInt maskStride
107  ) const;
108 
109  virtual void _accumNpts(
110  uInt64& npts, const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
111  const MaskIterator& maskBegin, uInt maskStride,
112  const DataRanges& ranges, Bool isInclude
113  ) const;
114 
115  virtual void _accumNpts(
116  uInt64& npts, const DataIterator& dataBegin,
117  const WeightsIterator& weightsBegin, uInt64 nr, uInt dataStride
118  ) const;
119 
120  virtual void _accumNpts(
121  uInt64& npts,
122  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
123  uInt64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
124  ) const;
125 
126  virtual void _accumNpts(
127  uInt64& npts,
128  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
129  uInt64 nr, uInt dataStride, const MaskIterator& maskBegin,
130  uInt maskStride, const DataRanges& ranges, Bool isInclude
131  ) const;
132 
133  virtual void _accumNpts(
134  uInt64& npts, const DataIterator& dataBegin,
135  const WeightsIterator& weightBegin, uInt64 nr, uInt dataStride,
136  const MaskIterator& maskBegin, uInt maskStride
137  ) const;
138  // </group>
139 
140  // <group>
141  virtual void _minMax(
143  const DataIterator& dataBegin, uInt64 nr, uInt dataStride
144  ) const;
145 
146  virtual void _minMax(
148  const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
149  const DataRanges& ranges, Bool isInclude
150  ) const;
151 
152  virtual void _minMax(
154  const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
155  const MaskIterator& maskBegin, uInt maskStride
156  ) const;
157 
158  virtual void _minMax(
160  const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
161  const MaskIterator& maskBegin,
162  uInt maskStride, const DataRanges& ranges, Bool isInclude
163  ) const;
164 
165  virtual void _minMax(
167  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
168  uInt64 nr, uInt dataStride
169  ) const;
170 
171  virtual void _minMax(
173  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
174  uInt64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
175  ) const;
176 
177  virtual void _minMax(
179  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
180  uInt64 nr, uInt dataStride, const MaskIterator& maskBegin,
181  uInt maskStride, const DataRanges& ranges, Bool isInclude
182  ) const;
183 
184  virtual void _minMax(
186  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
187  uInt64 nr, uInt dataStride, const MaskIterator& maskBegin,
188  uInt maskStride
189  ) const;
190 
191  // <group>
192  // Sometimes we want the min, max, and npts all in one scan.
193  virtual void _minMaxNpts(
194  uInt64& npts, CountedPtr<AccumType>& mymin,
195  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin,
196  uInt64 nr, uInt dataStride
197  ) const;
198 
199  virtual void _minMaxNpts(
200  uInt64& npts, CountedPtr<AccumType>& mymin,
201  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin, uInt64 nr,
202  uInt dataStride, const DataRanges& ranges, Bool isInclude
203  ) const;
204 
205  virtual void _minMaxNpts(
206  uInt64& npts, CountedPtr<AccumType>& mymin,
207  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin, uInt64 nr,
208  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
209  ) const;
210 
211  virtual void _minMaxNpts(
212  uInt64& npts, CountedPtr<AccumType>& mymin,
213  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin, uInt64 nr,
214  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
215  const DataRanges& ranges, Bool isInclude
216  ) const;
217 
218  virtual void _minMaxNpts(
219  uInt64& npts, CountedPtr<AccumType>& mymin,
220  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin,
221  const WeightsIterator& weightsBegin, uInt64 nr, uInt dataStride
222  ) const;
223 
224  virtual void _minMaxNpts(
225  uInt64& npts, CountedPtr<AccumType>& mymin,
226  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin,
227  const WeightsIterator& weightsBegin, uInt64 nr, uInt dataStride,
228  const DataRanges& ranges, Bool isInclude
229  ) const;
230 
231  virtual void _minMaxNpts(
232  uInt64& npts, CountedPtr<AccumType>& mymin,
233  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin,
234  const WeightsIterator& weightsBegin, uInt64 nr, uInt dataStride,
235  const MaskIterator& maskBegin, uInt maskStride,
236  const DataRanges& ranges, Bool isInclude
237  ) const;
238 
239  virtual void _minMaxNpts(
240  uInt64& npts, CountedPtr<AccumType>& mymin,
241  CountedPtr<AccumType>& mymax, const DataIterator& dataBegin,
242  const WeightsIterator& weightBegin, uInt64 nr, uInt dataStride,
243  const MaskIterator& maskBegin, uInt maskStride
244  ) const;
245  // </group>
246 
247  // <group>
248  // no weights, no mask, no ranges
249  virtual void _unweightedStats(
250  StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
251  const DataIterator& dataBegin, uInt64 nr, uInt dataStride
252  );
253 
254  // no weights, no mask
255  virtual void _unweightedStats(
256  StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
257  const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
258  const DataRanges& ranges, Bool isInclude
259  );
260 
261  virtual void _unweightedStats(
262  StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
263  const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
264  const MaskIterator& maskBegin, uInt maskStride
265  );
266 
267  virtual void _unweightedStats(
268  StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
269  const DataIterator& dataBegin, uInt64 nr, uInt dataStride,
270  const MaskIterator& maskBegin, uInt maskStride,
271  const DataRanges& ranges, Bool isInclude
272  );
273  // </group>
274 
275  // <group>
276  // has weights, but no mask, no ranges
277  virtual void _weightedStats(
278  StatsData<AccumType>& stats, LocationType& location,
279  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
280  uInt64 nr, uInt dataStride
281  );
282 
283  virtual void _weightedStats(
284  StatsData<AccumType>& stats, LocationType& location,
285  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
286  uInt64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
287  );
288 
289  virtual void _weightedStats(
290  StatsData<AccumType>& stats, LocationType& location,
291  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
292  uInt64 nr, uInt dataStride, const MaskIterator& maskBegin,
293  uInt maskStride
294  );
295 
296  virtual void _weightedStats(
297  StatsData<AccumType>& stats, LocationType& location,
298  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
299  uInt64 nr, uInt dataStride, const MaskIterator& maskBegin,
300  uInt maskStride, const DataRanges& ranges, Bool isInclude
301  );
302  // </group>
303 
304 private:
305 
306  // _f defined in inclusion range between Q1 - _f*D and Q3 + _f*D, where
307  // D = Q3 - Q1 and Q1 and Q3 are the first and third quartiles, respectively
310 
311  void _setRange();
312 
313 };
314 
315 }
316 
317 #ifndef CASACORE_NO_AUTO_TEMPLATES
318 #include <casacore/scimath/StatsFramework/HingesFencesStatistics.tcc>
319 #endif //# CASACORE_NO_AUTO_TEMPLATES
320 
321 #endif
Class to calculate statistics using the so-called hinges and fences algorithm.
virtual void _minMax(CountedPtr< AccumType > &mymin, CountedPtr< AccumType > &mymax, const DataIterator &dataBegin, uInt64 nr, uInt dataStride) const
virtual StatisticsAlgorithm< CASA_STATP > * clone() const
Clone this instance.
unsigned long long uInt64
Definition: aipsxtype.h:39
HingesFencesStatistics(Double f=-1.0)
If f is negative, the full dataset is used; ie the object has the same behavior as a ClassicalStatist...
virtual void reset()
reset object to initial state.
ALGORITHM
implemented algorithms
HingesFencesStatistics< CASA_STATP > & operator=(const HingesFencesStatistics< CASA_STATP > &other)
copy semantics
std::pair< Int64, Int64 > LocationType
double Double
Definition: aipstype.h:55
#define DataRanges
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Abstract base class for statistics algorithms which are characterized by a range of good values...
const Bool False
Definition: aipstype.h:44
void _setRange()
derived classes need to implement how to set their respective range
Double _f
_f defined in inclusion range between Q1 - _f*D and Q3 + _f*D, where D = Q3 - Q1 and Q1 and Q3 are t...
void setCalculateAsAdded(Bool c)
This class does not allow statistics to be calculated as datasets are added, so an exception will be ...
virtual void _weightedStats(StatsData< AccumType > &stats, LocationType &location, const DataIterator &dataBegin, const WeightsIterator &weightsBegin, uInt64 nr, uInt dataStride)
has weights, but no mask, no ranges
const Double c
Fundamental physical constants (SI units):
virtual void _minMaxNpts(uInt64 &npts, CountedPtr< AccumType > &mymin, CountedPtr< AccumType > &mymax, const DataIterator &dataBegin, uInt64 nr, uInt dataStride) const
Sometimes we want the min, max, and npts all in one scan.
virtual void _accumNpts(uInt64 &npts, const DataIterator &dataStart, uInt64 nr, uInt dataStride) const
scan through the data set to determine the number of good (unmasked, weight &gt; 0, within range) points...
virtual StatisticsData::ALGORITHM algorithm() const
get the algorithm that this object uses for computing stats
virtual void _unweightedStats(StatsData< AccumType > &stats, uInt64 &ngood, LocationType &location, const DataIterator &dataBegin, uInt64 nr, uInt dataStride)
no weights, no mask, no ranges
unsigned int uInt
Definition: aipstype.h:51