Changeset 8245 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Aug 8, 2006, 4:26:44 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (78 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r8232 r8245 16 16 * use ->min and ->max (PS_STAT_USE_RANGE) 17 17 * 18 * @version $Revision: 1.18 3$ $Name: not supported by cvs2svn $19 * @date $Date: 2006-08-0 8 23:32:23$18 * @version $Revision: 1.184 $ $Name: not supported by cvs2svn $ 19 * @date $Date: 2006-08-09 02:26:44 $ 20 20 * 21 21 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 110 110 psStats* stats) 111 111 { 112 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);112 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 113 113 114 114 psF32 mean = 0.0; // The mean … … 221 221 stats->sampleMean = mean; 222 222 if (isnan(mean)) { 223 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);223 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 224 224 return false; 225 225 } 226 226 227 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);227 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 228 228 return true; 229 229 } … … 240 240 ) 241 241 { 242 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);242 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 243 243 psF32 max = -PS_MAX_F32; // The calculated maximum 244 244 psF32 min = PS_MAX_F32; // The calculated minimum … … 316 316 stats->min = min; 317 317 } 318 psTrace( __func__, 4, "---- %s(%d) end ----\n", __func__, numValid);318 psTrace("psLib.math", 4, "---- %s(%d) end ----\n", __func__, numValid); 319 319 return numValid; 320 320 } … … 332 332 psStats* stats) 333 333 { 334 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);334 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 335 335 PS_ASSERT_VECTOR_NON_NULL(myVector, false); 336 336 PS_ASSERT_PTR_NON_NULL(stats, false); … … 342 342 (stats->min <= myVector->data.F32[i]) && 343 343 (myVector->data.F32[i] <= stats->max)) { 344 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);344 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 345 345 return true; 346 346 } … … 350 350 if ((stats->min <= myVector->data.F32[i]) && 351 351 (myVector->data.F32[i] <= stats->max)) { 352 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);352 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 353 353 return true; 354 354 } … … 359 359 for (long i = 0; i < myVector->n; i++) { 360 360 if (!(maskVal & maskVector->data.U8[i])) { 361 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);361 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 362 362 return true; 363 363 } … … 365 365 } else { 366 366 if (myVector->n > 0) { 367 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);367 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 368 368 return true; 369 369 } 370 370 } 371 371 } 372 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);372 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 373 373 return(false); 374 374 } … … 385 385 psStats* stats) 386 386 { 387 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);387 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 388 388 389 389 // Allocate temporary vectors for the data. … … 441 441 false, 442 442 _("Failed to sort input data.")); 443 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);443 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 444 444 psFree(vector); 445 445 return false; … … 463 463 464 464 // Return "true" on success. 465 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);465 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 466 466 return true; 467 467 } … … 475 475 psF32 sigma) 476 476 { 477 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);478 psTrace( __func__, 5, "(histogram->nums->n, sigma) is (%d, %.2f\n", (int) histogram->nums->n, sigma);477 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 478 psTrace("psLib.math", 5, "(histogram->nums->n, sigma) is (%d, %.2f\n", (int) histogram->nums->n, sigma); 479 479 PS_ASSERT_PTR_NON_NULL(histogram, NULL); 480 480 PS_ASSERT_PTR_NON_NULL(histogram->bounds, NULL); … … 564 564 PS_VECTOR_PRINT_F32(smooth); 565 565 } 566 psTrace( __func__, 4, "---- %s() end ----\n", __func__);566 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 567 567 return(smooth); 568 568 } … … 586 586 psStats* stats) 587 587 { 588 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);588 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 589 589 590 590 // This procedure requires the mean. If it has not been already … … 597 597 stats->sampleStdev = NAN; 598 598 psLogMsg(__func__, PS_LOG_WARN, "WARNING: vectorSampleStdev(): vectorSampleMean() reported a NAN mean.\n"); 599 psTrace( __func__, 4, "---- %s() end ----\n", __func__);599 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 600 600 return false; 601 601 } … … 680 680 (float)(count - 1)); 681 681 } 682 psTrace( __func__, 4, "---- %s() end ----\n", __func__);682 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 683 683 684 684 return true; … … 704 704 ) 705 705 { 706 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);707 psTrace( __func__, 4, "Trace level is %d\n", psTraceGetLevel(__func__));706 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 707 psTrace("psLib.math", 4, "Trace level is %d\n", psTraceGetLevel(__func__)); 708 708 709 709 // Ensure that stats->clipIter is within the proper range. … … 739 739 stats->clippedMean = NAN; 740 740 stats->clippedStdev = NAN; 741 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);741 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 742 742 psFree(tmpMask); 743 743 psFree(statsTmp); 744 744 return false; 745 745 } 746 psTrace( __func__, 6, "The initial sample median is %f\n", statsTmp->sampleMedian);746 psTrace("psLib.math", 6, "The initial sample median is %f\n", statsTmp->sampleMedian); 747 747 748 748 // 2. Compute the sample standard deviation. … … 752 752 stats->clippedMean = NAN; 753 753 stats->clippedStdev = NAN; 754 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);754 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 755 755 psFree(tmpMask); 756 756 psFree(statsTmp); 757 757 return false; 758 758 } 759 psTrace( __func__, 6, "The initial sample stdev is %f\n", statsTmp->sampleStdev);759 psTrace("psLib.math", 6, "The initial sample stdev is %f\n", statsTmp->sampleStdev); 760 760 761 761 // 3. Use the sample median as the first estimator of the mean X. … … 770 770 for (int iter = 0; iter < stats->clipIter && clipped; iter++) { 771 771 clipped = false; 772 psTrace( __func__, 6, "------------ Iteration %d ------------\n", iter);772 psTrace("psLib.math", 6, "------------ Iteration %d ------------\n", iter); 773 773 // a) Exclude all values x_i for which |x_i - x| > K * stdev 774 774 if (errors) { … … 777 777 fabsf(myVector->data.F32[j] - clippedMean) > stats->clipSigma * errors->data.F32[j]) { 778 778 tmpMask->data.U8[j] = 0xff; 779 psTrace( __func__, 10, "Clipped %d: %f +/- %f\n", j,779 psTrace("psLib.math", 10, "Clipped %d: %f +/- %f\n", j, 780 780 myVector->data.F32[j], errors->data.F32[j]); 781 781 numClipped++; … … 788 788 fabsf(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * clippedStdev)) { 789 789 tmpMask->data.U8[j] = 0xff; 790 psTrace( __func__, 10, "Clipped %d: %f\n", j, myVector->data.F32[j]);790 psTrace("psLib.math", 10, "Clipped %d: %f\n", j, myVector->data.F32[j]); 791 791 numClipped++; 792 792 clipped = true; … … 798 798 vectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp); 799 799 vectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp); 800 psTrace( __func__, 6, "The new sample mean is %f\n", statsTmp->sampleMean);801 psTrace( __func__, 6, "The new sample stdev is %f\n", statsTmp->sampleStdev);800 psTrace("psLib.math", 6, "The new sample mean is %f\n", statsTmp->sampleMean); 801 psTrace("psLib.math", 6, "The new sample stdev is %f\n", statsTmp->sampleStdev); 802 802 803 803 // If the new mean and stdev are NAN, we must exit the loop. … … 821 821 if (stats->options & PS_STAT_CLIPPED_MEAN) { 822 822 stats->clippedMean = clippedMean; 823 psTrace( __func__, 6, "The final clipped mean is %f\n", clippedMean);823 psTrace("psLib.math", 6, "The final clipped mean is %f\n", clippedMean); 824 824 } 825 825 // 8. The last calcuated value of stdev is the clipped stdev. 826 826 if (stats->options & PS_STAT_CLIPPED_STDEV) { 827 827 stats->clippedStdev = clippedStdev; 828 psTrace( __func__, 6, "The final clipped stdev is %f\n", clippedStdev);828 psTrace("psLib.math", 6, "The final clipped stdev is %f\n", clippedStdev); 829 829 } 830 830 831 831 psFree(tmpMask); 832 832 psFree(statsTmp); 833 psTrace( __func__, 4, "---- %s(true) end ----\n", __func__);833 psTrace("psLib.math", 4, "---- %s(true) end ----\n", __func__); 834 834 return true; 835 835 } … … 884 884 ) 885 885 { 886 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);887 psTrace( __func__, 5, "binNum, yVal is (%d, %f)\n", binNum, yVal);886 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 887 psTrace("psLib.math", 5, "binNum, yVal is (%d, %f)\n", binNum, yVal); 888 888 if (psTraceGetLevel(__func__) >= 8) { 889 889 PS_VECTOR_PRINT_F32(xVec); … … 913 913 y->data.F64[1] = yVec->data.F32[binNum]; 914 914 y->data.F64[2] = yVec->data.F32[binNum + 1]; 915 psTrace( __func__, 6, "x vec (orig) is (%f %f %f %f)\n", xVec->data.F32[binNum - 1],915 psTrace("psLib.math", 6, "x vec (orig) is (%f %f %f %f)\n", xVec->data.F32[binNum - 1], 916 916 xVec->data.F32[binNum], xVec->data.F32[binNum+1], xVec->data.F32[binNum+2]); 917 psTrace( __func__, 6, "x data is (%f %f %f)\n", x->data.F64[0], x->data.F64[1], x->data.F64[2]);918 psTrace( __func__, 6, "y data is (%f %f %f)\n", y->data.F64[0], y->data.F64[1], y->data.F64[2]);917 psTrace("psLib.math", 6, "x data is (%f %f %f)\n", x->data.F64[0], x->data.F64[1], x->data.F64[2]); 918 psTrace("psLib.math", 6, "y data is (%f %f %f)\n", y->data.F64[0], y->data.F64[1], y->data.F64[2]); 919 919 920 920 // … … 937 937 psFree(x); 938 938 psFree(y); 939 psTrace( __func__, 5, "---- %s() end ----\n", __func__);939 psTrace("psLib.math", 5, "---- %s() end ----\n", __func__); 940 940 return NAN; 941 941 } … … 949 949 psFree(x); 950 950 psFree(y); 951 psTrace( __func__, 5, "---- %s(NAN) end ----\n", __func__);951 psTrace("psLib.math", 5, "---- %s(NAN) end ----\n", __func__); 952 952 return NAN; 953 953 } 954 psTrace( __func__, 6, "myPoly->coeff[0] is %f\n", myPoly->coeff[0]);955 psTrace( __func__, 6, "myPoly->coeff[1] is %f\n", myPoly->coeff[1]);956 psTrace( __func__, 6, "myPoly->coeff[2] is %f\n", myPoly->coeff[2]);957 psTrace( __func__, 6, "Fitted y vec is (%f %f %f)\n",954 psTrace("psLib.math", 6, "myPoly->coeff[0] is %f\n", myPoly->coeff[0]); 955 psTrace("psLib.math", 6, "myPoly->coeff[1] is %f\n", myPoly->coeff[1]); 956 psTrace("psLib.math", 6, "myPoly->coeff[2] is %f\n", myPoly->coeff[2]); 957 psTrace("psLib.math", 6, "Fitted y vec is (%f %f %f)\n", 958 958 (psF32) psPolynomial1DEval(myPoly, (psF64) x->data.F64[0]), 959 959 (psF32) psPolynomial1DEval(myPoly, (psF64) x->data.F64[1]), 960 960 (psF32) psPolynomial1DEval(myPoly, (psF64) x->data.F64[2])); 961 961 962 psTrace( __func__, 6, "We fit the polynomial, now find x such that f(x) equals %f\n", yVal);962 psTrace("psLib.math", 6, "We fit the polynomial, now find x such that f(x) equals %f\n", yVal); 963 963 tmpFloat = QuadraticInverse(myPoly->coeff[2], myPoly->coeff[1], myPoly->coeff[0], yVal, 964 964 x->data.F64[0], x->data.F64[2]); … … 970 970 psFree(x); 971 971 psFree(y); 972 psTrace( __func__, 5, "---- %s(NAN) end ----\n", __func__);972 psTrace("psLib.math", 5, "---- %s(NAN) end ----\n", __func__); 973 973 return(NAN); 974 974 } … … 990 990 } 991 991 992 psTrace( __func__, 6, "FIT: return %f\n", tmpFloat);992 psTrace("psLib.math", 6, "FIT: return %f\n", tmpFloat); 993 993 psFree(x); 994 994 psFree(y); 995 995 996 psTrace( __func__, 5, "---- %s(%f) end ----\n", __func__, tmpFloat);996 psTrace("psLib.math", 5, "---- %s(%f) end ----\n", __func__, tmpFloat); 997 997 return tmpFloat; 998 998 } … … 1006 1006 ) 1007 1007 { 1008 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);1008 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 1009 1009 PS_ASSERT_VECTOR_NON_NULL(params, NAN); 1010 1010 PS_ASSERT_VECTOR_SIZE(params, 2, NAN); … … 1028 1028 1029 1029 1030 psTrace( __func__, 4, "---- %s() end ----\n", __func__);1030 psTrace("psLib.math", 4, "---- %s() end ----\n", __func__); 1031 1031 return gauss; 1032 1032 } … … 1057 1057 psStats* stats) 1058 1058 { 1059 psTrace( __func__, 4, "---- %s() begin ----\n", __func__);1059 psTrace("psLib.math", 4, "---- %s() begin ----\n", __func__); 1060 1060 if (psTraceGetLevel(__func__) >= 8) { 1061 1061 PS_VECTOR_PRINT_F32(myVector); … … 1085 1085 // Iterate to get the best bin size 1086 1086 for (int iterate = 1; iterate > 0; iterate++) { 1087 psTrace( __func__, 6,1087 psTrace("psLib.math", 6, 1088 1088 "-------------------- Iterating on Bin size. Iteration number %d --------------------\n", 1089 1089 iterate); … … 1098 1098 psFree(statsMinMax); 1099 1099 psFree(mask); 1100 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1100 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1101 1101 return false; 1102 1102 } 1103 psTrace( __func__, 6, "Data min/max is (%.2f, %.2f)\n", min, max);1103 psTrace("psLib.math", 6, "Data min/max is (%.2f, %.2f)\n", min, max); 1104 1104 1105 1105 // If all data points have the same value, then we set the appropiate members of stats and return. 1106 1106 if (fabs(max - min) <= FLT_EPSILON) { 1107 psTrace( __func__, 5, "All data points have the same value: %f.\n", min);1107 psTrace("psLib.math", 5, "All data points have the same value: %f.\n", min); 1108 1108 if (stats->options & PS_STAT_ROBUST_MEDIAN) { 1109 1109 stats->robustMedian = min; … … 1117 1117 psFree(mask); 1118 1118 1119 psTrace( __func__, 4, "---- %s(0) end ----\n", __func__);1119 psTrace("psLib.math", 4, "---- %s(0) end ----\n", __func__); 1120 1120 return false; 1121 1121 } … … 1125 1125 // Set initial bin size to the specified value. 1126 1126 binSize = stats->binsize; 1127 psTrace( __func__, 6, "Setting initial robust bin size to %.2f\n", binSize);1127 psTrace("psLib.math", 6, "Setting initial robust bin size to %.2f\n", binSize); 1128 1128 } else { 1129 1129 // Determine the bin size of the robust histogram, using the pre-defined number of bins 1130 1130 binSize = (max - min) / INITIAL_NUM_BINS; 1131 1131 } 1132 psTrace( __func__, 6, "Initial robust bin size is %.2f\n", binSize);1132 psTrace("psLib.math", 6, "Initial robust bin size is %.2f\n", binSize); 1133 1133 1134 1134 // ADD step 0: Construct the histogram with the specified bin size. NOTE: we can not specify the bin … … 1136 1136 // we get here, we know that binSize != 0.0. 1137 1137 long numBins = (max - min) / binSize; // Number of bins 1138 psTrace( __func__, 6, "Numbins is %d\n", numBins);1139 psTrace( __func__, 6, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max);1138 psTrace("psLib.math", 6, "Numbins is %d\n", numBins); 1139 psTrace("psLib.math", 6, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max); 1140 1140 // Generate the histogram 1141 1141 histogram = psHistogramAlloc(min, max, numBins); … … 1159 1159 // ADD step 2: Find the bin which contains the 50% data point. 1160 1160 totalDataPoints = cumulative->nums->data.F32[numBins - 1]; 1161 psTrace( __func__, 6, "Total data points is %d\n", totalDataPoints);1161 psTrace("psLib.math", 6, "Total data points is %d\n", totalDataPoints); 1162 1162 long binMedian; 1163 1163 if (totalDataPoints/2.0 < cumulative->nums->data.F32[0]) { … … 1175 1175 psFree(cumulative); 1176 1176 psFree(mask); 1177 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1177 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1178 1178 return false; 1179 1179 } 1180 1180 } 1181 psTrace( __func__, 6, "The median bin is %d (%.2f to %.2f)\n", binMedian,1181 psTrace("psLib.math", 6, "The median bin is %d (%.2f to %.2f)\n", binMedian, 1182 1182 cumulative->bounds->data.F32[binMedian], cumulative->bounds->data.F32[binMedian+1]); 1183 1183 … … 1192 1192 psFree(cumulative); 1193 1193 psFree(mask); 1194 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1194 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1195 1195 return false; 1196 1196 } 1197 psTrace( __func__, 6, "Current robust median is %f\n", stats->robustMedian);1197 psTrace("psLib.math", 6, "Current robust median is %f\n", stats->robustMedian); 1198 1198 1199 1199 // ADD step 4: Find the bins which contains the 15.8655% and 84.1345% data points. … … 1217 1217 } 1218 1218 } 1219 psTrace( __func__, 6, "The 15.8655%% and 84.1345%% data point bins are (%d, %d).\n",1219 psTrace("psLib.math", 6, "The 15.8655%% and 84.1345%% data point bins are (%d, %d).\n", 1220 1220 binLo, binHi); 1221 psTrace( __func__, 6, "binLo midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binLo));1222 psTrace( __func__, 6, "binHi midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binHi));1221 psTrace("psLib.math", 6, "binLo midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binLo)); 1222 psTrace("psLib.math", 6, "binHi midpoint is %f\n", PS_BIN_MIDPOINT(cumulative, binHi)); 1223 1223 1224 1224 if ((binLo < 0) || (binHi < 0)) { … … 1228 1228 psFree(cumulative); 1229 1229 psFree(mask); 1230 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1230 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1231 1231 return false; 1232 1232 } … … 1244 1244 float binHiF32 = fitQuadraticSearchForYThenReturnX(cumulative->bounds, cumulative->nums, binHi, 1245 1245 totalDataPoints * 0.841345f); 1246 psTrace( __func__, 6, "The exact 15.8655%% and 84.1345%% data point positions are: (%f, %f)\n",1246 psTrace("psLib.math", 6, "The exact 15.8655%% and 84.1345%% data point positions are: (%f, %f)\n", 1247 1247 binLoF32, binHiF32); 1248 1248 #else 1249 1249 // This code basically interpolates to find the positions exactly. 1250 psTrace( __func__, 6, "binLo is %d. Nums at that bin and the next are (%.2f, %.2f)\n",1250 psTrace("psLib.math", 6, "binLo is %d. Nums at that bin and the next are (%.2f, %.2f)\n", 1251 1251 binLo, cumulative->nums->data.F32[binLo], cumulative->nums->data.F32[binLo+1]); 1252 psTrace( __func__, 6, "binHi is %d. Nums at that bin and the next are (%.2f, %.2f)\n",1252 psTrace("psLib.math", 6, "binHi is %d. Nums at that bin and the next are (%.2f, %.2f)\n", 1253 1253 binHi, cumulative->nums->data.F32[binHi], cumulative->nums->data.F32[binHi+1]); 1254 1254 … … 1266 1266 float base = cumulative->bounds->data.F32[binLo]; 1267 1267 float binLoF32 = base + (deltaBounds / deltaNums) * percentNums; // Value for the 15.8655% mark 1268 psTrace( __func__, 6,1268 psTrace("psLib.math", 6, 1269 1269 "(base, deltaBounds, deltaNums, prevPixels, percentNums) is (%.2f %.2f %.2f %.2f %.2f)\n", 1270 1270 base, deltaBounds, deltaNums, prevPixels, percentNums); … … 1281 1281 base = cumulative->bounds->data.F32[binHi]; 1282 1282 float binHiF32 = base + (deltaBounds / deltaNums) * percentNums; // Value for the 84.1345% mark 1283 psTrace( __func__, 6,1283 psTrace("psLib.math", 6, 1284 1284 "(base, deltaBounds, deltaNums, prevPixels, percentNums) is (%.2f %.2f %.2f %.2f %.2f)\n", 1285 1285 base, deltaBounds, deltaNums, prevPixels, percentNums); 1286 psTrace( __func__, 6,1286 psTrace("psLib.math", 6, 1287 1287 "The exact 15.8655 and 84.1345 percent data point positions are: (%f, %f)\n", 1288 1288 binLoF32, binHiF32); … … 1291 1291 // ADD step 5: Determine SIGMA as 1/2 of the distance between these positions. 1292 1292 sigma = (binHiF32 - binLoF32) / 2.0; 1293 psTrace( __func__, 6, "The current sigma is %f.\n", sigma);1293 psTrace("psLib.math", 6, "The current sigma is %f.\n", sigma); 1294 1294 stats->robustStdev = sigma; 1295 1295 … … 1297 1297 // than 25 bins from the median, recalculate the bin size, and perform the algorithm again. 1298 1298 if (sigma < (2 * binSize)) { 1299 psTrace( __func__, 6, "*************: Do another iteration (%f %f).\n", sigma, binSize);1299 psTrace("psLib.math", 6, "*************: Do another iteration (%f %f).\n", sigma, binSize); 1300 1300 long maskLo = PS_MAX(0, (binMedian - 25)); // Low index for masking region 1301 1301 long maskHi = PS_MIN(histogram->bounds->n - 1, (binMedian + 25)); // High index for masking 1302 1302 psF32 medianLo = histogram->bounds->data.F32[maskLo]; // Value at low index 1303 1303 psF32 medianHi = histogram->bounds->data.F32[maskHi]; // Value at high index 1304 psTrace( __func__, 6, "Masking data more than 25 bins from the median\n");1305 psTrace( __func__, 6,1304 psTrace("psLib.math", 6, "Masking data more than 25 bins from the median\n"); 1305 psTrace("psLib.math", 6, 1306 1306 "The median is at bin number %d. We mask bins outside the bin range (%d:%d)\n", 1307 1307 binMedian, maskLo, maskHi); 1308 psTrace( __func__, 6, "Masking data outside (%f %f)\n", medianLo, medianHi);1308 psTrace("psLib.math", 6, "Masking data outside (%f %f)\n", medianLo, medianHi); 1309 1309 for (long i = 0 ; i < myVector->n ; i++) { 1310 1310 if ((myVector->data.F32[i] < medianLo) || (myVector->data.F32[i] > medianHi)) { 1311 1311 mask->data.U8[i] = 0xff; 1312 psTrace( __func__, 6, "Masking element %d is %f\n", i, myVector->data.F32[i]);1312 psTrace("psLib.math", 6, "Masking element %d is %f\n", i, myVector->data.F32[i]); 1313 1313 } 1314 1314 } … … 1318 1318 } else { 1319 1319 // We've got the bin size correct now 1320 psTrace( __func__, 6, "*************: No more iteration. sigma is %f\n", sigma);1320 psTrace("psLib.math", 6, "*************: No more iteration. sigma is %f\n", sigma); 1321 1321 iterate = -1; 1322 1322 } … … 1347 1347 psFree(cumulative); 1348 1348 psFree(mask); 1349 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1349 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1350 1350 return false; 1351 1351 } 1352 psTrace( __func__, 6, "The 25-percent and 75-precent data point bins are (%d, %d).\n", binLo25, binHi25);1352 psTrace("psLib.math", 6, "The 25-percent and 75-precent data point bins are (%d, %d).\n", binLo25, binHi25); 1353 1353 1354 1354 // ADD step 8: Interpolate to find these two positions exactly: these are the upper and lower quartile … … 1365 1365 psFree(statsMinMax); 1366 1366 psFree(mask); 1367 psTrace( __func__, 4, "---- %s(1) end ----\n", __func__);1367 psTrace("psLib.math", 4, "---- %s(1) end ----\n", __func__); 1368 1368 return false; 1369 1369 } … … 1371 1371 stats->robustLQ = binLo25F32; 1372 1372 stats->robustUQ = binHi25F32; 1373 psTrace( __func__, 6, "The 25 and 75 percent data point exact positions are (%f, %f).\n",1373 psTrace("psLib.math", 6, "The 25 and 75 percent data point exact positions are (%f, %f).\n", 1374 1374 binLo25F32, binHi25F32); 1375 1375 long N50 = 0; … … 1381 1381 } 1382 1382 stats->robustN50 = N50; 1383 psTrace( __func__, 6, "The robustN50 is %d.\n", N50);1383 psTrace("psLib.math", 6, "The robustN50 is %d.\n", N50); 1384 1384 1385 1385 … … 1405 1405 psFree(statsMinMax); 1406 1406 psFree(mask); 1407 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1407 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1408 1408 return false; 1409 1409 } … … 1411 1411 // Calculate the number of bins. 1412 1412 long numBins = (max - min) / newBinSize; 1413 psTrace( __func__, 6, "The new min/max values are (%f, %f).\n", min, max);1414 psTrace( __func__, 6, "The new bin size is %f.\n", newBinSize);1415 psTrace( __func__, 6, "The numBins is %d\n", numBins);1413 psTrace("psLib.math", 6, "The new min/max values are (%f, %f).\n", min, max); 1414 psTrace("psLib.math", 6, "The new bin size is %f.\n", newBinSize); 1415 psTrace("psLib.math", 6, "The numBins is %d\n", numBins); 1416 1416 1417 1417 psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers) … … 1448 1448 psFree(histogram); 1449 1449 psFree(mask); 1450 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1450 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1451 1451 return false; 1452 1452 } … … 1460 1460 } 1461 1461 } 1462 psTrace( __func__, 6, "The peak bin is %d, with %f data.n", binNum, binMaxNums);1462 psTrace("psLib.math", 6, "The peak bin is %d, with %f data.n", binNum, binMaxNums); 1463 1463 1464 1464 // Fit a Gaussian to the bins in the range 20 sigma of the robust histogram median. … … 1480 1480 psFree(histogram); 1481 1481 psFree(mask); 1482 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1482 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1483 1483 return false; 1484 1484 } … … 1511 1511 psFree(histogram); 1512 1512 psFree(statsMinMax); 1513 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1513 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1514 1514 return false; 1515 1515 } … … 1537 1537 psFree(params); 1538 1538 psFree(mask); 1539 psTrace( __func__, 4, "---- %s(false) end ----\n", __func__);1539 psTrace("psLib.math", 4, "---- %s(false) end ----\n", __func__); 1540 1540 return false; 1541 1541 } … … 1546 1546 // The fitted mean is the Gaussian mean. 1547 1547 stats->fittedMean = params->data.F32[0]; 1548 psTrace( __func__, 6, "The fitted mean is %f.\n", params->data.F32[0]);1548 psTrace("psLib.math", 6, "The fitted mean is %f.\n", params->data.F32[0]); 1549 1549 1550 1550 // The fitted standard deviation, SIGMA_r is determined by subtracting the smoothing scale in 1551 1551 // quadrature: SIGMA_r^2 = SIGMA^2 - sigma_s^2 1552 1552 stats->fittedStdev = sqrt(PS_SQR(params->data.F32[1]) - PS_SQR(newBinSize)); 1553 psTrace( __func__, 6, "The fitted stdev is %f.\n", stats->fittedStdev);1553 psTrace("psLib.math", 6, "The fitted stdev is %f.\n", stats->fittedStdev); 1554 1554 1555 1555 // Clean up after fitting … … 1564 1564 psFree(mask); 1565 1565 1566 psTrace( __func__, 4, "---- %s(0) end ----\n", __func__);1566 psTrace("psLib.math", 4, "---- %s(0) end ----\n", __func__); 1567 1567 return true; 1568 1568 } … … 1587 1587 psStats* psStatsAlloc(psStatsOptions options) 1588 1588 { 1589 psTrace( __func__, 3,"---- %s() begin ----\n", __func__);1589 psTrace("psLib.math", 3,"---- %s() begin ----\n", __func__); 1590 1590 psStats* newStruct = NULL; 1591 1591 … … 1616 1616 newStruct->options = options; 1617 1617 1618 psTrace( __func__, 3, "---- %s() end ----\n", __func__);1618 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 1619 1619 return (newStruct); 1620 1620 } … … 1645 1645 psHistogram* psHistogramAlloc(float lower, float upper, int n) 1646 1646 { 1647 psTrace( __func__, 3, "---- %s() begin ----\n", __func__);1648 psTrace( __func__, 5, "(lower, upper, n) is (%f, %f, %d)\n", lower, upper, n);1647 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 1648 psTrace("psLib.math", 5, "(lower, upper, n) is (%f, %f, %d)\n", lower, upper, n); 1649 1649 PS_ASSERT_INT_POSITIVE(n, NULL); 1650 1650 PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(upper, lower, NULL); … … 1678 1678 newHist->uniform = true; 1679 1679 1680 psTrace( __func__, 3, "---- %s() end ----\n", __func__);1680 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 1681 1681 return newHist; 1682 1682 } … … 1693 1693 psHistogram* psHistogramAllocGeneric(const psVector* bounds) 1694 1694 { 1695 psTrace( __func__, 3, "---- %s() begin ----\n", __func__);1695 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 1696 1696 PS_ASSERT_VECTOR_NON_NULL(bounds, NULL); 1697 1697 PS_ASSERT_VECTOR_TYPE(bounds, PS_TYPE_F32, NULL); … … 1721 1721 newHist->uniform = false; 1722 1722 1723 psTrace( __func__, 3, "---- %s() end ----\n", __func__);1723 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 1724 1724 return (newHist); 1725 1725 } … … 1757 1757 ) 1758 1758 { 1759 psTrace( __func__, 3, "---- %s() begin ----\n", __func__);1759 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 1760 1760 PS_ASSERT_PTR_NON_NULL(out, false); 1761 1761 PS_ASSERT_PTR_NON_NULL(out->bounds, false); … … 1794 1794 if (boxcarLeftBinNum == boxcarRightBinNum) { 1795 1795 out->nums->data.F32[binNum] += 1.0; 1796 psTrace( __func__, 3, "---- %s(true) end ----\n", __func__);1796 psTrace("psLib.math", 3, "---- %s(true) end ----\n", __func__); 1797 1797 return true; 1798 1798 } … … 1813 1813 (boxcarRight - out->bounds->data.F32[boxcarRightBinNum]) / boxcarWidth; 1814 1814 1815 psTrace( __func__, 3, "---- %s(true) end ----\n", __func__);1815 psTrace("psLib.math", 3, "---- %s(true) end ----\n", __func__); 1816 1816 return true; 1817 1817 } … … 1838 1838 psMaskType maskVal) 1839 1839 { 1840 psTrace( __func__, 3, "---- %s() begin ----\n", __func__);1840 psTrace("psLib.math", 3, "---- %s() begin ----\n", __func__); 1841 1841 PS_ASSERT_PTR_NON_NULL(out, NULL); 1842 1842 PS_ASSERT_VECTOR_NON_NULL(out->bounds, NULL); … … 1933 1933 psFree(errorsF32); 1934 1934 1935 psTrace( __func__, 3, "---- %s() end ----\n", __func__);1935 psTrace("psLib.math", 3, "---- %s() end ----\n", __func__); 1936 1936 return (out); 1937 1937 } … … 1959 1959 psMaskType maskVal) 1960 1960 { 1961 psTrace( __func__, 3,"---- %s() begin ----\n", __func__);1961 psTrace("psLib.math", 3,"---- %s() begin ----\n", __func__); 1962 1962 PS_ASSERT_PTR_NON_NULL(stats, NULL); 1963 1963 PS_ASSERT_VECTOR_NON_NULL(in, NULL); … … 2039 2039 psFree(inF32); 2040 2040 psFree(errorsF32); 2041 psTrace( __func__, 3,"---- %s(NULL) end ----\n", __func__);2041 psTrace("psLib.math", 3,"---- %s(NULL) end ----\n", __func__); 2042 2042 return(NULL); 2043 2043 } … … 2063 2063 psFree(errorsF32); 2064 2064 psFree(maskU8); 2065 psTrace( __func__, 3,"---- %s() end ----\n", __func__);2065 psTrace("psLib.math", 3,"---- %s() end ----\n", __func__); 2066 2066 return (stats); 2067 2067 }
Note:
See TracChangeset
for help on using the changeset viewer.
