Changeset 3349 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Mar 1, 2005, 11:03:25 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r3348 r3349 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.11 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-03-01 21:0 2:21$11 * @version $Revision: 1.115 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-03-01 21:03:25 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1002 1002 -1: error 1003 1003 -2: warning 1004 1005 XXX: Create a new psStats object for the sample mean and sample stdev. 1006 1007 XXX: Do we really need to calculate median and mean? 1008 1009 XXX: Use static vectors for tmpMask. 1004 1010 *****************************************************************************/ 1005 1011 psS32 p_psVectorClippedStats(const psVector* myVector, … … 1013 1019 psF32 clippedMean = 0.0; // self-explanatory 1014 1020 psF32 clippedStdev = 0.0; // self-explanatory 1015 psF32 oldStanMean = 0.0; // Temporary variable1016 psF32 oldStanStdev = 0.0; // Temporary variable1017 1021 psVector* tmpMask = NULL; // Temporary vector 1022 psStats *statsTmp = NULL; 1018 1023 1019 1024 // Ensure that stats->clipIter is within the proper range. … … 1026 1031 PS_CLIPPED_SIGMA_LB, 1027 1032 PS_CLIPPED_SIGMA_UB, -1); 1033 1034 if (statsTmp == NULL) { 1035 statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 1036 p_psMemSetPersistent(statsTmp, true); 1037 } 1028 1038 1029 1039 // We allocate a temporary mask vector since during the iterative … … 1040 1050 } 1041 1051 // 1. Compute the sample median. 1042 p_psVectorSampleMedian(myVector, maskVector, maskVal, stats );1043 if (isnan(stats ->sampleMedian)) {1052 p_psVectorSampleMedian(myVector, maskVector, maskVal, statsTmp); 1053 if (isnan(statsTmp->sampleMedian)) { 1044 1054 psLogMsg(__func__, PS_LOG_WARN, "Call to p_psVectorSampleMedian returned NAN\n"); 1045 1055 stats->clippedMean = NAN; … … 1049 1059 1050 1060 // 2. Compute the sample standard deviation. 1051 p_psVectorSampleStdev(myVector, errors, maskVector, maskVal, stats );1052 if (isnan(stats ->sampleStdev)) {1061 p_psVectorSampleStdev(myVector, errors, maskVector, maskVal, statsTmp); 1062 if (isnan(statsTmp->sampleStdev)) { 1053 1063 psLogMsg(__func__, PS_LOG_WARN, "Call to p_psVectorSampleStdev returned NAN\n"); 1054 1064 stats->clippedMean = NAN; … … 1058 1068 1059 1069 // 3. Use the sample median as the first estimator of the mean X. 1060 clippedMean = stats->sampleMean; 1061 1070 clippedMean = statsTmp->sampleMean; 1062 1071 // 4. Use the sample stdev as the first estimator of the mean stdev. 1063 clippedStdev = stats->sampleStdev; 1064 1065 // Must save the old sampleMean and sampleStdev since the following code 1066 // block overwrites them. 1067 oldStanMean = stats->sampleMean; 1068 oldStanStdev = stats->sampleStdev; 1072 clippedStdev = statsTmp->sampleStdev; 1069 1073 1070 1074 // 5. Repeat N times: … … 1073 1077 if (errors != NULL) { 1074 1078 for (j = 0; j < myVector->n; j++) { 1075 if (fabs(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * errors->data.F32[j])) { 1076 tmpMask->data.U8[i] = 0xff; 1079 if (fabs(myVector->data.F32[j] - clippedMean) > 1080 (stats->clipSigma * errors->data.F32[j])) { 1081 tmpMask->data.U8[j] = 0xff; 1077 1082 } 1078 1083 } 1079 1084 } else { 1080 1085 for (j = 0; j < myVector->n; j++) { 1081 if (fabs(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * clippedStdev)) { 1082 tmpMask->data.U8[i] = 0xff; 1086 if (fabs(myVector->data.F32[j] - clippedMean) > 1087 (stats->clipSigma * clippedStdev)) { 1088 tmpMask->data.U8[j] = 0xff; 1083 1089 } 1084 1090 } … … 1086 1092 1087 1093 // b) compute new mean and stdev 1088 p_psVectorSampleMean(myVector, errors, tmpMask, maskVal, stats );1089 p_psVectorSampleStdev(myVector, errors, tmpMask, maskVal, stats );1094 p_psVectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp); 1095 p_psVectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp); 1090 1096 1091 1097 // If the new mean and stdev are not NAN, then we use them. 1092 1098 // Otherwise, keep the old ones, and exit the loop. 1093 if (! (isnan(stats ->sampleMean) || isnan(stats->sampleStdev))) {1094 clippedMean = stats ->sampleMean;1095 clippedStdev = stats ->sampleStdev;1096 1099 if (! (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev))) { 1100 clippedMean = statsTmp->sampleMean; 1101 clippedStdev = statsTmp->sampleStdev; 1102 } else { 1097 1103 // Exit loop 1104 // Should we throw an error or warning here? 1098 1105 i = stats->clipIter; 1099 1106 } 1100 1107 } 1101 1102 stats->sampleMean = oldStanMean;1103 stats->sampleStdev = oldStanStdev;1104 1108 1105 1109 // 7. The last calcuated value of x is the cliped mean. … … 2240 2244 // XXX: Different conditions for return -1 and -2? 2241 2245 if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) { 2242 if (-1 > p_psVectorClippedStats(inF32, errorsF32, mask, maskVal, stats)) { 2246 psS32 rc = p_psVectorClippedStats(inF32, errorsF32, mask, maskVal, stats); 2247 if (-1 == rc) { 2243 2248 psError(PS_ERR_UNKNOWN, false, 2244 2249 "Failed to calculate clipped statistics for input psVector.\n"); 2245 2250 stats->clippedMean = NAN; 2246 2251 stats->clippedStdev = NAN; 2247 } else if (-2 == p_psVectorClippedStats(inF32, errorsF32, mask, maskVal, stats)) {2252 } else if (-2 == rc) { 2248 2253 psLogMsg(__func__, PS_LOG_WARN, "Failed to calculate clipped statistics for input psVector."); 2249 2254 stats->clippedMean = NAN;
Note:
See TracChangeset
for help on using the changeset viewer.
