Ejemplo n.º 1
0
        public void BackPropagateIsCorrect()
        {
            int   numberOfBanks = 3;
            Layer layer         = new Layer(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            LayerBank     bank        = new LayerBank(layer, numberOfBanks);
            NetworkVector inputVector = new NetworkVector(new double[] { 1, 2, 3 });
            NetworkVector bpVector    = new NetworkVector(new double[] { 5, 7, 11 });

            bank.Run(inputVector);
            NetworkVector inputGradientCheck = new NetworkVector(new double[] { 5, 7, 11 });

            Assert.AreEqual(inputGradientCheck, bank.InputGradient(bpVector));


            bank.BackPropagate(bpVector, inputVector);
            bank.Update(new GradientDescent());

            WeightsMatrix weightsCheck = new WeightsMatrix(new double[, ] {
                { -51 }
            });
            NetworkVector biasCheck = new NetworkVector(new double[] { -23 });

            Assert.AreEqual(biasCheck, bank.Biases);
            Assert.AreEqual(weightsCheck, bank.Weights);
        }
Ejemplo n.º 2
0
        public void InputGradient()
        {
            int   numberOfBanks = 3;
            Layer layer         = new Layer(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            LayerBank     bank       = new LayerBank(layer, numberOfBanks);
            NetworkVector zeroVector = new NetworkVector(numberOfBanks);

            Assert.AreEqual(zeroVector, bank.InputGradient(zeroVector));
        }
Ejemplo n.º 3
0
        public void CorrectInputGradientOneInput()
        {
            int   numberOfBanks = 3;
            Layer layer         = new Layer(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            LayerBank     bank               = new LayerBank(layer, numberOfBanks);
            NetworkVector input              = new NetworkVector(new double[] { 2, 3, 5 });
            NetworkVector outputGradient     = new NetworkVector(new double[] { 2, 3, 5 });
            NetworkVector inputGradientCheck = new NetworkVector(new double[] { 2, 3, 5 });

            Assert.AreEqual(inputGradientCheck, bank.InputGradient(outputGradient));
        }