public void TestBackPropWithKnownValues() { NNetwork n = NetworkTest.XorNetwork(); n.SetInput(new double[] { 1, 1 }); n.SetAnswers(new double[] { 0 }); n.BackPropagate(); double[] deltas = n.GetDeltasForLayer(2); Assert.AreNotEqual(deltas[0], 0); Assert.AreNotEqual(deltas[1], 0); MyAssert.CloseTo(deltas[0], 0, 0.001); MyAssert.CloseTo(deltas[1], 0, 0.001); }
public void TestNetworkSetAnswerAndGetDelta() { NNetwork n = NNetwork.SigmoidNetwork(new int[] { 2, 3, 2 }); n.SetInput(new double[] { 0, 0 }); double[] outputs = n.GetOutput(); double[] answers = new double[] { 0.1, 0.9 }; n.SetAnswers(answers); n.BackPropagate(); double[] deltas = n.GetDeltasForLayer(3); for (int i = 0; i < answers.Length; i++) { MyAssert.CloseTo(deltas[i], answers[i] - outputs[i]); } }
public void CanNotGetDeltasForFirstLayer() { NNetwork n = NNetwork.SigmoidNetwork(new int[] { 2, 3, 2 }); Assert.Throws(typeof(CannotGetDeltasForThisLayer), () => n.GetDeltasForLayer(1)); }