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_CHAUVENETCRITERIONSTATISTICS_H 00028 #define SCIMATH_CHAUVENETCRITERIONSTATISTICS_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 Chauvenet criterion. This method 00041 // iteratively calculates statistics by discarding outliers on the basis of Chauvenet's 00042 // criterion, until the specified maximum number of iterations is reached, or the final 00043 // iteration results in no additional points being discarded. 00044 // Alternatively, one can specify a z score which indicates the number of standard deviations 00045 // beyond which to discard points. In this case, no iterating is done. 00046 00047 template <class AccumType, class DataIterator, class MaskIterator=const Bool*, class WeightsIterator=DataIterator> 00048 class ChauvenetCriterionStatistics 00049 : public ConstrainedRangeStatistics<CASA_STATP> { 00050 public: 00051 00052 // If <src>zscore</src> is not negative, use that value to discard outliers beyond 00053 // zscore standard deviations from the mean, and compute statistics based on the 00054 // remaining data. If <src>zscore</src> is negative, use Chauvenet's Criterion to 00055 // determine which outliers to discard. <src>maxIterations</src> is the maximum 00056 // number of iterations to use before stopping. If negative, continue iterating until the 00057 // set zscore or Chauvenet's criterion is met (ie that there are no remaining outliers). 00058 ChauvenetCriterionStatistics(Double zscore=-1, Int maxIterations=0); 00059 00060 virtual ~ChauvenetCriterionStatistics(); 00061 00062 // copy semantics 00063 ChauvenetCriterionStatistics<CASA_STATP>& operator=( 00064 const ChauvenetCriterionStatistics<CASA_STATP>& other 00065 ); 00066 00067 // get the algorithm that this object uses for computing stats 00068 virtual StatisticsData::ALGORITHM algorithm() const { 00069 return StatisticsData::CHAUVENETCRITERION; 00070 }; 00071 00072 // reset object to initial state. Clears all private fields including data, 00073 // accumulators, global range. It does not affect the fence factor (_f), which was 00074 // set at object construction. 00075 virtual void reset(); 00076 00077 // This class does not allow statistics to be calculated as datasets are added, so 00078 // an exception will be thrown if <src>c</src> is True. 00079 void setCalculateAsAdded(Bool c); 00080 00081 // get the number of iterations 00082 uInt getNiter() const { return _niter; } 00083 00084 private: 00085 00086 Double _zscore; 00087 Int _maxIterations; 00088 Bool _rangeIsSet; 00089 uInt _niter; 00090 00091 void _setRange(); 00092 }; 00093 00094 } 00095 00096 #ifndef CASACORE_NO_AUTO_TEMPLATES 00097 #include <casacore/scimath/Mathematics/ChauvenetCriterionStatistics.tcc> 00098 #endif //# CASACORE_NO_AUTO_TEMPLATES 00099 00100 #endif