Пример #1
0
        private static List <double> ClassifyByJenksFisher(int numBreaks, List <ValueCountTuple> tuples)
        {
            var breaksArray = new List <double>(numBreaks);

            if (numBreaks == 0)
            {
                return(breaksArray);
            }
            //  Avoid array <-> list conversations
            breaksArray.AddRange(Enumerable.Repeat(0.0d, numBreaks));

            var classificator = new NaturalBreaks(tuples, numBreaks);

            if (numBreaks > 1)
            {
                //  Runs the actual calculation
                classificator.CalculateAll();
                var lastClassBreakIndex = classificator.FindMaxBreakIndex(classificator._bufferSize - 1, 0, classificator._bufferSize);
                while (--numBreaks != 0)
                {
                    //  Assign the break values to the result
                    breaksArray[numBreaks] = tuples[lastClassBreakIndex + numBreaks].Value;

                    if (numBreaks > 1)
                    {
                        classificator._classBreaksIndex -= classificator._bufferSize;
                        lastClassBreakIndex              = classificator._classBreaks[classificator._classBreaksIndex + lastClassBreakIndex];
                    }
                }
            }

            breaksArray[0] = tuples[0].Value;
            return(breaksArray);
        }
Пример #2
0
        private static double ApplyJenks(ref List <double> refList)
        {
            int[] groupCorrection = { 1, 1, 1, 2, 4, 7, 9, 10, 10, 10 };

            //  Check if the speed list is empty.
            if (refList.Count == 0)
            {
                throw new InvalidOperationException("Empty list");
            }

            var corr      = NaturalBreaks.CreateNaturalBreaksArray(refList, 10);
            var groupList = new List <int>(refList.Count);

            foreach (var cur in refList)
            {
                for (var j = 1; j < corr.Count + 1; j++)
                {
                    if (j == corr.Count || cur < corr[j])
                    {
                        groupList.Add(j - 1);
                        break;
                    }
                }
            }

            var jenksVar = refList.Select((t, i) => t * groupCorrection[groupList[i]]).Sum();

            var GroupCount = 0;

            for (var i = 0; i < 10; i++)
            {
                GroupCount += groupList.Count(x => x == i) * groupCorrection[i];
            }

            return(jenksVar / GroupCount);
        }