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