Changeset 2269 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Nov 2, 2004, 5:30:30 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
r2268 r2269 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.8 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-11-0 2 19:13:03$11 * @version $Revision: 1.84 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-03 03:30:30 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 403 403 *****************************************************************************/ 404 404 void p_psVectorSampleMedian(const psVector* restrict myVector, 405 const psVector* restrict maskVector, psU32 maskVal, psStats* stats) 405 const psVector* restrict maskVector, 406 psU32 maskVal, 407 psStats* stats) 406 408 { 407 409 psVector* unsortedVector = NULL; // Temporary vector 408 410 psVector* sortedVector = NULL; // Temporary vector 409 psS32 i = 0; // Loop index variable410 psS32 count = 0; // # of points in this mean?411 psS32 nValues = 0; // # of points in vector412 float rangeMin = 0.0; // Exclude data below this413 float rangeMax = 0.0; // Exclude date above this411 psS32 i = 0; // Loop index variable 412 psS32 count = 0; // # of points in this mean? 413 psS32 nValues = 0; // # of points in vector 414 float rangeMin = 0.0; // Exclude data below this 415 float rangeMax = 0.0; // Exclude date above this 414 416 415 417 // Determine how many data points fit inside this min/max range 416 // and are not masked, IFthe maskVector is not NULL>418 // and are not masked, if the maskVector is not NULL> 417 419 nValues = p_psVectorNValues(myVector, maskVector, maskVal, stats); 418 420 … … 551 553 *****************************************************************************/ 552 554 void p_psVectorSampleQuartiles(const psVector* restrict myVector, 553 const psVector* restrict maskVector, psU32 maskVal, psStats* stats) 555 const psVector* restrict maskVector, 556 psU32 maskVal, 557 psStats* stats) 554 558 { 555 559 psVector* unsortedVector = NULL; // Temporary vector 556 560 psVector* sortedVector = NULL; // Temporary vector 557 561 psS32 i = 0; // Loop index variable 558 psS32 count = 0; // # of points in this mean ?562 psS32 count = 0; // # of points in this mean. 559 563 psS32 nValues = 0; // # data points 560 564 float rangeMin = 0.0; // Exclude data below this … … 631 635 *****************************************************************************/ 632 636 void p_psVectorSampleStdev(const psVector* restrict myVector, 633 const psVector* restrict maskVector, psU32 maskVal, psStats* stats) 637 const psVector* restrict maskVector, 638 psU32 maskVal, 639 psStats* stats) 634 640 { 635 641 psS32 i = 0; // Loop index variable … … 713 719 stats 714 720 Returns 715 NULL 716 *****************************************************************************/ 717 void p_psVectorClippedStats(const psVector* restrict myVector, 718 const psVector* restrict maskVector, psU32 maskVal, psStats* stats) 721 0 for success. 722 *****************************************************************************/ 723 int p_psVectorClippedStats(const psVector* restrict myVector, 724 const psVector* restrict maskVector, 725 psU32 maskVal, 726 psStats* stats) 719 727 { 720 728 psS32 i = 0; // Loop index variable … … 726 734 psVector* tmpMask = NULL; // Temporary vector 727 735 728 // En dure that stats->clipIter is within the proper range.736 // Ensure that stats->clipIter is within the proper range. 729 737 if (!((PS_CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <= PS_CLIPPED_NUM_ITER_UB))) { 730 738 psError(__func__, "Unallowed value for clipIter (%d).\n", stats->clipIter); 731 } 732 // Endure that stats->clipSigma is within the proper range. 739 return(-1); 740 } 741 // Ensure that stats->clipSigma is within the proper range. 733 742 if (!((PS_CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <= PS_CLIPPED_SIGMA_UB))) { 734 743 psError(__func__, "Unallowed value for clipSigma (%f).\n", stats->clipSigma); 744 return(-1); 735 745 } 736 746 // We allocate a temporary mask vector since during the iterative … … 798 808 799 809 psFree(tmpMask); 800 } 801 802 void p_psNormalizeVectorF32_0(psVector* myData) 810 return(0); 811 } 812 813 /***************************************************************************** 814 *****************************************************************************/ 815 void p_psNormalizeVectorRangeF32(psVector* myData, 816 float outLow, 817 float outHigh) 803 818 { 804 819 float min = (float)HUGE; … … 815 830 } 816 831 817 // float range = max - min;818 // for (i = 0; i < myData->n; i++) {819 // myData->data.F32[i] = (myData->data.F32[i] - min) / range;820 // }821 832 for (i = 0; i < myData->n; i++) { 822 myData->data.F32[i] = (myData->data.F32[i] - min) / (max - min); 823 } 824 } 825 826 827 828 /***************************************************************************** 829 p_psNormalizeVectorF32(myData): this is a private function which normalizes the 830 elements of a vector to a range between 0.0 and 1.0. 831 832 XXX: how about an arbitrary p_psNormalizeVectorF32(myData, min, max)? 833 *****************************************************************************/ 834 void p_psNormalizeVectorF32(psVector* myData) 833 myData->data.F32[i] = outLow + (myData->data.F32[i] - min) * (outHigh - outLow) / (max - min); 834 } 835 } 836 void p_psNormalizeVectorRangeF64(psVector* myData, 837 float outLow, 838 float outHigh) 835 839 { 836 840 float min = (float)HUGE; … … 840 844 for (i = 0; i < myData->n; i++) { 841 845 if (myData->data.F32[i] < min) { 842 min = myData->data.F 32[i];846 min = myData->data.F64[i]; 843 847 } 844 848 if (myData->data.F32[i] > max) { 845 max = myData->data.F32[i]; 846 } 847 } 848 849 // float range = max - min; 850 // for (i = 0; i < myData->n; i++) { 851 // myData->data.F32[i] = (myData->data.F32[i] - min) / range; 852 // } 849 max = myData->data.F64[i]; 850 } 851 } 852 853 853 for (i = 0; i < myData->n; i++) { 854 myData->data.F32[i] = (myData->data.F32[i] - 0.5 * (min + max)) / 855 (0.5 * (max - min)); 854 myData->data.F64[i] = outLow + (myData->data.F64[i] - min) * (outHigh - outLow) / (max - min); 856 855 } 857 856 } 858 857 859 858 /***************************************************************************** 860 p_psNormalizeVectorF64(myData): this is a private function which normalizes the 861 elements of a vector to a range between -1.0 and 1.0. 862 XXX: 0-1 or -1:1? 863 864 XXX: how about an arbitrary p_psNormalizeVectorF64(myData, min, max)? 865 *****************************************************************************/ 866 void p_psNormalizeVectorF64(psVector* myData) 867 { 868 float min = (double)HUGE; 869 float max = (double)-HUGE; 870 double range = 0.0; 871 psS32 i = 0; 872 873 for (i = 0; i < myData->n; i++) { 874 if (myData->data.F64[i] < min) { 875 min = myData->data.F64[i]; 876 } 877 if (myData->data.F64[i] > max) { 878 max = myData->data.F64[i]; 879 } 880 } 881 882 range = max - min; 883 for (i = 0; i < myData->n; i++) { 884 myData->data.F64[i] = -1.0 + 2.0 * 885 ((myData->data.F64[i] - min) / range); 886 } 887 888 // for (i = 0; i < myData->n; i++) { 889 // myData->data.F64[i] = (myData->data.F64[i] - 0.5 * (min + max)) / 890 // (0.5 * (max - min)); 891 // } 892 } 893 894 // XXX: how about an arbitrary p_psNormalizeVector(myData, min, max)? 895 void p_psNormalizeVector(psVector* myData) 859 psNormalizeVectorRange(myData, low, high): this is a private function which 860 normalizes the elements of a vector to a range between low and high. 861 *****************************************************************************/ 862 void psNormalizeVectorRange(psVector* myData, 863 float low, 864 float high) 896 865 { 897 866 if (myData->type.type == PS_TYPE_F32) { 898 p_psNormalizeVector F32(myData);867 p_psNormalizeVectorRangeF32(myData, low, high); 899 868 } else if (myData->type.type == PS_TYPE_F64) { 900 p_psNormalizeVector F64(myData);869 p_psNormalizeVectorRangeF64(myData, low, high); 901 870 } else { 902 871 psError(__func__, "Unalowable data type.\n"); … … 914 883 915 884 XXX: Terminate when f(x)-getThisValue is within some error tolerance. 885 886 XXX: Solve for X analytically. 916 887 *****************************************************************************/ 917 888 float p_ps1DPolyMedian(psPolynomial1D* myPoly, … … 924 895 float oldMidpoint = 1.0; 925 896 float f = 0.0; 926 927 // printf("p_ps1DPolyMedian(%f, %f, %f) \n", rangeLow, rangeHigh, getThisValue);928 897 929 898 while (numIterations < PS_POLY_MEDIAN_MAX_ITERATIONS) { … … 956 925 and i+1 is used for x[i]). It then determines for what value x does that 957 926 quadratic f(x) = yVal (the input parameter). 927 928 XXX: After you fit the polynomial, solve for X analytically. 958 929 *****************************************************************************/ 959 930 float fitQuadraticSearchForYThenReturnX(psVector *xVec, … … 1034 1005 stats 1035 1006 Returns 1036 NULL1007 0 on success. 1037 1008 *****************************************************************************/ 1038 1009 int p_psVectorRobustStats(const psVector* restrict myVector, … … 1119 1090 tmpStats->clippedStdev / 4.0f); 1120 1091 1121 // The following was necessary to fit a gaussian to the data, since1122 // gaussian functions produce data between 0.0 and 1.0.1123 // p_psNormalizeVectorF32(robustHistogramVector);1124 1125 1092 /************************************************************************** 1126 1093 Determine the median/lower/upper quartile bin numbers. … … 1207 1174 psVector *y = psVectorAlloc(robustHistogramVector->n, PS_TYPE_F32); 1208 1175 1209 p_psNormalizeVector F32_0(robustHistogramVector);1176 p_psNormalizeVectorRange(robustHistogramVector, 0.0, 1.0); 1210 1177 for (i=0;i<robustHistogramVector->n;i++) { 1211 1178 myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32); … … 1620 1587 } 1621 1588 // ************************************************************************ 1622 // XXX: The Stdev calculation requires the mean. Should we assume the1623 // mean has already been calculated? Or should we always calculate it?1624 1589 if (stats->options & PS_STAT_SAMPLE_STDEV) { 1625 1590 p_psVectorSampleMean(inF32, mask, maskVal, stats); … … 1643 1608 1644 1609 if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) { 1645 p_psVectorClippedStats(inF32, mask, maskVal, stats); 1610 if (0 != p_psVectorClippedStats(inF32, mask, maskVal, stats)) { 1611 psError(__func__, "p_psVectorClippedStats() failed.\n"); 1612 } 1646 1613 } 1647 1614 // ************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.
