Exemplo n.º 1
0
        public void DerivativeAndNandNoRegularizationTest()
        {
            var net    = NetBuilder.CreateAndNandNet();
            var func   = net.CostFunction;
            var inputs = DenseMatrix.OfArray(new double[, ] {
                { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 }
            });
            {
                var outputIndices = new int[] { 1, 1, 1, 0 };
                func.SetInputsOutputs(inputs, outputIndices, 0);
                int dims = func.DimensionsCount;

                var rand = new Random(0);
                FunctionDerivativeTester.PerformDerivativeTest(func,
                                                               Enumerable.Range(0, 100).Select(x =>
                                                                                               Enumerable.Range(0, dims).Select(y => rand.NextDouble() * 10 - 5).ToArray()
                                                                                               ).ToArray()
                                                               );
            }
            {
                var outputIndices = new int[] { 0, 0, 0, 1 };
                func.SetInputsOutputs(inputs, outputIndices, 0);
                int dims = func.DimensionsCount;

                var rand = new Random(0);
                FunctionDerivativeTester.PerformDerivativeTest(func,
                                                               Enumerable.Range(0, 100).Select(x =>
                                                                                               Enumerable.Range(0, dims).Select(y => rand.NextDouble() * 10 - 5).ToArray()
                                                                                               ).ToArray()
                                                               );
            }
        }
Exemplo n.º 2
0
        public void EvaluateAndNotandTest()
        {
            var net = NetBuilder.CreateAndNandNet();

            performEvaluatorTest(net, new int[] { 0, 1 }, 0, 0);
            performEvaluatorTest(net, new int[] { 0, 1 }, 0, 1);
            performEvaluatorTest(net, new int[] { 0, 1 }, 1, 0);
            performEvaluatorTest(net, new int[] { 1, 0 }, 1, 1);
        }
Exemplo n.º 3
0
        public void TrainAndNandTest()
        {
            var net    = NetBuilder.CreateAndNandNet();
            var inputs = DenseMatrix.OfArray(new double[, ] {
                { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 }
            });
            var outputIndices = new int[] { 1, 1, 1, 0 };

            performTrainTest(net, inputs, outputIndices, 1, 0.05, 1024);
            //performTrainTestWithPlots(net, inputs, outputIndices, 1, 0.05, 1024, 0.05);
        }
Exemplo n.º 4
0
        public void EvaluateAndNandNoRegularizationTest()
        {
            var net    = NetBuilder.CreateAndNandNet();
            var func   = net.CostFunction;
            var inputs = DenseMatrix.OfArray(new double[, ] {
                { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 }
            });
            {
                var outputIndices = new int[] { 1, 1, 1, 0 };
                func.SetInputsOutputs(inputs, outputIndices, 0);

                double value = func.Evaluate(net.Coefficients.Pack());
                Assert.IsTrue(value < 0.001);
            }
            {
                var outputIndices = new int[] { 0, 0, 0, 1 };
                func.SetInputsOutputs(inputs, outputIndices, 0);

                double value = func.Evaluate(net.Coefficients.Pack());
                Assert.IsTrue(value > 10);
            }
        }