public static void TestTanhDerivative() { NNetwork n = NNetwork.HyperbolicNetwork(new int[] { 2, 2, 1 }); n.RandomizeWeights(-1, 10); Random random = new Random(); double x; double y; double z; x = random.NextDouble(); y = random.NextDouble(); z = some_function(x, y); n.SetInput(new double[] { x, y }); n.SetAnswers(new double[] { z }); n.BackPropagate(); double[] ders = n.Derivatives(); double[] ests = n.Estimation(0.0001); for (int i = 0; i < ders.Length; i++) { Show(new[] { ders[i], ests[i], ests[i] / ders[i] }); } }
public void TestDerivative() { //Fails with square error function NNetwork n = NNetwork.SigmoidNetwork(new int[] { 2, 2, 1 }); n.RandomizeWeights(-1, 10); Random random = new Random(); double x; double y; double z; x = random.NextDouble(); y = random.NextDouble(); z = some_function(x, y); n.SetInput(new double[] { x, y }); n.SetAnswers(new double[] { z }); n.BackPropagate(); double[] ders = n.Derivatives(); double[] ests = n.Estimation(0.0001); for (int i = 0; i < ders.Length; i++) { MyAssert.CloseTo(ders[i], ests[i], 0.0001); } }