00001 /* @file psStats.h 00002 * @brief basic statistical operations 00003 * 00004 * This file will hold the definition of the histogram and stats data 00005 * structures. It also contains prototypes for procedures which operate 00006 * on those data structures. 00007 * 00008 * @author GLG, MHPCC 00009 * 00010 * @version $Revision: 1.59 $ $Name: $ 00011 * @date $Date: 2007/01/23 22:47:23 $ 00012 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00013 */ 00014 00015 #ifndef PS_STATS_H 00016 #define PS_STATS_H 00017 00018 /// @addtogroup MathOps Mathematical Operations 00019 /// @{ 00020 00021 /****************************************************************************** 00022 Statistical functions and data structures. 00023 *****************************************************************************/ 00024 00025 /** enumeration of statistical calculation options 00026 * 00027 * @see psStats, psVectorStats, psImageStats 00028 */ 00029 typedef enum { 00030 PS_STAT_NONE = 0x000000, ///< Empty set 00031 PS_STAT_SAMPLE_MEAN = 0x000001, ///< Sample Mean 00032 PS_STAT_SAMPLE_MEDIAN = 0x000002, ///< Sample Median 00033 PS_STAT_SAMPLE_STDEV = 0x000004, ///< Sample Standard Deviation 00034 PS_STAT_SAMPLE_QUARTILE = 0x000008, ///< Sample Quartile 00035 PS_STAT_ROBUST_MEDIAN = 0x000010, ///< Robust Median 00036 PS_STAT_ROBUST_STDEV = 0x000020, ///< Robust Standarad Deviation 00037 PS_STAT_ROBUST_QUARTILE = 0x000040, ///< Robust Quartile 00038 PS_STAT_FITTED_MEAN = 0x000080, ///< Fitted Mean 00039 PS_STAT_FITTED_STDEV = 0x000100, ///< Fitted Standard Deviation 00040 PS_STAT_CLIPPED_MEAN = 0x000200, ///< Clipped Mean 00041 PS_STAT_CLIPPED_STDEV = 0x000400, ///< Clipped Standard Deviation 00042 PS_STAT_MAX = 0x000800, ///< Maximum 00043 PS_STAT_MIN = 0x001000, ///< Minumum 00044 PS_STAT_USE_RANGE = 0x002000, ///< Range 00045 PS_STAT_USE_BINSIZE = 0x004000, ///< Binsize 00046 PS_STAT_FITTED_MEAN_V2 = 0x008000, ///< Fitted Mean 00047 PS_STAT_FITTED_STDEV_V2 = 0x010000, ///< Fitted Standard Deviation 00048 PS_STAT_FITTED_MEAN_V3 = 0x020000, ///< Fitted Mean 00049 PS_STAT_FITTED_STDEV_V3 = 0x040000, ///< Fitted Standard Deviation 00050 } psStatsOptions; 00051 00052 /** This is the generic statistics structure. It contails the data members 00053 for the various statistic values. It also contains the options member to 00054 specifiy which statistics should be calculated. */ 00055 typedef struct 00056 { 00057 double sampleMean; ///< formal mean of sample 00058 double sampleMedian; ///< formal median of sample 00059 double sampleStdev; ///< standard deviation of sample 00060 double sampleUQ; ///< upper quartile of sample 00061 double sampleLQ; ///< lower quartile of sample 00062 double robustMedian; ///< robust median of array 00063 double robustStdev; ///< robust standard deviation of array 00064 double robustUQ; ///< robust upper quartile 00065 double robustLQ; ///< robust lower quartile 00066 long robustN50; ///< Number of points in Gaussian fit; XXX: This is currently unused. 00067 double fittedMean; ///< robust mean of data 00068 double fittedStdev; ///< robust standard deviation of data 00069 long fittedNfit; ///< Number of points in Gaussian fit; XXX: This is currently unused 00070 double clippedMean; ///< Nsigma clipped mean 00071 double clippedStdev; ///< standard deviation after clipping 00072 long clippedNvalues; ///< Number of data points used for clipped mean. 00073 double clipSigma; ///< Nsigma used for clipping; user input 00074 int clipIter; ///< Number of clipping iterations; user input 00075 double min; ///< minimum data value in array 00076 double max; ///< maximum data value in array 00077 double binsize; ///< binsize for robust fit (input/ouput) 00078 long nSubsample; ///< maxinum number of measurements (input) 00079 psStatsOptions options; ///< bitmask of values requested 00080 psStatsOptions results; ///< bitmask of values calculated 00081 } 00082 psStats; 00083 00084 /** Performs statistical calculations on a vector. 00085 * 00086 * @return psStats* the statistical results as specified by stats->options 00087 */ 00088 bool psVectorStats( 00089 psStats* stats, ///< stats structure defines stats to be calculated and how 00090 const psVector* in, ///< Vector to be analysed. 00091 const psVector* errors, ///< Errors. 00092 const psVector* mask, ///< Ignore elements where (maskVector & maskVal) != 0: must be INT or NULL 00093 psMaskType maskVal ///< Only mask elements with one of these bits set in maskVector 00094 ); 00095 00096 /** Allocator of the psStats structure. 00097 * 00098 * @return psStats* A new psStats struct with the options member set to the 00099 * value given. 00100 */ 00101 psStats* psStatsAlloc( 00102 psStatsOptions options ///< Statistics to calculate 00103 ); 00104 00105 00106 /** Checks the type of a particular pointer. 00107 * 00108 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 00109 * 00110 * @return bool: True if the pointer matches a psStats structure, false otherwise. 00111 */ 00112 bool psMemCheckStats( 00113 psPtr ptr ///< the pointer whose type to check 00114 ); 00115 00116 // Get the statistics option from a string 00117 psStatsOptions psStatsOptionFromString(const char *string); 00118 // Write a string from the statistics options 00119 psString psStatsOptionToString(psStatsOptions option); 00120 // Generate a psStats from a string of statistics options 00121 psStats *psStatsFromString(const char *string); 00122 // Generate a string of statistics options from a psStats 00123 psString psStatsToString(const psStats *stats); 00124 // Is only a single statistics option set? 00125 psStatsOptions psStatsSingleOption(psStatsOptions option); 00126 // Return a particular stats value 00127 double psStatsGetValue(const psStats *stats, psStatsOptions option); 00128 00129 /// @} 00130 #endif // #ifndef PS_STATS_H 00131 00132 /* 00133 * private stats functions used in psStats.c: 00134 * 00135 * vectorSampleMean 00136 (none) 00137 * vectorMinMax 00138 (none) 00139 * vectorSampleMedian (also yields SAMPLE_QUARTILE) 00140 (none) 00141 * vectorSampleStdev 00142 (vectorSampleMean) 00143 * vectorClippedStats 00144 (vectorSampleMedian) 00145 (vectorSampleMean (*also subset)) 00146 (vectorSampleStdev (*also subset)) 00147 * vectorRobustStats 00148 (vectorMinMax (*only subset)) 00149 * vectorFittedStats 00150 (vectorRobustStats) 00151 00152 * private stats functions called by other private stats functions are automatically called by 00153 * those functions. since they set the stats->results flags, they are not called multiple 00154 * times. 00155 00156 * the private stats functions do not test for their corresponding stats flags: it is not 00157 * necessary to request them if they are called within this function. 00158 00159 */
1.5.1