Exemple #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);
        }
Exemple #2
0
        public void CanRunLayerBank()
        {
            int   numberOfBanks = 3;
            Layer layer         = new Layer(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            LayerBank     bank       = new LayerBank(layer, numberOfBanks);
            NetworkVector zeroVector = new NetworkVector(numberOfBanks);

            NetworkVector result = bank.Run(zeroVector);

            Assert.AreEqual(zeroVector, result);
        }
Exemple #3
0
        public void CorrectRunThreeInputs()
        {
            int   numberOfBanks = 3;
            Layer layer         = new Layer(new WeightsMatrix(new double[, ] {
                { 2, 3, 5 }
            }));
            LayerBank     bank        = new LayerBank(layer, numberOfBanks);
            NetworkVector input       = new NetworkVector(new double[] { 7, 7, 7, 11, 11, 11, 13, 13, 13 });
            NetworkVector outputcheck = new NetworkVector(new double[] { 70, 110, 130 });

            NetworkVector result = bank.Run(input);

            Assert.AreEqual(outputcheck, result);
        }
Exemple #4
0
        public void CannotRunLayerBankWithBadInputSize()
        {
            int   numberOfBanks = 3;
            Layer layer         = new Layer(new WeightsMatrix(new double[, ] {
                { 1 }
            }));
            LayerBank     bank     = new LayerBank(layer, numberOfBanks);
            NetworkVector badInput = new NetworkVector(2);

            try
            {
                bank.Run(badInput);
                Assert.Fail("LayerBank.Run failed to throw an ArgumentException for input of the wrong size.");
            }
            catch (ArgumentException) { }
        }