예제 #1
0
        public void LargeRunTest()
        {
            double[][]   inputs;
            int[]        outputs;
            DecisionTree tree = createTree(out inputs, out outputs);

            var rules = DecisionSet.FromDecisionTree(tree);

            Simplification simpl = new Simplification(rules);
            double         error = simpl.ComputeError(inputs, outputs);

            Assert.AreEqual(0, error);

            double newError = simpl.Compute(inputs, outputs);

            Assert.AreEqual(0.067515432098765427, newError);
        }
예제 #2
0
        public void LargeRunTest2()
        {
            Accord.Math.Random.Generator.Seed = 0;

            int[,] random = Matrix.Random(1000, 10, 0.0, 10.0).ToInt32();

            int[][] samples = random.ToJagged();
            int[]   outputs = new int[1000];

            for (int i = 0; i < samples.Length; i++)
            {
                if (samples[i][0] > 5 || Tools.Random.NextDouble() > 0.85)
                {
                    outputs[i] = 1;
                }
            }

            DecisionVariable[] vars = new DecisionVariable[10];
            for (int i = 0; i < vars.Length; i++)
            {
                vars[i] = new DecisionVariable("x" + i, 10);
            }

            DecisionTree tree = new DecisionTree(vars, 2);

            var teacher = new ID3Learning(tree);

            double error = teacher.Run(samples, outputs);

            Assert.AreEqual(0, error);

            var rules = DecisionSet.FromDecisionTree(tree);

            Simplification simpl = new Simplification(rules)
            {
                Alpha = 0.05
            };

            error = simpl.ComputeError(samples.ToDouble(), outputs);
            Assert.AreEqual(0, error);

            double newError = simpl.Compute(samples.ToDouble(), outputs);

            Assert.AreEqual(0.097, newError);
        }