Changeset 27334
- Timestamp:
- Mar 18, 2010, 1:28:21 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r26641 r27334 751 751 psTrace(TRACE, 6, "-------------------- Iterating on Bin size. Iteration number %d --------------------\n", iterate); 752 752 753 if (iterate >= PS_ROBUST_MAX_ITERATIONS) {754 // This occurs when a large number of the values are identical --- a bin size cannot be found755 // that will spread out the distribution. Therefore, set what we can, and fall over756 // gracefully.757 COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);758 goto escape;759 }753 if (iterate >= PS_ROBUST_MAX_ITERATIONS) { 754 // This occurs when a large number of the values are identical --- a bin size cannot be found 755 // that will spread out the distribution. Therefore, set what we can, and fall over 756 // gracefully. 757 COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS); 758 goto escape; 759 } 760 760 761 761 // Get the minimum and maximum values … … 823 823 } 824 824 825 // perversity check: if most of the values land in a single bin, then we probably826 // have a perverse case (eg, small number of points at extremely large / small827 // values; nearly bi-modal distribution). if so, keep only points within 5? 10?828 // bins of that excess bin:829 int nMaxBin = 0;830 int iMaxBin = 0;825 // perversity check: if most of the values land in a single bin, then we probably 826 // have a perverse case (eg, small number of points at extremely large / small 827 // values; nearly bi-modal distribution). if so, keep only points within 5? 10? 828 // bins of that excess bin: 829 int nMaxBin = 0; 830 int iMaxBin = 0; 831 831 for (long i = 1; i < histogram->nums->n; i++) { 832 if (histogram->nums->data.F32[i] > nMaxBin) {833 nMaxBin = histogram->nums->data.F32[i];834 iMaxBin = i;835 }836 } 837 if (nMaxBin > numValid / 2) {838 float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize;839 float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize;840 int nInvalid = 0;841 for (long i = 0; i < myVector->n; i++) {842 // skip the already-masked values843 if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;844 bool invalid = false;845 invalid |= (myVector->data.F32[i] <= minKeep);846 invalid |= (myVector->data.F32[i] >= maxKeep);847 invalid |= (!isfinite(myVector->data.F32[i]));848 if (!invalid) continue;849 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;850 nInvalid ++;851 } 852 853 if (nInvalid) {854 psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);855 psFree(histogram);856 psFree(cumulative);857 histogram = NULL;858 cumulative = NULL;859 continue;860 }861 // if we did not mask anything, give up.862 }832 if (histogram->nums->data.F32[i] > nMaxBin) { 833 nMaxBin = histogram->nums->data.F32[i]; 834 iMaxBin = i; 835 } 836 } 837 if (nMaxBin > numValid / 2) { 838 float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize; 839 float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize; 840 int nInvalid = 0; 841 for (long i = 0; i < myVector->n; i++) { 842 // skip the already-masked values 843 if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue; 844 bool invalid = false; 845 invalid |= (myVector->data.F32[i] <= minKeep); 846 invalid |= (myVector->data.F32[i] >= maxKeep); 847 invalid |= (!isfinite(myVector->data.F32[i])); 848 if (!invalid) continue; 849 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal; 850 nInvalid ++; 851 } 852 853 if (nInvalid) { 854 psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid); 855 psFree(histogram); 856 psFree(cumulative); 857 histogram = NULL; 858 cumulative = NULL; 859 continue; 860 } 861 // if we did not mask anything, give up. 862 } 863 863 864 864 // ADD step 1: Convert the specific histogram to a cumulative histogram … … 1873 1873 COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n"); 1874 1874 psFree(statsMinMax); 1875 psFree(histogram); 1875 1876 goto escape; 1876 1877 } … … 1942 1943 1943 1944 if (!status) { 1944 psErrorClear();1945 psErrorClear(); 1945 1946 COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n"); 1946 1947 psFree(poly); … … 2032 2033 2033 2034 if (!status) { 2034 psErrorClear();2035 psErrorClear(); 2035 2036 COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n"); 2036 2037 psFree(poly);
Note:
See TracChangeset
for help on using the changeset viewer.
