Пример #1
0
        public void BackPropagateWeightedCombinerBankIsCorrect()
        {
            int numberOfBanks      = 3;
            WeightedCombiner layer = new WeightedCombiner(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            WeightedCombinerBank bank        = new WeightedCombinerBank(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);
        }
Пример #2
0
        public void InputGradientWeightedCombinerBank()
        {
            int numberOfBanks      = 3;
            WeightedCombiner layer = new WeightedCombiner(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            WeightedCombinerBank bank       = new WeightedCombinerBank(layer, numberOfBanks);
            NetworkVector        zeroVector = new NetworkVector(numberOfBanks);

            bank.BackPropagate(zeroVector, new NetworkVector(3));
            Assert.AreEqual(zeroVector, bank.InputGradient(zeroVector));
        }
Пример #3
0
        public void CannotBackPropagateWeightedCombinerBankWithBadOutputGradientSize()
        {
            int numberOfBanks      = 3;
            WeightedCombiner layer = new WeightedCombiner(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            WeightedCombinerBank bank        = new WeightedCombinerBank(layer, numberOfBanks);
            NetworkVector        badGradient = new NetworkVector(2);

            try
            {
                bank.BackPropagate(badGradient, new NetworkVector(3));
                Assert.Fail("WeightedCombinerBank.BackPropagate failed to throw an ArgumentException for outputgradient of the wrong size.");
            }
            catch (ArgumentException) { }
        }