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_STATISTICSUTILITIES_H
00028 #define SCIMATH_STATISTICSUTILITIES_H
00029
00030 #include <casacore/casa/Exceptions/Error.h>
00031 #include <casacore/scimath/Mathematics/StatisticsTypes.h>
00032 #include <casacore/casa/Utilities/DataType.h>
00033 #include <casacore/casa/aips.h>
00034
00035 #include <iostream>
00036 #include <casacore/casa/iosfwd.h>
00037
00038 namespace casacore {
00039
00040
00041
00042 template <class AccumType> class StatisticsUtilities {
00043 public:
00044
00045
00046
00047
00048 struct BinDesc {
00049 AccumType binWidth;
00050 AccumType minLimit;
00051 uInt nBins;
00052 };
00053
00054 ~StatisticsUtilities() {}
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 inline static void accumulate (
00070 Double& npts, AccumType& sum, AccumType& mean, const AccumType& datum
00071 );
00072
00073
00074
00075
00076
00077 inline static void waccumulate (
00078 Double& npts, AccumType& sumweights, AccumType& wsum, AccumType& wmean,
00079 const AccumType& datum, const AccumType& weight
00080 );
00081
00082 inline static void accumulate (
00083 Double& npts, AccumType& sum, AccumType& mean, AccumType& nvariance,
00084 AccumType& sumsq, const AccumType& datum
00085 );
00086
00087
00088 inline static void waccumulate (
00089 Double& npts, AccumType& sumweights, AccumType& wsum,
00090 AccumType& wmean, AccumType& wnvariance, AccumType& wsumsq,
00091 const AccumType& datum, const AccumType& weight
00092 );
00093
00094
00095
00096
00097
00098 template <class LocationType>
00099 inline static void accumulate (
00100 Double& npts, AccumType& sum, AccumType& mean, AccumType& nvariance,
00101 AccumType& sumsq, AccumType& datamin,
00102 AccumType& datamax, LocationType& minpos, LocationType& maxpos,
00103 const AccumType& datum, const LocationType& location
00104 );
00105
00106 template <class LocationType>
00107 inline static void waccumulate (
00108 Double& npts, AccumType& sumofweights, AccumType& sum, AccumType& mean,
00109 AccumType& nvariance, AccumType& sumsq, AccumType& datamin, AccumType& datamax,
00110 LocationType& minpos, LocationType& maxpos,
00111 const AccumType& datum, const AccumType& weight, const LocationType& location
00112 );
00113
00114
00115
00116
00117
00118 template <class LocationType>
00119 inline static Bool doMax(
00120 AccumType& datamax, LocationType& maxpos, Bool isFirst,
00121 const AccumType& datum, const LocationType& location
00122 );
00123
00124 template <class LocationType>
00125 inline static Bool doMin(
00126 AccumType& datamin, LocationType& minpos, Bool isFirst,
00127 const AccumType& datum, const LocationType& location
00128 );
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 inline static void accumulateSym (
00150 Double& npts, AccumType& nvariance,
00151 AccumType& sumsq, const AccumType& datum, const AccumType& center
00152 );
00153
00154
00155 inline static void waccumulateSym (
00156 Double& npts, AccumType& sumweights,
00157 AccumType& wnvariance, AccumType& wsumsq,
00158 const AccumType& datum, const AccumType& weight, const AccumType& center
00159 );
00160
00161
00162
00163 template <class LocationType>
00164 inline static void accumulateSym (
00165 Double& npts, AccumType& nvariance,
00166 AccumType& sumsq, AccumType& datamin,
00167 AccumType& datamax, LocationType& minpos, LocationType& maxpos,
00168 const AccumType& datum, const LocationType& location, const AccumType& center
00169 );
00170
00171 template <class LocationType>
00172 inline static void waccumulateSym (
00173 Double& npts, AccumType& sumofweights,
00174 AccumType& nvariance, AccumType& sumsq, AccumType& datamin, AccumType& datamax,
00175 LocationType& minpos, LocationType& maxpos,
00176 const AccumType& datum, const AccumType& weight, const LocationType& location,
00177 const AccumType& center
00178 );
00179
00180
00181
00182
00183
00184 inline static Int getInt(const AccumType& v) {
00185 return (Int)v;
00186 }
00187
00188 inline static Bool includeDatum(
00189 const AccumType& datum, typename DataRanges::const_iterator beginRange,
00190 typename DataRanges::const_iterator endRange, Bool isInclude
00191 );
00192
00193
00194
00195
00196
00197
00198
00199 static StatsData<AccumType> combine(
00200 const vector<StatsData<AccumType> >& stats
00201 );
00202
00203 private:
00204
00205 const static AccumType TWO;
00206
00207 StatisticsUtilities() {}
00208
00209 };
00210
00211
00212
00213
00214 template<>
00215 inline Int StatisticsUtilities<casacore::Complex>::getInt(const casacore::Complex&) {
00216 ThrowCc("This version for complex data types should never be called");
00217 }
00218
00219 template<>
00220 inline Int StatisticsUtilities<casacore::DComplex>::getInt(const casacore::DComplex&) {
00221 ThrowCc("Logic Error: This version for complex data types should never be called");
00222 }
00223
00224 template <class T>
00225 ostream &operator<<(ostream &os, const typename StatisticsUtilities<T>::BinDesc &desc) {
00226 os << "min limit " << desc.minLimit << " bin width " << desc.binWidth
00227 << " nbins " << desc.nBins;
00228 return os;
00229 }
00230
00231 }
00232
00233 #ifndef CASACORE_NO_AUTO_TEMPLATES
00234 #include <casacore/scimath/Mathematics/StatisticsUtilities.tcc>
00235 #endif //# CASACORE_NO_AUTO_TEMPLATES
00236
00237 #endif