Changeset 3350 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Mar 1, 2005, 11:20:51 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r3349 r3350 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.11 5$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-03-01 21: 03:25$11 * @version $Revision: 1.116 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-03-01 21:20:51 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1003 1003 -2: warning 1004 1004 1005 XXX: Create a new psStats object for the sample mean and sample stdev.1006 1007 1005 XXX: Do we really need to calculate median and mean? 1008 1006 … … 1015 1013 psStats* stats) 1016 1014 { 1017 psS32 i = 0; // Loop index variable1018 psS32 j = 0; // Loop index variable1019 1015 psF32 clippedMean = 0.0; // self-explanatory 1020 1016 psF32 clippedStdev = 0.0; // self-explanatory 1021 psVector* tmpMask = NULL; // Temporary vector 1022 psStats *statsTmp = NULL; 1017 psVector* tmpMask = NULL; // Temporary vector for masks during iterations. 1018 psStats *statsTmp = NULL; // Temporary psStats struct. 1019 psS32 rc = 0; // Return code. 1023 1020 1024 1021 // Ensure that stats->clipIter is within the proper range. … … 1032 1029 PS_CLIPPED_SIGMA_UB, -1); 1033 1030 1031 // Allocate a psStats structure for calculating the mean, median, and 1032 // stdev. 1034 1033 if (statsTmp == NULL) { 1035 1034 statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN); … … 1045 1044 // mask vector with those values. 1046 1045 if (maskVector != NULL) { 1047 for ( i = 0; i < tmpMask->n; i++) {1046 for (psS32 i = 0; i < tmpMask->n; i++) { 1048 1047 tmpMask->data.U8[i] = maskVector->data.U8[i]; 1049 1048 } 1050 1049 } 1050 1051 1051 // 1. Compute the sample median. 1052 1052 p_psVectorSampleMedian(myVector, maskVector, maskVal, statsTmp); … … 1069 1069 // 3. Use the sample median as the first estimator of the mean X. 1070 1070 clippedMean = statsTmp->sampleMean; 1071 1071 1072 // 4. Use the sample stdev as the first estimator of the mean stdev. 1072 1073 clippedStdev = statsTmp->sampleStdev; 1073 1074 1074 // 5. Repeat N times:1075 for ( i = 0; i < stats->clipIter; i++) {1075 // 5. Repeat N (stats->clipIter) times: 1076 for (psS32 iter = 0; iter < stats->clipIter; iter++) { 1076 1077 // a) Exclude all values x_i for which |x_i - x| > K * stdev 1077 1078 if (errors != NULL) { 1078 for ( j = 0; j < myVector->n; j++) {1079 for (psS32 j = 0; j < myVector->n; j++) { 1079 1080 if (fabs(myVector->data.F32[j] - clippedMean) > 1080 1081 (stats->clipSigma * errors->data.F32[j])) { … … 1083 1084 } 1084 1085 } else { 1085 for ( j = 0; j < myVector->n; j++) {1086 for (psS32 j = 0; j < myVector->n; j++) { 1086 1087 if (fabs(myVector->data.F32[j] - clippedMean) > 1087 1088 (stats->clipSigma * clippedStdev)) { … … 1095 1096 p_psVectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp); 1096 1097 1097 // If the new mean and stdev are not NAN, then we use them. 1098 // Otherwise, keep the old ones, and exit the loop. 1099 if (! (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev))) { 1098 // If the new mean and stdev are NAN, we must exit the loop. 1099 // Otherwise, use the new results and continue. 1100 if (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev)) { 1101 // Exit loop. XXX: Should we throw an error or warning here? 1102 iter = stats->clipIter; 1103 rc = -1; 1104 } else { 1100 1105 clippedMean = statsTmp->sampleMean; 1101 1106 clippedStdev = statsTmp->sampleStdev; 1102 } else {1103 // Exit loop1104 // Should we throw an error or warning here?1105 i = stats->clipIter;1106 1107 } 1107 1108 } … … 1117 1118 1118 1119 psFree(tmpMask); 1119 return( 0);1120 return(rc); 1120 1121 } 1121 1122
Note:
See TracChangeset
for help on using the changeset viewer.
