Changeset 2411 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Nov 23, 2004, 2:05:54 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r2406 r2411 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.9 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-11-2 3 19:35:30$11 * @version $Revision: 1.99 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-24 00:05:54 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 128 128 NOTE: it is assumed that any call to these statistical functions will have 129 129 been preceded by a call to the psVectorStats() function. Various sanity tests 130 will only be performed in psVectorStats(). 131 132 XXX: Should we perform the sanity checks in each routine anyway? 130 will only be performed in psVectorStats(). Should we perform the sanity 131 checks in each routine anyway? 133 132 134 133 XXX: For many of these private stats routines, what should be done if there 135 are no wacceptable elements in the input vector (if no elements lie within134 are no acceptable elements in the input vector (if no elements lie within 136 135 range, or there are no unmasked elements, or the input vector is NULL)? 137 136 Currently we set the value to NAN. … … 931 930 932 931 /***************************************************************************** 933 psNormalizeVectorRange##TYPE(myData, low, high): this is a private function which 934 normalizes the elements of a vector to a range between low and high. 935 936 XXX: Should we make the arguments psScalars? 937 938 XXX: Should we make the arguments PS_TYPE_F64? 932 These macros and functions define the following functions: 933 934 p_psNormalizeVectorRange(myData, low, high) 935 936 That assumes that the low/high arguments are PS_TYPE_F64; the vector myData 937 can be of any type. Arguments low/high will be converted to the appropriate 938 type and one of the type-specific functions below will be called: 939 940 p_psNormalizeVectorRangeU8(myData, low, high) 941 p_psNormalizeVectorRangeU16(myData, low, high) 942 p_psNormalizeVectorRangeU32(myData, low, high) 943 p_psNormalizeVectorRangeU64(myData, low, high) 944 p_psNormalizeVectorRangeS8(myData, low, high) 945 p_psNormalizeVectorRangeS16(myData, low, high) 946 p_psNormalizeVectorRangeS32(myData, low, high) 947 p_psNormalizeVectorRangeS64(myData, low, high) 948 p_psNormalizeVectorRangeF32(myData, low, high) 949 p_psNormalizeVectorRangeF64(myData, low, high) 939 950 *****************************************************************************/ 940 951 #define PS_FUNC_MACRO_NORMALIZE_VECTOR_RANGE(TYPE) \ … … 984 995 PS_FUNC_MACRO_NORMALIZE_VECTOR_RANGE(F64) 985 996 997 void p_psNormalizeVectorRange(psVector* myData, 998 psF64 outLow, 999 psF64 outHigh) 1000 { 1001 switch (myData->type.type) { 1002 case PS_TYPE_U8: 1003 p_psNormalizeVectorRangeU8(myData, (psU8) outLow, (psU8) outHigh); 1004 break; 1005 case PS_TYPE_U16: 1006 p_psNormalizeVectorRangeU16(myData, (psU16) outLow, (psU16) outHigh); 1007 break; 1008 case PS_TYPE_U32: 1009 p_psNormalizeVectorRangeU32(myData, (psU32) outLow, (psU32) outHigh); 1010 break; 1011 case PS_TYPE_U64: 1012 p_psNormalizeVectorRangeU64(myData, (psU64) outLow, (psU64) outHigh); 1013 break; 1014 case PS_TYPE_S8: 1015 p_psNormalizeVectorRangeS8(myData, (psS8) outLow, (psS8) outHigh); 1016 break; 1017 case PS_TYPE_S16: 1018 p_psNormalizeVectorRangeS16(myData, (psS16) outLow, (psS16) outHigh); 1019 break; 1020 case PS_TYPE_S32: 1021 p_psNormalizeVectorRangeS32(myData, (psS32) outLow, (psS32) outHigh); 1022 break; 1023 case PS_TYPE_S64: 1024 p_psNormalizeVectorRangeS64(myData, (psS64) outLow, (psS64) outHigh); 1025 break; 1026 case PS_TYPE_F32: 1027 p_psNormalizeVectorRangeF32(myData, (psF32) outLow, (psF32) outHigh); 1028 break; 1029 case PS_TYPE_F64: 1030 p_psNormalizeVectorRangeF64(myData, (psF64) outLow, (psF64) outHigh); 1031 break; 1032 case PS_TYPE_C32: 1033 case PS_TYPE_C64: 1034 default: 1035 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1036 "Unallowable operation: %s has incorrect type.", 1037 myData); 1038 break; 1039 } 1040 } 1041 986 1042 /****************************************************************************** 987 1043 p_ps1DPolyMedian(myPoly, rangeLow, rangeHigh, midpoint): This routine takes … … 1053 1109 1054 1110 XXX: After you fit the polynomial, solve for X analytically. 1055 1056 XXX: Check for errors in psLib routines that we call.1057 1111 *****************************************************************************/ 1058 1112 float fitQuadraticSearchForYThenReturnX(psVector *xVec, … … 1104 1158 // polynomial, looking for the value x such that f(x) = yVal 1105 1159 tmpFloat = p_ps1DPolyMedian(myPoly, x->data.F64[0], x->data.F64[2], yVal); 1160 if (isnan(tmpFloat)) { 1161 psError(PS_ERR_UNEXPECTED_NULL, 1162 false, 1163 PS_ERRORTEXT_psStats_STATS_FIT_QUADRATIC_POLY_MEDIAN); 1164 return(NAN); 1165 } 1106 1166 1107 1167 } else { … … 1135 1195 PS_STAT_ROBUST_QUARTILE 1136 1196 I have included all that computation in a single function, as opposed to 1137 breaking it across several functions for one primary reason: they all 1138 require the same basic initial processing steps (calculate the histogram, 1139 etc.) however there is no currently defined means, in the SDRS, to specify 1140 this computation as a separate step. If the above robust stat measures were 1141 calcualted in separate functiosn, then much of the initial processing would 1142 be duplicated. 1197 breaking it across several functions for one primary reason: they all require 1198 the same basic initial processing steps (calculate the histogram, etc.). 1143 1199 1144 1200 Inputs … … 1185 1241 // by computing the clipped standard deviation of the vector, and dividing 1186 1242 // that by 10.0; 1187 p_psVectorClippedStats(myVector, maskVector, maskVal, tmpStats); 1243 int rc = p_psVectorClippedStats(myVector, maskVector, maskVal, tmpStats); 1244 if (rc != 0) { 1245 psError(PS_ERR_UNEXPECTED_NULL, 1246 false, 1247 PS_ERRORTEXT_psStats_ROBUST_STATS_CLIPPED_STATS); 1248 return(1); 1249 } 1188 1250 binSize = tmpStats->clippedStdev / 10.0f; 1189 1251 … … 1213 1275 return(0); 1214 1276 } 1277 1215 1278 // Determine minimum and maximum values in the data vector. 1216 1279 if (isnan(stats->min)) { … … 1221 1284 } 1222 1285 } 1223 1224 1225 1286 if (isnan(stats->max)) { 1226 if (0 != p_psVectorMax(myVector, maskVector, maskVal, stats)) {} 1287 if (0 != p_psVectorMax(myVector, maskVector, maskVal, stats)) { 1288 psLogMsg(__func__, PS_LOG_WARN, 1289 "WARNING: p_psVectorMin(): p_psVectorMax() reported a NAN mean.\n"); 1290 return(1); 1291 } 1227 1292 } 1228 1293 … … 1594 1659 1595 1660 psS32 i = 0; // Loop index variable 1596 float binSize = 0.0; // Histogram bin size1661 float binSize = 0.0; // Histogram bin size 1597 1662 psS32 binNum = 0; // A temporary bin number 1598 1663 psS32 numBins = 0; // The total number of bins … … 1608 1673 } 1609 1674 1610 1611 1675 numBins = out->nums->n; 1612 1676 for (i = 0; i < inF32->n; i++) { 1613 1677 // Check if this pixel is masked, and if so, skip it. 1614 if ((mask == NULL) || ((mask != NULL) && (!(mask->data.U8[i] & maskVal)))) { 1615 // Check if this pixel is below the minimum value, and if so 1616 // count it, then skip it. 1678 if ((mask == NULL) || 1679 ((mask != NULL) && (!(mask->data.U8[i] & maskVal)))) { 1617 1680 if (inF32->data.F32[i] < out->bounds->data.F32[0]) { 1681 // If this pixel is below minimum value, count it, then skip. 1618 1682 out->minNum++; 1619 // Check if this pixel is above the maximum value, and if so1620 // count it, then skip it.1621 1683 } else if (inF32->data.F32[i] > out->bounds->data.F32[numBins]) { 1684 // If this pixel is above maximum value, count it, then skip. 1622 1685 out->maxNum++; 1623 1686 } else { … … 1629 1692 1630 1693 // XXX: This if-statement really shouldn't be necessary. 1631 // However, due to numerical lack of precision, we occasionally1632 // produce a binNum outside the range of bins.1694 // However, due to numerical lack of precision, we 1695 // occasionally produce a binNum outside the range. 1633 1696 if (binNum >= out->nums->n) { 1634 1697 binNum = out->nums->n - 1; … … 1637 1700 (out->nums->data.U32[binNum])++; 1638 1701 1639 // If this is a non-uniform histogram, determining the correct1640 // bin number requires a bit more work.1641 1702 } else { 1703 // If this is a non-uniform histogram, determining the 1704 // correct bin number requires a bit more work. 1642 1705 tmpScalar.data.F32 = inF32->data.F32[i]; 1643 1706 tmp = p_psVectorBinDisect(out->bounds, &tmpScalar); 1644 1707 if (tmp < 0) { 1645 // XXX: Generate warning message 1708 psLogMsg(__func__, PS_LOG_WARN, 1709 "WARNING: psVectorHistogram(): element outside histogram bounds.\n"); 1646 1710 } else { 1647 1711 (out->nums->data.U32[tmp])++; … … 1666 1730 everything and put type support in the various stat functions. 1667 1731 1668 XXX: Should the default data type be F64? Since we are buying Athlons...1732 XXX: Should the default data type be F64? Since we are buying Opterons... 1669 1733 *****************************************************************************/ 1670 1734 psVector* p_psConvertToF32(psVector* in) … … 1744 1808 // ************************************************************************ 1745 1809 if (stats->options & PS_STAT_SAMPLE_MEAN) { 1746 p_psVectorSampleMean(inF32, mask, maskVal, stats); 1810 if (0 != p_psVectorSampleMean(inF32, mask, maskVal, stats)) { 1811 psLogMsg(__func__, PS_LOG_WARN, 1812 "WARNING: psVectorStats(): p_psVectorSampleMean() returned an error.\n"); 1813 } 1747 1814 } 1748 1815 // ************************************************************************ 1749 1816 if (stats->options & PS_STAT_SAMPLE_MEDIAN) { 1750 p_psVectorSampleMedian(inF32, mask, maskVal, stats); 1817 if (false == p_psVectorSampleMedian(inF32, mask, maskVal, stats)) { 1818 psLogMsg(__func__, PS_LOG_WARN, 1819 "WARNING: psVectorStats(): p_psVectorSampleMedian() returned an error.\n"); 1820 } 1751 1821 } 1752 1822 // ************************************************************************ 1753 1823 if (stats->options & PS_STAT_SAMPLE_STDEV) { 1754 p_psVectorSampleMean(inF32, mask, maskVal, stats); 1824 if (0 != p_psVectorSampleMean(inF32, mask, maskVal, stats)) { 1825 psLogMsg(__func__, PS_LOG_WARN, 1826 "WARNING: psVectorStats(): p_psVectorSampleMean() returned an error.\n"); 1827 } 1755 1828 p_psVectorSampleStdev(inF32, mask, maskVal, stats); 1756 1829 } 1757 1830 // ************************************************************************ 1758 1831 if (stats->options & PS_STAT_SAMPLE_QUARTILE) { 1759 p_psVectorSampleQuartiles(inF32, mask, maskVal, stats); 1832 if (false == p_psVectorSampleQuartiles(inF32, mask, maskVal, stats)) { 1833 psLogMsg(__func__, PS_LOG_WARN, 1834 "WARNING: psVectorStats(): p_psVectorSampleQuartiles() returned an error.\n"); 1835 } 1760 1836 } 1761 1837 // Since the various robust stats quantities share much computation, they … … 1765 1841 (stats->options & PS_STAT_ROBUST_MEDIAN) || 1766 1842 (stats->options & PS_STAT_ROBUST_MODE) || 1767 (stats->options & PS_STAT_ROBUST_STDEV) || (stats->options & PS_STAT_ROBUST_QUARTILE)) { 1843 (stats->options & PS_STAT_ROBUST_STDEV) || 1844 (stats->options & PS_STAT_ROBUST_QUARTILE)) { 1768 1845 if (0 != p_psVectorRobustStats(inF32, mask, maskVal, stats)) { 1769 1846 psError(PS_ERR_UNKNOWN, false,
Note:
See TracChangeset
for help on using the changeset viewer.
