IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6270


Ignore:
Timestamp:
Jan 31, 2006, 4:07:24 PM (20 years ago)
Author:
gusciora
Message:

Fixed bug 674.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psStats.c

    r6215 r6270  
    2222 *
    2323 *
    24  *  @version $Revision: 1.163 $ $Name: not supported by cvs2svn $
    25  *  @date $Date: 2006-01-26 23:49:11 $
     24 *  @version $Revision: 1.164 $ $Name: not supported by cvs2svn $
     25 *  @date $Date: 2006-02-01 02:07:24 $
    2626 *
    2727 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    16441644}
    16451645
     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
    16461738/******************************************************************************
    16471739p_psVectorRobustStats(myVector, maskVector, maskVal, stats): This is the new
     
    16621754XXX: Review and ensure that all memory is free'ed at premature exits.
    16631755*****************************************************************************/
     1756#define INITIAL_NUM_BINS 1000.0
    16641757psS32 p_psVectorRobustStats(const psVector* myVector,
    16651758                            const psVector* errors,
     
    16971790
    16981791    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);
    17001793        psF32 binSize = 0.0;
    17011794        if ((iterate == 1) && (stats->options & PS_STAT_USE_BINSIZE)) {
     
    17171810                return(1);
    17181811            }
    1719             psTrace(__func__, 6, "Data min/man is (%.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;
    17211814            psTrace(__func__, 6, "Robust bin size is %.2f\n", binSize);
    17221815        }
     
    17561849        numBins = (psS32)((tmpStatsMinMax->max - tmpStatsMinMax->min) / binSize);
    17571850        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);
    17581852        robustHistogram = psHistogramAlloc(tmpStatsMinMax->min, tmpStatsMinMax->max, numBins);
    17591853        cumulativeRobustHistogram = psHistogramAlloc(tmpStatsMinMax->min, tmpStatsMinMax->max, numBins);
     
    17921886        } else {
    17931887            tmpScalar->data.F32 = totalDataPoints/2.0;
    1794             binMedian = p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);
     1888            binMedian = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);
    17951889            if (binMedian < 0) {
    17961890                psError(PS_ERR_UNKNOWN, false, "Failed to calculate the 50 precent data point (%d).\n", binMedian);
     
    18041898            }
    18051899        }
    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]);
    18071901
    18081902        //
     
    18391933        } else {
    18401934            // 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);
    18421936            if (binHi > cumulativeRobustHistogram->nums->n-1) {
    18431937                binHi = cumulativeRobustHistogram->nums->n-1;
    18441938            }
    18451939        }
    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);
    18471941        psTrace(__func__, 6, "binLo midpoint is %f\n", PS_BIN_MIDPOINT(cumulativeRobustHistogram, binLo));
    18481942        psTrace(__func__, 6, "binHi midpoint is %f\n", PS_BIN_MIDPOINT(cumulativeRobustHistogram, binHi));
     
    19202014        if (sigma < (2 * binSize)) {
    19212015            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);
    19242031            psTrace(__func__, 6, "Masking data outside (%f %f)\n", medianLo, medianHi);
    19252032            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)) {
    19282034                    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]);
    19302036                }
    19312037            }
     
    19512057        binLo25 = 0;
    19522058    } else {
    1953         binLo25 = p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);
     2059        binLo25 = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);
    19542060    }
    19552061    tmpScalar->data.F32 = totalDataPoints * 0.75f;
     
    19582064        binHi25 = 0;
    19592065    } else {
    1960         binHi25 = p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);
     2066        binHi25 = 1 + p_psVectorBinDisect(cumulativeRobustHistogram->nums, tmpScalar);
    19612067    }
    19622068    if ((binLo25 < 0) || (binHi25 < 0)) {
     
    19702076        return(1);
    19712077    }
    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);
    19732079
    19742080    //
Note: See TracChangeset for help on using the changeset viewer.