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); }
public void CanRunWeightedCombinerBank() { int numberOfBanks = 3; WeightedCombiner layer = new WeightedCombiner(new WeightsMatrix(new double[, ] { { 1 } })); WeightedCombinerBank bank = new WeightedCombinerBank(layer, numberOfBanks); NetworkVector zeroVector = new NetworkVector(numberOfBanks); NetworkVector result = bank.Run(zeroVector); Assert.AreEqual(zeroVector, result); }
public void CorrectRunThreeInputs() { int numberOfBanks = 3; WeightedCombiner layer = new WeightedCombiner(new WeightsMatrix(new double[, ] { { 2, 3, 5 } })); WeightedCombinerBank bank = new WeightedCombinerBank(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); }
public void CannotRunWeightedCombinerBankWithBadInputSize() { int numberOfBanks = 3; WeightedCombiner layer = new WeightedCombiner(new WeightsMatrix(new double[, ] { { 1 } })); WeightedCombinerBank bank = new WeightedCombinerBank(layer, numberOfBanks); NetworkVector badInput = new NetworkVector(2); try { bank.Run(badInput); Assert.Fail("WeightedCombinerBank.Run failed to throw an ArgumentException for input of the wrong size."); } catch (ArgumentException) { } }