Changeset 6270
- Timestamp:
- Jan 31, 2006, 4:07:24 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r6215 r6270 22 22 * 23 23 * 24 * @version $Revision: 1.16 3$ $Name: not supported by cvs2svn $25 * @date $Date: 2006-0 1-26 23:49:11$24 * @version $Revision: 1.164 $ $Name: not supported by cvs2svn $ 25 * @date $Date: 2006-02-01 02:07:24 $ 26 26 * 27 27 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1644 1644 } 1645 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1646 1738 /****************************************************************************** 1647 1739 p_psVectorRobustStats(myVector, maskVector, maskVal, stats): This is the new … … 1662 1754 XXX: Review and ensure that all memory is free'ed at premature exits. 1663 1755 *****************************************************************************/ 1756 #define INITIAL_NUM_BINS 1000.0 1664 1757 psS32 p_psVectorRobustStats(const psVector* myVector, 1665 1758 const psVector* errors, … … 1697 1790 1698 1791 while (iterate > 0) { 1699 psTrace(__func__, 6, " Iterating on Bin size.\n");1792 psTrace(__func__, 6, "-------------------- Iterating on Bin size. Iteration number %d --------------------\n", iterate); 1700 1793 psF32 binSize = 0.0; 1701 1794 if ((iterate == 1) && (stats->options & PS_STAT_USE_BINSIZE)) { … … 1717 1810 return(1); 1718 1811 } 1719 psTrace(__func__, 6, "Data min/ma nis (%.2f, %.2f)\n", tmpStatsMinMax->min, tmpStatsMinMax->max);1720 binSize = (tmpStatsMinMax->max - tmpStatsMinMax->min) / 1000.0f;1812 psTrace(__func__, 6, "Data min/max is (%.2f, %.2f)\n", tmpStatsMinMax->min, tmpStatsMinMax->max); 1813 binSize = (tmpStatsMinMax->max - tmpStatsMinMax->min) / INITIAL_NUM_BINS; 1721 1814 psTrace(__func__, 6, "Robust bin size is %.2f\n", binSize); 1722 1815 } … … 1756 1849 numBins = (psS32)((tmpStatsMinMax->max - tmpStatsMinMax->min) / binSize); 1757 1850 psTrace(__func__, 6, "Numbins is %d\n", numBins); 1851 psTrace(__func__, 6, "Creating a robust histogram from data range (%.2f - %.2f)\n", tmpStatsMinMax->min, tmpStatsMinMax->max); 1758 1852 robustHistogram = psHistogramAlloc(tmpStatsMinMax->min, tmpStatsMinMax->max, numBins); 1759 1853 cumulativeRobustHistogram = psHistogramAlloc(tmpStatsMinMax->min, tmpStatsMinMax->max, numBins); … … 1792 1886 } else { 1793 1887 tmpScalar->data.F32 = totalDataPoints/2.0; 1794 binMedian = p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);1888 binMedian = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar); 1795 1889 if (binMedian < 0) { 1796 1890 psError(PS_ERR_UNKNOWN, false, "Failed to calculate the 50 precent data point (%d).\n", binMedian); … … 1804 1898 } 1805 1899 } 1806 psTrace(__func__, 6, "The median bin is %d \n", binMedian);1900 psTrace(__func__, 6, "The median bin is %d (%.2f to %.2f)\n", binMedian, cumulativeRobustHistogram->bounds->data.F32[binMedian], cumulativeRobustHistogram->bounds->data.F32[binMedian+1]); 1807 1901 1808 1902 // … … 1839 1933 } else { 1840 1934 // NOTE: the (+1) here is because of the way p_psVectorBinDisect is defined. 1841 binHi = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);1935 binHi = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar); 1842 1936 if (binHi > cumulativeRobustHistogram->nums->n-1) { 1843 1937 binHi = cumulativeRobustHistogram->nums->n-1; 1844 1938 } 1845 1939 } 1846 psTrace(__func__, 6, "The 15.8655 % and 84.1345%data point bins are (%d, %d).\n", binLo, binHi);1940 psTrace(__func__, 6, "The 15.8655-percent and 84.1345-percent data point bins are (%d, %d).\n", binLo, binHi); 1847 1941 psTrace(__func__, 6, "binLo midpoint is %f\n", PS_BIN_MIDPOINT(cumulativeRobustHistogram, binLo)); 1848 1942 psTrace(__func__, 6, "binHi midpoint is %f\n", PS_BIN_MIDPOINT(cumulativeRobustHistogram, binHi)); … … 1920 2014 if (sigma < (2 * binSize)) { 1921 2015 psTrace(__func__, 6, "*************: Do another iteration (%f %f).\n", sigma, binSize); 1922 psF32 medianLo = robustHistogram->bounds->data.F32[binMedian - 25]; 1923 psF32 medianHi = robustHistogram->bounds->data.F32[binMedian + 25]; 2016 psF32 medianLo; 2017 psF32 medianHi; 2018 if ((binMedian - 25) > 0) { 2019 medianLo = robustHistogram->bounds->data.F32[binMedian - 25]; 2020 } else { 2021 medianLo = robustHistogram->bounds->data.F32[0]; 2022 } 2023 if ((binMedian + 25) < robustHistogram->bounds->n) { 2024 medianHi = robustHistogram->bounds->data.F32[binMedian + 25]; 2025 } else { 2026 medianHi = robustHistogram->bounds->data.F32[robustHistogram->bounds->n - 1]; 2027 } 2028 2029 psTrace(__func__, 6, "Masking data more than 25 bins from the median (%.2f)\n", stats->robustMedian); 2030 psTrace(__func__, 6, "The median is at bin number %d. We mask bins outside the bin range (%d:%d)\n", binMedian, binMedian - 25, binMedian + 25); 1924 2031 psTrace(__func__, 6, "Masking data outside (%f %f)\n", medianLo, medianHi); 1925 2032 for (psS32 i = 0 ; i < myVector->n ; i++) { 1926 if ((myVector->data.F32[i] < medianLo) || 1927 (myVector->data.F32[i] > medianHi)) { 2033 if ((myVector->data.F32[i] < medianLo) || (myVector->data.F32[i] > medianHi)) { 1928 2034 tmpMaskVec->data.U8[i] = 1; 1929 psTrace(__func__, 6, "Masking element %d is %f\n", i, myVector->data.F32[i]);2035 psTrace(__func__, 8, "Masking element %d is %f\n", i, myVector->data.F32[i]); 1930 2036 } 1931 2037 } … … 1951 2057 binLo25 = 0; 1952 2058 } else { 1953 binLo25 = p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);2059 binLo25 = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar); 1954 2060 } 1955 2061 tmpScalar->data.F32 = totalDataPoints * 0.75f; … … 1958 2064 binHi25 = 0; 1959 2065 } else { 1960 binHi25 = p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);2066 binHi25 = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar); 1961 2067 } 1962 2068 if ((binLo25 < 0) || (binHi25 < 0)) { … … 1970 2076 return(1); 1971 2077 } 1972 psTrace(__func__, 6, "The 25 % and 75%data point bins are (%d, %d).\n", binLo25, binHi25);2078 psTrace(__func__, 6, "The 25-percent and 75-precent data point bins are (%d, %d).\n", binLo25, binHi25); 1973 2079 1974 2080 //
Note:
See TracChangeset
for help on using the changeset viewer.
