public void GiniClasificationImpurityCalculator_ImpurityImprovement()
        {
            var values = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
            var unique = values.Distinct().ToArray();

            var parentInterval = Interval1D.Create(0, values.Length);

            var sut = new GiniClasificationImpurityCalculator();

            sut.Init(unique, values, new double[0], parentInterval);

            var impurity = sut.NodeImpurity();

            sut.UpdateIndex(50);
            var improvement1 = sut.ImpurityImprovement(impurity);

            Assert.AreEqual(0.33333333333333343, improvement1, 0.000001);

            sut.UpdateIndex(96);
            var improvement2 = sut.ImpurityImprovement(impurity);

            Assert.AreEqual(0.28047839506172845, improvement2, 0.000001);
        }
        public void GiniClasificationImpurityCalculator_ImpurityImprovement_Weighted()
        {
            var values = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
            var unique = values.Distinct().ToArray();

            var weights        = values.Select(t => Weight(t)).ToArray();
            var parentInterval = Interval1D.Create(0, values.Length);

            var sut = new GiniClasificationImpurityCalculator();

            sut.Init(unique, values, weights, parentInterval);

            var impurity = sut.NodeImpurity();

            sut.UpdateIndex(50);
            var improvement1 = sut.ImpurityImprovement(impurity);

            Assert.AreEqual(0.14015151515151511, improvement1, 0.000001);

            sut.UpdateIndex(96);
            var improvement2 = sut.ImpurityImprovement(impurity);

            Assert.AreEqual(0.17358104858104859, improvement2, 0.000001);
        }