00001 /** @file psStats.h 00002 * \brief basic statistical operations 00003 * @ingroup Stats 00004 * 00005 * This file will hold the definition of the histogram and stats data 00006 * structures. It also contains prototypes for procedures which operate 00007 * on those data structures. 00008 * 00009 * XXX: The following stats members are never used, or set in this code. 00010 * stats->robustN50 00011 * stats->clippedNvalues 00012 * stats->binsize 00013 * 00014 * @author GLG, MHPCC 00015 * 00016 * @version $Revision: 1.52 $ $Name: rel12 $ 00017 * @date $Date: 2006/05/22 22:46:01 $ 00018 * 00019 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00020 */ 00021 #ifndef PS_STATS_H 00022 #define PS_STATS_H 00023 00024 #include "psVector.h" 00025 00026 /// @addtogroup Stats 00027 /// @{ 00028 00029 /****************************************************************************** 00030 Statistical functions and data structures. 00031 *****************************************************************************/ 00032 00033 /** enumeration of statistical calculation options 00034 * 00035 * @see psStats, psVectorStats, psImageStats 00036 */ 00037 // XXX: Is PS_STAT_ROBUST_FOR_SAMPLE obsolete? 00038 typedef enum { 00039 PS_STAT_SAMPLE_MEAN = 0x000001, ///< Sample Mean 00040 PS_STAT_SAMPLE_MEDIAN = 0x000002, ///< Sample Median 00041 PS_STAT_SAMPLE_STDEV = 0x000004, ///< Sample Standard Deviation 00042 PS_STAT_SAMPLE_QUARTILE = 0x000008, ///< Sample Quartile 00043 PS_STAT_ROBUST_MEDIAN = 0x000010, ///< Robust Median 00044 PS_STAT_ROBUST_STDEV = 0x000020, ///< Robust Standarad Deviation 00045 PS_STAT_ROBUST_QUARTILE = 0x000040, ///< Robust Quartile 00046 PS_STAT_FITTED_MEAN = 0x000080, ///< Fitted Mean 00047 PS_STAT_FITTED_STDEV = 0x000100, ///< Fitted Standard Deviation 00048 PS_STAT_CLIPPED_MEAN = 0x000200, ///< Clipped Mean 00049 PS_STAT_CLIPPED_STDEV = 0x000400, ///< Clipped Standard Deviation 00050 PS_STAT_MAX = 0x000800, ///< Maximum 00051 PS_STAT_MIN = 0x001000, ///< Minumum 00052 PS_STAT_USE_RANGE = 0x002000, ///< Range 00053 PS_STAT_USE_BINSIZE = 0x004000 ///< Binsize 00054 } psStatsOptions; 00055 00056 /** This is the generic statistics structure. It contails the data members 00057 for the various statistic values. It also contains the options member to 00058 specifiy which statistics should be calculated. */ 00059 typedef struct 00060 { 00061 double sampleMean; ///< formal mean of sample 00062 double sampleMedian; ///< formal median of sample 00063 double sampleStdev; ///< standard deviation of sample 00064 double sampleUQ; ///< upper quartile of sample 00065 double sampleLQ; ///< lower quartile of sample 00066 double robustMedian; ///< robust median of array 00067 double robustStdev; ///< robust standard deviation of array 00068 double robustUQ; ///< robust upper quartile 00069 double robustLQ; ///< robust lower quartile 00070 long robustN50; ///< Number of points in Gaussian fit; XXX: This is currently unused. 00071 double fittedMean; ///< robust mean of data 00072 double fittedStdev; ///< robust standard deviation of data 00073 long fittedNfit; ///< Number of points in Gaussian fit; XXX: This is currently unused 00074 double clippedMean; ///< Nsigma clipped mean 00075 double clippedStdev; ///< standard deviation after clipping 00076 long clippedNvalues; ///< Number of data points used for clipped mean. 00077 double clipSigma; ///< Nsigma used for clipping; user input 00078 int clipIter; ///< Number of clipping iterations; user input 00079 double min; ///< minimum data value in array 00080 double max; ///< maximum data value in array 00081 double binsize; ///< binsize for robust fit (input/ouput) 00082 long nSubsample; ///< maxinum number of measurements (input) 00083 psStatsOptions options; ///< bitmask of calculated values 00084 } 00085 psStats; 00086 00087 /** Performs statistical calculations on a vector. 00088 * 00089 * @return psStats* the statistical results as specified by stats->options 00090 */ 00091 psStats* psVectorStats( 00092 psStats* stats, ///< stats structure defines stats to be calculated and how 00093 const psVector* in, ///< Vector to be analysed. 00094 const psVector* errors, ///< Errors. 00095 const psVector* mask, ///< Ignore elements where (maskVector & maskVal) != 0: must be INT or NULL 00096 psMaskType maskVal ///< Only mask elements with one of these bits set in maskVector 00097 ); 00098 00099 /** Allocator of the psStats structure. 00100 * 00101 * @return psStats* A new psStats struct with the options member set to the 00102 * value given. 00103 */ 00104 psStats* psStatsAlloc( 00105 psStatsOptions options ///< Statistics to calculate 00106 ); 00107 00108 00109 /** Checks the type of a particular pointer. 00110 * 00111 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00112 * 00113 * @return bool: True if the pointer matches a psStats structure, false otherwise. 00114 */ 00115 bool psMemCheckStats( 00116 psPtr ptr ///< the pointer whose type to check 00117 ); 00118 00119 00120 /****************************************************************************** 00121 Histogram functions and data structures. 00122 *****************************************************************************/ 00123 00124 /** The basic histogram structure which contains bounds and bins. 00125 * 00126 * In this structure, the vector bounds specifies the boundaries of the 00127 * histogram bins, and must of type psF32, while nums specifies the number 00128 * of entries in the bin, and must of type psU32. The value of bounds.n must 00129 * therefore be 1 greater than than nums.n. The two values minNum and maxNum 00130 * are the number of data values which fell below the lower limit bound or 00131 * above the upper limit bound, respectively. 00132 */ 00133 typedef struct 00134 { 00135 const psVector* bounds; ///< Bounds for the bins (type F32) 00136 psVector* nums; ///< Number in each of the bins (INT) 00137 int minNum; ///< Number below the minimum 00138 int maxNum; ///< Number above the maximum 00139 bool uniform; ///< Is it a uniform distribution? 00140 } 00141 psHistogram; 00142 00143 /** Allocator for psHistogram where the bounds of the bins are implicitly 00144 * specified through simply specifying an upper and lower limit along with 00145 * the size of the bins. 00146 * 00147 * @return psHistogram* Newly allocated psHistogram 00148 */ 00149 psHistogram* psHistogramAlloc( 00150 float lower, ///< Lower limit for the bins 00151 float upper, ///< Upper limit for the bins 00152 int n ///< Number of bins 00153 ); 00154 00155 00156 /** Checks the type of a particular pointer. 00157 * 00158 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00159 * 00160 * @return bool: True if the pointer matches a psHistogram structure, false otherwise. 00161 */ 00162 bool psMemCheckHistogram( 00163 psPtr ptr ///< the pointer whose type to check 00164 ); 00165 00166 00167 /** Allocator for psHistogram where the bounds of the bins are explicitly 00168 * specified. 00169 * 00170 * @return psHistogram* Newly allocated psHistogram 00171 */ 00172 psHistogram* psHistogramAllocGeneric( 00173 const psVector* bounds ///< Bounds for the bins 00174 ); 00175 00176 /** Calculate a histogram 00177 * 00178 * The following function populates the histogram bins from the specified 00179 * vector (in). It alters and returns the histogram out structure. The input 00180 * vector may be of types psU8, psU16, psF32, psF64. 00181 * 00182 * @return psHistogram* histogram result 00183 */ 00184 psHistogram* psVectorHistogram( 00185 psHistogram* out, ///< Histogram data 00186 const psVector* values, ///< Vector to analyse 00187 const psVector* errors, ///< Errors 00188 const psVector* mask, ///< Mask dat for input vector 00189 psMaskType maskVal ///< Mask value 00190 ); 00191 00192 /** Extracts the statistic value specified by stats->options. 00193 * 00194 * @return psBool If more than one statistic result is set in stats->options, 00195 * false is returned and the value parameter is not set, 00196 * otherwise true is returned. 00197 */ 00198 psBool p_psGetStatValue( 00199 const psStats* stats, ///< the statistic struct to operate on 00200 00201 psF64 *value ///< if return is true, this is set to the specified statistic value by stats->options 00202 ); 00203 00204 /// @} 00205 00206 #endif // #ifndef PS_STATS_H
1.4.4