public void CanUseBigSigmoidLayer() { double[,] weights = new double[2000, 1000]; double[] input = new double[1000]; for (int i = 0; i < 1000; i++) { weights[i, i] = 1.0; input[i] = (double)i; } NetworkVector inputvector = new NetworkVector(input); Layer layer = new SigmoidLayer(weights); layer.Run(inputvector); double[] result = layer.Output.ToArray(); double sig0 = sigmoid(0.0); for (int i = 0, j = 1000; i < 1000; i++, j++) { Assert.AreEqual(sigmoid((double)i), result[i], "Failed for i = " + i); Assert.AreEqual(sig0, result[j], "Failed for j = " + j); } }
public void SigmoidLayerHasRightRun() { double[,] weights = new double[, ] { { 1, 0, 1 }, { 1, 1, 0 } }; NetworkVector inputvector = new NetworkVector(new double[] { 1, 2, 3 }); Layer layer = new SigmoidLayer(weights); layer.Run(inputvector); double[] result = layer.Output.ToArray(); double[] expectedResult = new double[] { sigmoid(4), sigmoid(3) }; Assert.AreEqual(expectedResult[0], result[0]); Assert.AreEqual(expectedResult[1], result[1]); }
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)); } }