casacore
ConstrainedRangeStatistics.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 //# $Id: Array.h 21545 2015-01-22 19:36:35Z gervandiepen $
26 
27 #ifndef SCIMATH_CONSTRAINEDRANGESTATISTICS_H
28 #define SCIMATH_CONSTRAINEDRANGESTATISTICS_H
29 
30 #include <casacore/casa/aips.h>
31 
32 #include <casacore/scimath/Mathematics/ClassicalStatistics.h>
33 
34 #include <set>
35 #include <vector>
36 #include <utility>
37 
38 namespace casacore {
39 
40 // Abstract base class for statistics algorithms which are characterized by
41 // a range of good values. The range is usually calculated dynamically based on the entire distribution.
42 
43 template <class AccumType, class DataIterator, class MaskIterator=const Bool*, class WeightsIterator=DataIterator>
45  : public ClassicalStatistics<CASA_STATP> {
46 public:
47 
49 
50  // copy semantics
53  );
54 
55  // <group>
56  // In the following group of methods, if the size of the composite dataset
57  // is smaller than
58  // <src>binningThreshholdSizeBytes</src>, the composite dataset
59  // will be (perhaps partially) sorted and persisted in memory during the
60  // call. In that case, and if <src>persistSortedArray</src> is True, this
61  // sorted array will remain in memory after the call and will be used on
62  // subsequent calls of this method when <src>binningThreshholdSizeBytes</src>
63  // is greater than the size of the composite dataset. If
64  // <src>persistSortedArray</src> is False, the sorted array will not be
65  // stored after this call completes and so any subsequent calls for which the
66  // dataset size is less than <src>binningThreshholdSizeBytes</src>, the
67  // dataset will be sorted from scratch. Values which are not included due to
68  // non-unity strides, are not included in any specified ranges, are masked,
69  // or have associated weights of zero are not considered as dataset members
70  // for quantile computations.
71  // If one has a priori information regarding
72  // the number of points (npts) and/or the minimum and maximum values of the data
73  // set, these can be supplied to improve performance. Note however, that if these
74  // values are not correct, the resulting median
75  // and/or quantile values will also not be correct (although see the following notes regarding
76  // max/min). Note that if this object has already had getStatistics()
77  // called, and the min and max were calculated, there is no need to pass these values in
78  // as they have been stored internally and used (although passing them in shouldn't hurt
79  // anything). If provided, npts, the number of points falling in the specified ranges which are
80  // not masked and have weights > 0, should be exactly correct. <src>min</src> can be less than
81  // the true minimum, and <src>max</src> can be greater than the True maximum, but for best
82  // performance, these should be as close to the actual min and max as possible.
83  // In order for quantile computations to occur over multiple datasets, all datasets
84  // must be available. This means that if setCalculateAsAdded()
85  // was previously called by passing in a value of True, these methods will throw
86  // an exception as the previous call indicates that there is no guarantee that
87  // all datasets will be available. If one uses a data provider (by having called
88  // setDataProvider()), then this should not be an issue.
89 
90  // get the median of the distribution.
91  // For a dataset with an odd number of good points, the median is just the value
92  // at index int(N/2) in the equivalent sorted dataset, where N is the number of points.
93  // For a dataset with an even number of points, the median is the mean of the values at
94  // indices int(N/2)-1 and int(N/2) in the sorted dataset.
95  AccumType getMedian(
96  CountedPtr<uInt64> knownNpts=NULL, CountedPtr<AccumType> knownMin=NULL,
97  CountedPtr<AccumType> knownMax=NULL, uInt binningThreshholdSizeBytes=4096*4096,
98  Bool persistSortedArray=False, uInt64 nBins=10000
99  );
100 
101  // get the median of the absolute deviation about the median of the data.
102  AccumType getMedianAbsDevMed(
103  CountedPtr<uInt64> knownNpts=NULL,
104  CountedPtr<AccumType> knownMin=NULL, CountedPtr<AccumType> knownMax=NULL,
105  uInt binningThreshholdSizeBytes=4096*4096, Bool persistSortedArray=False,
106  uInt64 nBins=10000
107  );
108 
109  // If one needs to compute both the median and quantile values, it is better to call
110  // getMedianAndQuantiles() rather than getMedian() and getQuantiles() seperately, as the
111  // first will scan large data sets fewer times than calling the seperate methods.
112  // The return value is the median; the quantiles are returned in the <src>quantileToValue</src> map.
113  AccumType getMedianAndQuantiles(
114  std::map<Double, AccumType>& quantileToValue, const std::set<Double>& quantiles,
115  CountedPtr<uInt64> knownNpts=NULL, CountedPtr<AccumType> knownMin=NULL,
116  CountedPtr<AccumType> knownMax=NULL,
117  uInt binningThreshholdSizeBytes=4096*4096, Bool persistSortedArray=False,
118  uInt64 nBins=10000
119  );
120 
121  // Get the specified quantiles. <src>quantiles</src> must be between 0 and 1,
122  // noninclusive.
123  std::map<Double, AccumType> getQuantiles(
124  const std::set<Double>& quantiles, CountedPtr<uInt64> knownNpts=NULL,
125  CountedPtr<AccumType> knownMin=NULL, CountedPtr<AccumType> knownMax=NULL,
126  uInt binningThreshholdSizeBytes=4096*4096, Bool persistSortedArray=False,
127  uInt64 nBins=10000
128  );
129  // </group>
130 
131  // get the min and max of the data set
132  virtual void getMinMax(AccumType& mymin, AccumType& mymax);
133 
134  // scan the dataset(s) that have been added, and find the number of good points.
135  // This method may be called even if setStatsToCaclulate has been called and
136  // NPTS has been excluded. If setCalculateAsAdded(True) has previously been
137  // called after this object has been (re)initialized, an exception will be thrown.
138  virtual uInt64 getNPts();
139 
140  // see base class description
141  std::pair<Int64, Int64> getStatisticIndex(StatisticsData::STATS stat);
142 
143  // reset object to initial state. Clears all private fields including data,
144  // accumulators, global range. It does not affect the fence factor (_f), which was
145  // set at object construction.
146  virtual void reset();
147 
148 protected:
149 
151 
152  // <group>
153  // scan through the data set to determine the number of good (unmasked, weight > 0,
154  // within range) points. The first with no mask, no
155  // ranges, and no weights is trivial with npts = nr in this class, but is implemented here
156  // so that derived classes may override it.
157  inline void _accumNpts(
158  uInt64& npts,
159  const DataIterator& dataStart, Int64 nr, uInt dataStride
160  ) const;
161 
162  void _accumNpts(
163  uInt64& npts,
164  const DataIterator& dataStart, Int64 nr, uInt dataStride,
165  const DataRanges& ranges, Bool isInclude
166  ) const;
167 
168  void _accumNpts(
169  uInt64& npts,
170  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
171  const MaskIterator& maskBegin, uInt maskStride
172  ) const;
173 
174  void _accumNpts(
175  uInt64& npts,
176  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
177  const MaskIterator& maskBegin, uInt maskStride, const DataRanges& ranges,
178  Bool isInclude
179  ) const;
180 
181  void _accumNpts(
182  uInt64& npts,
183  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
184  Int64 nr, uInt dataStride
185  ) const;
186 
187  void _accumNpts(
188  uInt64& npts,
189  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
190  Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
191  ) const;
192 
193  void _accumNpts(
194  uInt64& npts,
195  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
196  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
197  const DataRanges& ranges, Bool isInclude
198  ) const;
199 
200  void _accumNpts(
201  uInt64& npts,
202  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
203  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
204  ) const;
205  // </group>
206 
207  virtual void _findBins(
208  vector<vector<uInt64> >& binCounts,
209  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
210  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
211  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc,
212  const vector<AccumType>& maxLimit
213  ) const;
214 
215  virtual void _findBins(
216  vector<vector<uInt64> >& binCounts,
217  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
218  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
219  const DataRanges& ranges, Bool isInclude,
220  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
221  ) const;
222 
223  virtual void _findBins(
224  vector<vector<uInt64> >& binCounts,
225  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
226  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
227  const MaskIterator& maskBegin, uInt maskStride,
228  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
229  ) const;
230 
231  virtual void _findBins(
232  vector<vector<uInt64> >& binCounts,
233  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
234  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
235  const MaskIterator& maskBegin, uInt maskStride, const DataRanges& ranges,
236  Bool isInclude,
237  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
238  ) const;
239 
240  virtual void _findBins(
241  vector<vector<uInt64> >& binCounts,
242  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
243  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
244  Int64 nr, uInt dataStride,
245  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
246  ) const ;
247 
248  virtual void _findBins(
249  vector<vector<uInt64> >& binCounts,
250  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
251  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
252  Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude,
253  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
254  ) const;
255 
256  virtual void _findBins(
257  vector<vector<uInt64> >& binCounts,
258  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
259  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
260  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
261  const DataRanges& ranges, Bool isInclude,
262  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
263  ) const;
264 
265  virtual void _findBins(
266  vector<vector<uInt64> >& binCounts,
267  vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
268  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
269  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
270  const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
271  ) const;
272  // </group>
273 
274  AccumType _getStatistic(StatisticsData::STATS stat);
275 
277 
278  inline Bool _isInRange(const AccumType& datum) const;
279 
280  // <group>
281  virtual void _minMax(
283  const DataIterator& dataBegin, Int64 nr, uInt dataStride
284  ) const;
285 
286  virtual void _minMax(
288  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
289  const DataRanges& ranges, Bool isInclude
290  ) const;
291 
292  virtual void _minMax(
294  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
295  const MaskIterator& maskBegin, uInt maskStride
296  ) const;
297 
298  virtual void _minMax(
300  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
301  const MaskIterator& maskBegin, uInt maskStride, const DataRanges& ranges,
302  Bool isInclude
303  ) const;
304 
305  virtual void _minMax(
307  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
308  Int64 nr, uInt dataStride
309  ) const;
310 
311  virtual void _minMax(
313  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
314  Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
315  ) const;
316 
317  virtual void _minMax(
319  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
320  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
321  const DataRanges& ranges, Bool isInclude
322  ) const;
323 
324  virtual void _minMax(
326  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
327  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
328  ) const;
329  // </group>
330 
331  //<group>
332  // populate an unsorted array with valid data. If <src>includeLimits</src> is defined,
333  // then restrict values that are entered in the array to those limits (inclusive of the
334  // minimum, exclusive of the maximum). <src>maxCount</src> and <src>currentCount</src> are
335  // used only if <src>includeLimits</src> is defined. In this case, the method will return
336  // when currentCount == maxCount, thus avoiding scanning remaining data unnecessarily.
337 
338  // no weights, no mask, no ranges
339  void _populateArray(
340  vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr, uInt dataStride
341  ) const;
342 
343  // ranges
344  void _populateArray(
345  vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
346  uInt dataStride, const DataRanges& ranges, Bool isInclude
347  ) const;
348 
349  void _populateArray(
350  vector<AccumType>& ary, const DataIterator& dataBegin,
351  Int64 nr, uInt dataStride, const MaskIterator& maskBegin,
352  uInt maskStride
353  ) const;
354 
355  // mask and ranges
356  void _populateArray(
357  vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
358  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
359  const DataRanges& ranges, Bool isInclude
360  ) const;
361 
362  // weights
363  void _populateArray(
364  vector<AccumType>& ary, const DataIterator& dataBegin,
365  const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride
366  ) const;
367 
368  // weights and ranges
369  void _populateArray(
370  vector<AccumType>& ary, const DataIterator& dataBegin,
371  const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
372  const DataRanges& ranges, Bool isInclude
373  ) const;
374 
375  // weights and mask
376  void _populateArray(
377  vector<AccumType>& ary, const DataIterator& dataBegin,
378  const WeightsIterator& weightBegin, Int64 nr, uInt dataStride,
379  const MaskIterator& maskBegin, uInt maskStride
380  ) const;
381 
382  // weights, mask, ranges
383  void _populateArray(
384  vector<AccumType>& ary, const DataIterator& dataBegin, const WeightsIterator& weightBegin,
385  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
386  const DataRanges& ranges, Bool isInclude
387  ) const;
388 
389  // no weights, no mask, no ranges
390  virtual void _populateArrays(
391  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, Int64 nr, uInt dataStride,
392  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
393  ) const;
394 
395  // ranges
396  virtual void _populateArrays(
397  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, Int64 nr,
398  uInt dataStride, const DataRanges& ranges, Bool isInclude,
399  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
400  ) const;
401 
402  virtual void _populateArrays(
403  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
404  Int64 nr, uInt dataStride, const MaskIterator& maskBegin,
405  uInt maskStride,
406  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
407  ) const;
408 
409  // mask and ranges
410  virtual void _populateArrays(
411  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, Int64 nr,
412  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
413  const DataRanges& ranges, Bool isInclude,
414  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
415  ) const;
416 
417  // weights
418  virtual void _populateArrays(
419  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
420  const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
421  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
422  ) const;
423 
424  // weights and ranges
425  virtual void _populateArrays(
426  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
427  const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
428  const DataRanges& ranges, Bool isInclude,
429  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
430  ) const;
431 
432  // weights and mask
433  virtual void _populateArrays(
434  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
435  const WeightsIterator& weightBegin, Int64 nr, uInt dataStride,
436  const MaskIterator& maskBegin, uInt maskStride,
437  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
438  ) const;
439 
440  // weights, mask, ranges
441  virtual void _populateArrays(
442  vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, const WeightsIterator& weightBegin,
443  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
444  const DataRanges& ranges, Bool isInclude,
445  const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
446  ) const;
447  // </group>
448 
449  // <group>
450  // no weights, no mask, no ranges
452  vector<AccumType>& ary, const DataIterator& dataBegin,
453  Int64 nr, uInt dataStride, uInt maxElements
454  ) const;
455 
456  // ranges
458  vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
459  uInt dataStride, const DataRanges& ranges, Bool isInclude,
460  uInt maxElements
461  ) const;
462 
463  // mask
465  vector<AccumType>& ary, const DataIterator& dataBegin,
466  Int64 nr, uInt dataStride, const MaskIterator& maskBegin,
467  uInt maskStride, uInt maxElements
468  ) const;
469 
470  // mask and ranges
472  vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
473  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
474  const DataRanges& ranges, Bool isInclude, uInt maxElements
475  ) const;
476 
477  // weights
479  vector<AccumType>& ary, const DataIterator& dataBegin,
480  const WeightsIterator& weightBegin, Int64 nr, uInt dataStride,
481  uInt maxElements
482  ) const;
483 
484  // weights and ranges
486  vector<AccumType>& ary, const DataIterator& dataBegin,
487  const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
488  const DataRanges& ranges, Bool isInclude, uInt maxElements
489  ) const;
490 
491  // weights and mask
493  vector<AccumType>& ary, const DataIterator& dataBegin,
494  const WeightsIterator& weightBegin, Int64 nr,
495  uInt dataStride, const MaskIterator& maskBegin,
496  uInt maskStride, uInt maxElements
497  ) const;
498 
499  // weights, mask, ranges
501  vector<AccumType>& ary, const DataIterator& dataBegin, const WeightsIterator& weightBegin,
502  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
503  const DataRanges& ranges, Bool isInclude,
504  uInt maxElements
505  ) const;
506  // </group>
507 
508  inline void _setRange(CountedPtr<std::pair<AccumType, AccumType> > r) { this->_clearStats(); _range = r; }
509 
510  // derived classes need to implement how to set their respective range
511  virtual void _setRange() = 0;
512 /*
513  // <group>
514  // no weights, no mask, no ranges
515  void _unweightedStats(
516  StatsData<AccumType>& stats, uInt64& ngood, AccumType& mymin,
517  AccumType& mymax, Int64& minpos, Int64& maxpos,
518  const DataIterator& dataBegin, Int64 nr, uInt dataStride
519  );
520 
521  // no weights, no mask
522  void _unweightedStats(
523  StatsData<AccumType>& stats, uInt64& ngood, AccumType& mymin,
524  AccumType& mymax, Int64& minpos, Int64& maxpos,
525  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
526  const DataRanges& ranges, Bool isInclude
527  );
528 
529  void _unweightedStats(
530  StatsData<AccumType>& stats, uInt64& ngood, AccumType& mymin,
531  AccumType& mymax, Int64& minpos, Int64& maxpos,
532  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
533  const MaskIterator& maskBegin, uInt maskStride
534  );
535 
536  void _unweightedStats(
537  StatsData<AccumType>& stats, uInt64& ngood, AccumType& mymin,
538  AccumType& mymax, Int64& minpos, Int64& maxpos,
539  const DataIterator& dataBegin, Int64 nr, uInt dataStride,
540  const MaskIterator& maskBegin, uInt maskStride,
541  const DataRanges& ranges, Bool isInclude
542  );
543  // </group>
544 
545  // <group>
546  // has weights, but no mask, no ranges
547  void _weightedStats(
548  StatsData<AccumType>& stats, AccumType& mymin, AccumType& mymax,
549  Int64& minpos, Int64& maxpos,
550  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
551  Int64 nr, uInt dataStride
552  );
553 
554  void _weightedStats(
555  StatsData<AccumType>& stats, AccumType& mymin, AccumType& mymax,
556  Int64& minpos, Int64& maxpos,
557  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
558  Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
559  );
560 
561  void _weightedStats(
562  StatsData<AccumType>& stats, AccumType& mymin, AccumType& mymax,
563  Int64& minpos, Int64& maxpos,
564  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
565  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
566  );
567 
568  void _weightedStats(
569  StatsData<AccumType>& stats, AccumType& mymin, AccumType& mymax,
570  Int64& minpos, Int64& maxpos,
571  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
572  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
573  const DataRanges& ranges, Bool isInclude
574  );
575  // </group>
576 */
577 
578  // <group>
579  // no weights, no mask, no ranges
580  void _unweightedStats(
581  StatsData<AccumType>& stats, uInt64& ngood, /* AccumType& mymin,
582  AccumType& mymax, LocationType& minpos, LocationType& maxpos, */
583  LocationType& location, const DataIterator& dataBegin, Int64 nr,
584  uInt dataStride
585  );
586 
587  // no weights, no mask
588  void _unweightedStats(
589  StatsData<AccumType>& stats, uInt64& ngood, /* AccumType& mymin,
590  AccumType& mymax, LocationType& minpos, LocationType& maxpos, */
591  LocationType& location, const DataIterator& dataBegin, Int64 nr,
592  uInt dataStride, const DataRanges& ranges, Bool isInclude
593  );
594 
595  void _unweightedStats(
596  StatsData<AccumType>& stats, uInt64& ngood, /* AccumType& mymin,
597  AccumType& mymax, LocationType& minpos, LocationType& maxpos, */
598  LocationType& location, const DataIterator& dataBegin, Int64 nr,
599  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
600  );
601 
602  void _unweightedStats(
603  StatsData<AccumType>& stats, uInt64& ngood, /* AccumType& mymin,
604  AccumType& mymax, LocationType& minpos, LocationType& maxpos, */
605  LocationType& location, const DataIterator& dataBegin, Int64 nr,
606  uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
607  const DataRanges& ranges, Bool isInclude
608  );
609  // </group>
610 
611  // <group>
612  // has weights, but no mask, no ranges
613  void _weightedStats(
614  StatsData<AccumType>& stats, /* AccumType& mymin, AccumType& mymax,
615  LocationType& minpos, LocationType& maxpos, */LocationType& location,
616  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
617  Int64 nr, uInt dataStride
618  );
619 
620  void _weightedStats(
621  StatsData<AccumType>& stats, /* AccumType& mymin, AccumType& mymax,
622  LocationType& minpos, LocationType& maxpos, */ LocationType& location,
623  const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
624  Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
625  );
626 
627  void _weightedStats(
628  StatsData<AccumType>& stats, /* AccumType& mymin, AccumType& mymax,
629  LocationType& minpos, LocationType& maxpos, */ LocationType& location,
630  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
631  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
632  );
633 
634  void _weightedStats(
635  StatsData<AccumType>& stats, /* AccumType& mymin, AccumType& mymax,
636  LocationType& minpos, LocationType& maxpos, */ LocationType& location,
637  const DataIterator& dataBegin, const WeightsIterator& weightBegin,
638  Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
639  const DataRanges& ranges, Bool isInclude
640  );
641  // </group>
642 
643 private:
646 
647 };
648 
649 }
650 
651 #ifndef CASACORE_NO_AUTO_TEMPLATES
652 #include <casacore/scimath/Mathematics/ConstrainedRangeStatistics.tcc>
653 #endif
654 
655 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
AccumType getMedian(CountedPtr< uInt64 > knownNpts=NULL, CountedPtr< AccumType > knownMin=NULL, CountedPtr< AccumType > knownMax=NULL, uInt binningThreshholdSizeBytes=4096 *4096, Bool persistSortedArray=False, uInt64 nBins=10000)
In the following group of methods, if the size of the composite dataset is smaller than binningThresh...
void _setRange(CountedPtr< std::pair< AccumType, AccumType > > r)
CASA_STATP _getStatistic(StatisticsData::STATS stat)
virtual void _minMax(CountedPtr< CASA_STATP > &mymin, CountedPtr< CASA_STATP > &mymax, const DataIterator &dataBegin, Int64 nr, uInt dataStride) const
StatsData< CASA_STATP > _getStatistics()
unsigned long long uInt64
Definition: aipsxtype.h:39
std::pair< Int64, Int64 > LocationType
void _accumNpts(uInt64 &npts, const DataIterator &dataStart, Int64 nr, uInt dataStride) const
scan through the data set to determine the number of good (unmasked, weight > 0, within range) points...
Class to calculate statistics in a "classical" sense, ie using accumulators with no special filtering...
std::map< Double, AccumType > getQuantiles(const std::set< Double > &quantiles, CountedPtr< uInt64 > knownNpts=NULL, CountedPtr< AccumType > knownMin=NULL, CountedPtr< AccumType > knownMax=NULL, uInt binningThreshholdSizeBytes=4096 *4096, Bool persistSortedArray=False, uInt64 nBins=10000)
Get the specified quantiles.
CountedPtr< std::pair< AccumType, AccumType > > _range
virtual void _populateArrays(vector< vector< CASA_STATP > > &arys, uInt64 &currentCount, const DataIterator &dataBegin, Int64 nr, uInt dataStride, const vector< std::pair< CASA_STATP, CASA_STATP > > &includeLimits, uInt64 maxCount) const
Create a vector of unsorted arrays, one array for each bin defined by includeLimits.
AccumType getMedianAbsDevMed(CountedPtr< uInt64 > knownNpts=NULL, CountedPtr< AccumType > knownMin=NULL, CountedPtr< AccumType > knownMax=NULL, uInt binningThreshholdSizeBytes=4096 *4096, Bool persistSortedArray=False, uInt64 nBins=10000)
get the median of the absolute deviation about the median of the data.
virtual uInt64 getNPts()
scan the dataset(s) that have been added, and find the number of good points.
Referenced counted pointer for constant data.
Definition: CountedPtr.h:86
ConstrainedRangeStatistics< CASA_STATP > & operator=(const ConstrainedRangeStatistics< CASA_STATP > &other)
copy semantics
#define DataRanges
Commonly used types in statistics framework.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual Bool _populateTestArray(vector< CASA_STATP > &ary, const DataIterator &dataBegin, Int64 nr, uInt dataStride, uInt maxElements) const
no weights, no mask, no ranges
virtual void reset()
reset object to initial state.
Abstract base class for statistics algorithms which are characterized by a range of good values...
const Bool False
Definition: aipstype.h:44
virtual void _unweightedStats(StatsData< CASA_STATP > &stats, uInt64 &ngood, LocationType &location, const DataIterator &dataBegin, Int64 nr, uInt dataStride)
no weights, no mask, no ranges
Bool _isInRange(const AccumType &datum) const
std::pair< Int64, Int64 > getStatisticIndex(StatisticsData::STATS stat)
see base class description
virtual void _weightedStats(StatsData< CASA_STATP > &stats, LocationType &location, const DataIterator &dataBegin, const DataIterator &weightsBegin, Int64 nr, uInt dataStride)
has weights, but no mask, no ranges
AccumType getMedianAndQuantiles(std::map< Double, AccumType > &quantileToValue, const std::set< Double > &quantiles, CountedPtr< uInt64 > knownNpts=NULL, CountedPtr< AccumType > knownMin=NULL, CountedPtr< AccumType > knownMax=NULL, uInt binningThreshholdSizeBytes=4096 *4096, Bool persistSortedArray=False, uInt64 nBins=10000)
If one needs to compute both the median and quantile values, it is better to call getMedianAndQuantil...
virtual void _populateArray(vector< CASA_STATP > &ary, const DataIterator &dataBegin, Int64 nr, uInt dataStride) const
populate an unsorted array with valid data.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
virtual void getMinMax(AccumType &mymin, AccumType &mymax)
get the min and max of the data set
virtual void _findBins(vector< vector< uInt64 > > &binCounts, vector< CountedPtr< AccumType > > &sameVal, vector< Bool > &allSame, const DataIterator &dataBegin, Int64 nr, uInt dataStride, const vector< typename StatisticsUtilities< AccumType >::BinDesc > &binDesc, const vector< AccumType > &maxLimit) const
unsigned int uInt
Definition: aipstype.h:51
description of a regularly spaced bins with the first bin having lower limit of minLimit and having n...