public void RegressionImpurityCalculator_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 parentInterval = Interval1D.Create(0, values.Length);

            var sut = new RegressionImpurityCalculator();

            sut.Init(new double[0], values, new double[0], parentInterval);
            var impurity = sut.NodeImpurity();

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

            Assert.AreEqual(75.0, improvement1, 0.000001);

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

            Assert.AreEqual(69.473379629629648, improvement2, 0.000001);
        }
        public void RegressionImpurityCalculator_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 weights        = values.Select(t => Weight(t)).ToArray();
            var parentInterval = Interval1D.Create(0, values.Length);

            var sut = new RegressionImpurityCalculator();

            sut.Init(new double[0], values, weights, parentInterval);
            var impurity = sut.NodeImpurity();

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

            Assert.AreEqual(167.04545454545456, improvement1, 0.000001);

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

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