Example #1
0
File: Offline.cs Project: rc153/LTF
        // quantize so that Q1 ~ Q3 is 10 buckets, and find the bucket with the most values in it
        // then recurse if there's still a lot of points in our largest bucket
        // if there are 2 possible answer, we return the lowest one
        public double GetMode()
        {
            double bucketSize = 0.1 * (GetQuantile(.75) - GetQuantile(.25));
            if (bucketSize <= 0) return Median;
            double result = 0;
            int maxNbPoints = 0;
            int i = 0;
            int oldI = 0;
            for (double d = Minimum + bucketSize; i < data.Count; d += bucketSize)
            {
                while (i < data.Count && data[i] < d) { i++; }
                if (i - oldI > maxNbPoints) { maxNbPoints = i - oldI; result = d - bucketSize / 2; }
                oldI = i;
            }

            OfflineUnivariateStat newStat = new OfflineUnivariateStat();
            for (int j = 0; j < data.Count; j++)
            {
                if (data[j] > result + 3 / 2 * bucketSize)
                    break;
                if (data[j] >= result - 3 / 2 * bucketSize)
                    newStat.Add(data[j]);
            }

            if (maxNbPoints > 1000)
                return newStat.GetMode();
            else
                return newStat.Median;
        }