HingesFencesStatistics.h

Go to the documentation of this file.
00001 //# Copyright (C) 2000,2001
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 //# $Id: Array.h 21545 2015-01-22 19:36:35Z gervandiepen $
00026 
00027 #ifndef SCIMATH_HINGESFENCESSTATISTICS_H
00028 #define SCIMATH_HINGESFENCESSTATISTICS_H
00029 
00030 #include <casacore/casa/aips.h>
00031 
00032 #include <casacore/scimath/Mathematics/ConstrainedRangeStatistics.h>
00033 
00034 #include <set>
00035 #include <vector>
00036 #include <utility>
00037 
00038 namespace casacore {
00039 
00040 // Class to calculate statistics using the so-called hinges and fences algorithm. In this
00041 // algorithm, the data on which the statistics are computed from is limited to the range
00042 // of values between Q1 - f*D and Q3 + f*D, inclusive, where D = Q3 - Q1 and Q1 and Q3 are
00043 // the first and third quartiles, respectively.
00044 
00045 template <class AccumType, class DataIterator, class MaskIterator=const Bool *, class WeightsIterator=DataIterator>
00046 class HingesFencesStatistics
00047     : public ConstrainedRangeStatistics<CASA_STATP> {
00048 public:
00049 
00050     // If <src>f</src> is negative, the full dataset is used; ie the object has the same
00051     // behavior as a ClassicalStatistics object
00052     HingesFencesStatistics(Double f=-1.0);
00053 
00054     virtual ~HingesFencesStatistics();
00055 
00056     // copy semantics
00057     HingesFencesStatistics<CASA_STATP>& operator=(
00058         const HingesFencesStatistics<CASA_STATP>& other
00059     );
00060 
00061     // get the algorithm that this object uses for computing stats
00062     virtual StatisticsData::ALGORITHM algorithm() const {
00063         return StatisticsData::HINGESFENCES;
00064     };
00065 
00066     // reset object to initial state. Clears all private fields including data,
00067     // accumulators, global range. It does not affect the fence factor (_f), which was
00068     // set at object construction.
00069     virtual void reset();
00070 
00071     // This class does not allow statistics to be calculated as datasets are added, so
00072     // an exception will be thrown if <src>c</src> is True.
00073     void setCalculateAsAdded(Bool c);
00074 
00075 protected:
00076     // <group>
00077     // scan through the data set to determine the number of good (unmasked, weight > 0,
00078     // within range) points. The first with no mask, no
00079     // ranges, and no weights is trivial with npts = nr in this class, but is implemented here
00080     // so that derived classes may override it.
00081     inline void _accumNpts(
00082         uInt64& npts,
00083         const DataIterator& dataStart, Int64 nr, uInt dataStride
00084     ) const;
00085 
00086     void _accumNpts(
00087         uInt64& npts,
00088         const DataIterator& dataStart, Int64 nr, uInt dataStride,
00089         const DataRanges& ranges, Bool isInclude
00090     ) const;
00091 
00092     void _accumNpts(
00093         uInt64& npts,
00094         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00095         const MaskIterator& maskBegin, uInt maskStride
00096     ) const;
00097 
00098     void _accumNpts(
00099         uInt64& npts,
00100         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00101         const MaskIterator& maskBegin, uInt maskStride, const DataRanges& ranges,
00102         Bool isInclude
00103     ) const;
00104 
00105     void _accumNpts(
00106         uInt64& npts,
00107         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00108         Int64 nr, uInt dataStride
00109     ) const;
00110 
00111     void _accumNpts(
00112         uInt64& npts,
00113         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00114         Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
00115     ) const;
00116 
00117     void _accumNpts(
00118         uInt64& npts,
00119         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00120         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00121         const DataRanges& ranges, Bool isInclude
00122     ) const;
00123 
00124     void _accumNpts(
00125         uInt64& npts,
00126         const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00127         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
00128     ) const;
00129     // </group>
00130 
00131     // <group>
00132     virtual void _findBins(
00133         vector<vector<uInt64> >& binCounts,
00134         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00135         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00136         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc,
00137         const vector<AccumType>& maxLimit
00138     ) const;
00139 
00140     virtual void _findBins(
00141         vector<vector<uInt64> >& binCounts,
00142         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00143         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00144         const DataRanges& ranges, Bool isInclude,
00145         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00146     ) const;
00147 
00148     virtual void _findBins(
00149         vector<vector<uInt64> >& binCounts,
00150         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00151         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00152         const MaskIterator& maskBegin, uInt maskStride,
00153         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00154     ) const;
00155 
00156     virtual void _findBins(
00157         vector<vector<uInt64> >& binCounts,
00158         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00159         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00160         const MaskIterator& maskBegin, uInt maskStride, const DataRanges& ranges,
00161         Bool isInclude,
00162         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00163     ) const;
00164 
00165     virtual void _findBins(
00166         vector<vector<uInt64> >& binCounts,
00167         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00168         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00169         Int64 nr, uInt dataStride,
00170         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00171     ) const ;
00172 
00173     virtual void _findBins(
00174         vector<vector<uInt64> >& binCounts,
00175         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00176         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00177         Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude,
00178         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00179     ) const;
00180 
00181     virtual void _findBins(
00182         vector<vector<uInt64> >& binCounts,
00183         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00184         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00185         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00186         const DataRanges& ranges, Bool isInclude,
00187         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00188     ) const;
00189 
00190     virtual void _findBins(
00191         vector<vector<uInt64> >& binCounts,
00192         vector<CountedPtr<AccumType> >& sameVal, vector<Bool>& allSame,
00193         const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00194         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00195         const vector<typename StatisticsUtilities<AccumType>::BinDesc>& binDesc, const vector<AccumType>& maxLimit
00196     ) const;
00197     // </group>
00198 
00199     // <group>
00200     virtual void _minMax(
00201         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00202         const DataIterator& dataBegin, Int64 nr, uInt dataStride
00203     ) const;
00204 
00205     virtual void _minMax(
00206         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00207         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00208         const DataRanges& ranges, Bool isInclude
00209     ) const;
00210 
00211     virtual void _minMax(
00212         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00213         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00214         const MaskIterator& maskBegin, uInt maskStride
00215     ) const;
00216 
00217     virtual void _minMax(
00218         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00219         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00220         const MaskIterator& maskBegin, uInt maskStride, const DataRanges& ranges,
00221         Bool isInclude
00222     ) const;
00223 
00224     virtual void _minMax(
00225         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00226         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00227         Int64 nr, uInt dataStride
00228     ) const;
00229 
00230     virtual void _minMax(
00231         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00232         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00233         Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
00234     ) const;
00235 
00236     virtual void _minMax(
00237         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00238         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00239         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00240         const DataRanges& ranges, Bool isInclude
00241     ) const;
00242 
00243     virtual void _minMax(
00244         CountedPtr<AccumType>& mymin, CountedPtr<AccumType>& mymax,
00245         const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00246         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
00247     ) const;
00248     // </group>
00249 
00250     //<group>
00251     // populate an unsorted array with valid data. If <src>includeLimits</src> is defined,
00252     // then restrict values that are entered in the array to those limits (inclusive of the
00253     // minimum, exclusive of the maximum). <src>maxCount</src> and <src>currentCount</src> are
00254     // used only if <src>includeLimits</src> is defined. In this case, the method will return
00255     // when currentCount == maxCount, thus avoiding scanning remaining data unnecessarily.
00256 
00257     // no weights, no mask, no ranges
00258     void _populateArray(
00259         vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr, uInt dataStride
00260     ) const;
00261 
00262     // ranges
00263     void _populateArray(
00264         vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
00265         uInt dataStride, const DataRanges& ranges, Bool isInclude
00266     ) const;
00267 
00268     void _populateArray(
00269         vector<AccumType>& ary, const DataIterator& dataBegin,
00270         Int64 nr, uInt dataStride, const MaskIterator& maskBegin,
00271         uInt maskStride
00272     ) const;
00273 
00274     // mask and ranges
00275     void _populateArray(
00276         vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
00277         uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00278         const DataRanges& ranges, Bool isInclude
00279     ) const;
00280 
00281     // weights
00282     void _populateArray(
00283         vector<AccumType>& ary, const DataIterator& dataBegin,
00284         const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride
00285     ) const;
00286 
00287     // weights and ranges
00288     void _populateArray(
00289         vector<AccumType>& ary, const DataIterator& dataBegin,
00290         const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
00291         const DataRanges& ranges, Bool isInclude
00292     ) const;
00293 
00294     // weights and mask
00295     void _populateArray(
00296         vector<AccumType>& ary, const DataIterator& dataBegin,
00297         const WeightsIterator& weightBegin, Int64 nr, uInt dataStride,
00298         const MaskIterator& maskBegin, uInt maskStride
00299     ) const;
00300 
00301     // weights, mask, ranges
00302     void _populateArray(
00303         vector<AccumType>& ary, const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00304         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00305         const DataRanges& ranges, Bool isInclude
00306     ) const;
00307 
00308     // no weights, no mask, no ranges
00309     virtual void _populateArrays(
00310         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00311         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00312     ) const;
00313 
00314     // ranges
00315     virtual void _populateArrays(
00316         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, Int64 nr,
00317         uInt dataStride, const DataRanges& ranges, Bool isInclude,
00318         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00319     ) const;
00320 
00321     virtual void _populateArrays(
00322         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
00323         Int64 nr, uInt dataStride, const MaskIterator& maskBegin,
00324         uInt maskStride,
00325         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00326     ) const;
00327 
00328     // mask and ranges
00329     virtual void _populateArrays(
00330         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, Int64 nr,
00331         uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00332         const DataRanges& ranges, Bool isInclude,
00333         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00334     ) const;
00335 
00336     // weights
00337     virtual void _populateArrays(
00338         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
00339         const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
00340         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00341     ) const;
00342 
00343     // weights and ranges
00344     virtual void _populateArrays(
00345         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
00346         const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
00347         const DataRanges& ranges, Bool isInclude,
00348         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00349     ) const;
00350 
00351     // weights and mask
00352     virtual void _populateArrays(
00353         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin,
00354         const WeightsIterator& weightBegin, Int64 nr, uInt dataStride,
00355         const MaskIterator& maskBegin, uInt maskStride,
00356         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00357     ) const;
00358 
00359     // weights, mask, ranges
00360     virtual void _populateArrays(
00361         vector<vector<AccumType> >& arys, uInt64& currentCount, const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00362         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00363         const DataRanges& ranges, Bool isInclude,
00364         const vector<std::pair<AccumType, AccumType> > &includeLimits, uInt64 maxCount
00365     ) const;
00366     // </group>
00367 
00368     // <group>
00369     // no weights, no mask, no ranges
00370     Bool _populateTestArray(
00371         vector<AccumType>& ary, const DataIterator& dataBegin,
00372         Int64 nr, uInt dataStride, uInt maxElements
00373     ) const;
00374 
00375     // ranges
00376     Bool _populateTestArray(
00377         vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
00378         uInt dataStride, const DataRanges& ranges, Bool isInclude,
00379         uInt maxElements
00380     ) const;
00381 
00382     // mask
00383     Bool _populateTestArray(
00384         vector<AccumType>& ary, const DataIterator& dataBegin,
00385         Int64 nr, uInt dataStride, const MaskIterator& maskBegin,
00386         uInt maskStride, uInt maxElements
00387     ) const;
00388 
00389     // mask and ranges
00390     Bool _populateTestArray(
00391         vector<AccumType>& ary, const DataIterator& dataBegin, Int64 nr,
00392         uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00393         const DataRanges& ranges, Bool isInclude, uInt maxElements
00394     ) const;
00395 
00396     // weights
00397     Bool _populateTestArray(
00398         vector<AccumType>& ary, const DataIterator& dataBegin,
00399         const WeightsIterator& weightBegin, Int64 nr, uInt dataStride,
00400         uInt maxElements
00401     ) const;
00402 
00403     // weights and ranges
00404     Bool _populateTestArray(
00405         vector<AccumType>& ary, const DataIterator& dataBegin,
00406         const WeightsIterator& weightsBegin, Int64 nr, uInt dataStride,
00407         const DataRanges& ranges, Bool isInclude, uInt maxElements
00408     ) const;
00409 
00410     // weights and mask
00411     Bool _populateTestArray(
00412         vector<AccumType>& ary, const DataIterator& dataBegin,
00413         const WeightsIterator& weightBegin, Int64 nr,
00414         uInt dataStride, const MaskIterator& maskBegin,
00415         uInt maskStride, uInt maxElements
00416     ) const;
00417 
00418     // weights, mask, ranges
00419     Bool _populateTestArray(
00420         vector<AccumType>& ary, const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00421         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00422         const DataRanges& ranges, Bool isInclude,
00423         uInt maxElements
00424     ) const;
00425     // </group>
00426 
00427     // <group>
00428     // no weights, no mask, no ranges
00429     void _unweightedStats(
00430         StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00431         const DataIterator& dataBegin, Int64 nr, uInt dataStride
00432     );
00433 
00434     // no weights, no mask
00435     void _unweightedStats(
00436         StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00437         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00438         const DataRanges& ranges, Bool isInclude
00439     );
00440 
00441     void _unweightedStats(
00442         StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00443         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00444         const MaskIterator& maskBegin, uInt maskStride
00445     );
00446 
00447     void _unweightedStats(
00448         StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00449         const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00450         const MaskIterator& maskBegin, uInt maskStride,
00451         const DataRanges& ranges, Bool isInclude
00452     );
00453     // </group>
00454 
00455     // <group>
00456     // has weights, but no mask, no ranges
00457     void _weightedStats(
00458         StatsData<AccumType>& stats, LocationType& location,
00459         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00460         Int64 nr, uInt dataStride
00461     );
00462 
00463     void _weightedStats(
00464         StatsData<AccumType>& stats, LocationType& location,
00465         const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00466         Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
00467     );
00468 
00469     void _weightedStats(
00470         StatsData<AccumType>& stats, LocationType& location,
00471         const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00472         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
00473     );
00474 
00475     void _weightedStats(
00476         StatsData<AccumType>& stats, LocationType& location,
00477         const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00478         Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00479         const DataRanges& ranges, Bool isInclude
00480     );
00481     // </group>
00482 
00483 private:
00484 
00485     // _f defined in inclusion range between Q1 - _f*D and Q3 + _f*D, where D = Q3 - Q1 and
00486     // Q1 and Q3 are the first and third quartiles, respectively
00487     Double _f;
00488     Bool _rangeIsSet, _hasRange;
00489 
00490     void _setRange();
00491 
00492 };
00493 
00494 }
00495 
00496 #ifndef CASACORE_NO_AUTO_TEMPLATES
00497 #include <casacore/scimath/Mathematics/HingesFencesStatistics.tcc>
00498 #endif //# CASACORE_NO_AUTO_TEMPLATES
00499 
00500 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1