Пример #1
0
        public void DerivativeNxorNoRegularizationTest()
        {
            var net    = NetBuilder.CreateNxorNet();
            var inputs = DenseMatrix.OfArray(new double[, ] {
                { 0, 0 }, { 1, 1 }
            });
            var outputIndices = new int[] { 0, 0 };

            net.CostFunction.SetInputsOutputs(inputs, outputIndices, 0);
            int dims = net.CostFunction.DimensionsCount;

            var rand = new Random(0);

            FunctionDerivativeTester.PerformDerivativeTest(net.CostFunction,
                                                           Enumerable.Range(0, 100).Select(x =>
                                                                                           Enumerable.Range(0, dims).Select(y => rand.NextDouble() * 10 - 5).ToArray()
                                                                                           ).ToArray()
                                                           );
        }
Пример #2
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);
            }
        }