Beispiel #1
0
        public void BackpropagateRuns()
        {
            double[,] weights = new double[, ] {
                { 1 }
            };
            NetworkVector outputgradient = new NetworkVector(new double[] { 1 });
            Layer         layer          = new SigmoidLayer(weights);

            layer.BackPropagate(outputgradient);

            double[] inputGradientCheck  = new double[] { 0 };
            double[] inputGradientValues = layer.InputGradient.ToArray();
            for (int i = 0; i < layer.NumberOfInputs; i++)
            {
                Assert.AreEqual(inputGradientCheck[i], inputGradientValues[i]);
            }
        }
Beispiel #2
0
        public void BackpropagateRunsTwoByThree()
        {
            double[,] weights = new double[, ] {
                { 1, 2, 3 }, { 2, 3, 4 }
            };
            Layer layer = new SigmoidLayer(weights);

            NetworkVector layerinput = new NetworkVector(new double[] { 1, 0, -1 });

            layer.Run(layerinput);

            NetworkVector outputgradient = new NetworkVector(new double[] { 1, 1 });

            layer.BackPropagate(outputgradient);

            double[] inputGradientCheck  = new double[] { 0.31498075621051952, 0.52496792701753248, 0.7349550978245456 };
            double[] inputGradientValues = layer.InputGradient.ToArray();
            for (int i = 0; i < layer.NumberOfInputs; i++)
            {
                Assert.AreEqual(inputGradientCheck[i], inputGradientValues[i], string.Format("Failure for input {0}", i));
            }
        }