public void DecisionTreeLearn_OneSplit()
        {
            GlobalVariables.GrowCondition = new GrowCondition(5);

            var synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);

            synthesisTree.Learn();

            var tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(12, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Output);
            Assert.AreEqual(2, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Output);

            int[] actual = tree.Decide(validation)
                           .Select(val => val > 0 ? 0 : 1)
                           .ToArray();

            var areaSize = (double)tree.Decide(validation)
                           .Count(val => val > 0);

            var confusionMatrix = new Accord.Statistics.Analysis.ConfusionMatrix(actual, validationOutput, 0, 1);

            Assert.AreEqual(14, confusionMatrix.TruePositives);
            Assert.AreEqual(40, confusionMatrix.TrueNegatives);
            Assert.AreEqual(0, confusionMatrix.FalseNegatives);
            Assert.AreEqual(2, confusionMatrix.FalsePositives);
            Assert.AreEqual(16, areaSize);
        }
        public void DecisionTrreLearn_MinLeafSizeParameter()
        {
            GlobalVariables.GrowCondition = new GrowCondition(minLeafSize: 2);

            var synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);

            synthesisTree.Learn();

            var tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(12, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Output);
            Assert.AreEqual(0,
                            tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Branches[0].Output);
            Assert.AreEqual(2,
                            tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Branches[1].Output);

            GlobalVariables.GrowCondition = new GrowCondition(minLeafSize: 3);

            synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);
            synthesisTree.Learn();

            tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(14, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Output);
        }
Ejemplo n.º 3
0
        public void DecisionTreeLearn_BoundingBox()
        {
            GlobalVariables.GrowCondition = new GrowCondition(0);

            var synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);

            synthesisTree.Learn();

            var tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(learn.Length, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Output);
            Assert.IsTrue(tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].IsLeaf);

            int[] actual = tree.Decide(validation)
                           .Select(val => val > 0 ? 0 : 1)
                           .ToArray();

            var areaSize = (double)tree.Decide(validation)
                           .Count(val => val > 0) / validation.Length;

            var confusionMatrix = new Accord.Statistics.Analysis.ConfusionMatrix(actual, validationOutput, 0, 1);
        }
Ejemplo n.º 4
0
        private static void LearnDecisionTree()
        {
            timer.Start();
            var learnDecisionTree = new SynthesisTreeLearn(
                dataStorage.DecisionVariables, dataStorage.LearnDataSet, dataStorage.ValidationDataSet);

            learnDecisionTree.Learn();
            decisionTree = learnDecisionTree.Tree;
            timer.Stop();
        }
Ejemplo n.º 5
0
        public void DecisionTreeLearn_BoundingBox()
        {
            var synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);

            synthesisTree.Learn();

            var tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(9, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Output);
            Assert.IsTrue(tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].IsLeaf);
        }
Ejemplo n.º 6
0
        public void DecisionTreeLearn_MaxAttributeUsageParameter()
        {
            GlobalVariables.GrowCondition = new GrowCondition(maxAttributeUsage: 1);

            var synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);

            synthesisTree.Learn();

            var tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(3, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Output);
            Assert.AreEqual(9, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Output);

            int[] actual = tree.Decide(validation)
                           .Select(val => val > 0 ? 0 : 1)
                           .ToArray();

            var areaSize = (double)tree.Decide(validation)
                           .Count(val => val > 0) / validation.Length;

            var confusionMatrix = new Accord.Statistics.Analysis.ConfusionMatrix(actual, validationOutput, 0, 1);

            GlobalVariables.GrowCondition = new GrowCondition(maxAttributeUsage: 2);

            synthesisTree = new SynthesisTreeLearn(attributes, learn, validation);
            synthesisTree.Learn();

            tree = synthesisTree.Tree;

            Assert.AreEqual(1, tree.Root.Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches.Count);
            Assert.AreEqual(3, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Output);
            Assert.AreEqual(0, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Output);
            Assert.AreEqual(9, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Output);
            Assert.AreEqual(1, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Branches[0].Output);
            Assert.AreEqual(2, tree.Root.Branches[0].Branches[0].Branches[0].Branches[0].Branches[1].Branches[1].Output);
        }