00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SCIMATH_FITTOHALFSTATISTICS_H
00028 #define SCIMATH_FITTOHALFSTATISTICS_H
00029
00030 #include <casacore/casa/aips.h>
00031
00032 #include <casacore/scimath/Mathematics/ConstrainedRangeStatistics.h>
00033 #include <casacore/scimath/Mathematics/FitToHalfStatisticsData.h>
00034
00035 namespace casacore {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 template <class AccumType, class DataIterator, class MaskIterator=const Bool *, class WeightsIterator=DataIterator>
00047 class FitToHalfStatistics
00048 : public ConstrainedRangeStatistics<CASA_STATP> {
00049 public:
00050
00051 const static AccumType TWO;
00052
00053
00054 FitToHalfStatistics(
00055 FitToHalfStatisticsData::CENTER center=FitToHalfStatisticsData::CMEAN,
00056 FitToHalfStatisticsData::USE_DATA useData=FitToHalfStatisticsData::LE_CENTER,
00057 AccumType value=0
00058 );
00059
00060 virtual ~FitToHalfStatistics();
00061
00062
00063 FitToHalfStatistics<CASA_STATP>& operator=(
00064 const FitToHalfStatistics<CASA_STATP>& other
00065 );
00066
00067
00068 virtual StatisticsData::ALGORITHM algorithm() const {
00069 return StatisticsData::FITTOHALF;
00070 };
00071
00072
00073 AccumType getMedian(
00074 CountedPtr<uInt64> knownNpts=NULL, CountedPtr<AccumType> knownMin=NULL,
00075 CountedPtr<AccumType> knownMax=NULL, uInt binningThreshholdSizeBytes=4096*4096,
00076 Bool persistSortedArray=False, uInt64 nBins=10000
00077 );
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 AccumType getMedianAndQuantiles(
00109 std::map<Double, AccumType>& quantiles, const std::set<Double>& fractions,
00110 CountedPtr<uInt64> knownNpts=NULL, CountedPtr<AccumType> knownMin=NULL,
00111 CountedPtr<AccumType> knownMax=NULL,
00112 uInt binningThreshholdSizeBytes=4096*4096, Bool persistSortedArray=False,
00113 uInt64 nBins=10000
00114 );
00115
00116
00117 AccumType getMedianAbsDevMed(
00118 CountedPtr<uInt64> knownNpts=NULL,
00119 CountedPtr<AccumType> knownMin=NULL, CountedPtr<AccumType> knownMax=NULL,
00120 uInt binningThreshholdSizeBytes=4096*4096, Bool persistSortedArray=False,
00121 uInt64 nBins=10000
00122 );
00123
00124
00125
00126 std::map<Double, AccumType> getQuantiles(
00127 const std::set<Double>& fractions, CountedPtr<uInt64> knownNpts=NULL,
00128 CountedPtr<AccumType> knownMin=NULL, CountedPtr<AccumType> knownMax=NULL,
00129 uInt binningThreshholdSizeBytes=4096*4096, Bool persistSortedArray=False,
00130 uInt64 nBins=10000
00131 );
00132
00133
00134
00135
00136
00137 virtual void getMinMax(AccumType& mymin, AccumType& mymax);
00138
00139
00140
00141
00142
00143 uInt64 getNPts();
00144
00145
00146
00147
00148 virtual void reset();
00149
00150
00151
00152 void setCalculateAsAdded(Bool c);
00153
00154 protected:
00155
00156 virtual void _clearData();
00157
00158 virtual StatsData<AccumType> _getInitialStats() const;
00159
00160 StatsData<AccumType> _getStatistics();
00161
00162 inline StatsData<AccumType>& _getStatsData() { return _statsData; }
00163
00164 inline const StatsData<AccumType>& _getStatsData() const { return _statsData; }
00165
00166
00167
00168 void _unweightedStats(
00169 StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00170 const DataIterator& dataBegin, Int64 nr, uInt dataStride
00171 );
00172
00173
00174 void _unweightedStats(
00175 StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00176 const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00177 const DataRanges& ranges, Bool isInclude
00178 );
00179
00180 void _unweightedStats(
00181 StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00182 const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00183 const MaskIterator& maskBegin, uInt maskStride
00184 );
00185
00186 void _unweightedStats(
00187 StatsData<AccumType>& stats, uInt64& ngood, LocationType& location,
00188 const DataIterator& dataBegin, Int64 nr, uInt dataStride,
00189 const MaskIterator& maskBegin, uInt maskStride,
00190 const DataRanges& ranges, Bool isInclude
00191 );
00192
00193
00194 void _updateDataProviderMaxMin(
00195 const StatsData<AccumType>& threadStats
00196 );
00197
00198
00199
00200
00201 void _weightedStats(
00202 StatsData<AccumType>& stats, LocationType& location,
00203 const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00204 Int64 nr, uInt dataStride
00205 );
00206
00207 void _weightedStats(
00208 StatsData<AccumType>& stats, LocationType& location,
00209 const DataIterator& dataBegin, const WeightsIterator& weightsBegin,
00210 Int64 nr, uInt dataStride, const DataRanges& ranges, Bool isInclude
00211 );
00212
00213 void _weightedStats(
00214 StatsData<AccumType>& stats, LocationType& location,
00215 const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00216 Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride
00217 );
00218
00219 void _weightedStats(
00220 StatsData<AccumType>& stats, LocationType& location,
00221 const DataIterator& dataBegin, const WeightsIterator& weightBegin,
00222 Int64 nr, uInt dataStride, const MaskIterator& maskBegin, uInt maskStride,
00223 const DataRanges& ranges, Bool isInclude
00224 );
00225
00226
00227 private:
00228 FitToHalfStatisticsData::CENTER _centerType;
00229 Bool _useLower;
00230 AccumType _centerValue;
00231 StatsData<AccumType> _statsData;
00232 Bool _doMedAbsDevMed, _rangeIsSet;
00233
00234 CountedPtr<AccumType> _realMax, _realMin;
00235
00236 void _getRealMinMax(
00237 CountedPtr<AccumType>& realMin, CountedPtr<AccumType>& realMax,
00238 CountedPtr<AccumType> knownMin, CountedPtr<AccumType> knownMax
00239 );
00240
00241 void _setRange();
00242 };
00243
00244 }
00245
00246 #ifndef CASACORE_NO_AUTO_TEMPLATES
00247 #include <casacore/scimath/Mathematics/FitToHalfStatistics.tcc>
00248 #endif //# CASACORE_NO_AUTO_TEMPLATES
00249
00250 #endif