public void FeedForwardTest() { FormMain_Accessor target = new FormMain_Accessor(); target.sqareSideLengthA = 3; target.sqareSideLengthB = 3; target.AllocateNetwork(3, 3); target.rawSamples.Add(null); target.rawSamples.Add(null); target.rawSamples.Add(null); target.xCookedSamples = new double[3][]; target.xCookedSamples[0] = new double[] { 1, -1, -1 }; target.xCookedSamples[1] = new double[] { -1, 1, -1 }; target.xCookedSamples[2] = new double[] { -1, -1, 1 }; target.yCookedSamples = new double[3][]; target.yCookedSamples[0] = new double[] { -1, -1, 1 }; target.yCookedSamples[1] = new double[] { -1, 1, -1 }; target.yCookedSamples[2] = new double[] { 1, -1, -1 }; target.Train(); double[] actual = target.FeedForward(new double[] { 1, -1, -1 }); double[] expected = new double[] { -3, -3, 5 }; for (int i = 0; i < 3; i++) { Assert.AreEqual(expected[i], actual[i], 1e-1); } expected = new double[] { -1, -1, 1 }; target.BinarizeToPlusMinus(ref actual); for (int i = 0; i < 3; i++) { Assert.AreEqual(expected[i], actual[i], 1e-1); } }
public void TrainTest() { FormMain_Accessor target = new FormMain_Accessor(); target.sqareSideLengthA = 3; target.sqareSideLengthB = 3; target.AllocateNetwork(3, 3); target.rawSamples.Add(null); target.rawSamples.Add(null); target.rawSamples.Add(null); target.xCookedSamples = new double[3][]; target.xCookedSamples[0] = new double[] { 1, -1, -1 }; target.xCookedSamples[1] = new double[] { -1, 1, -1 }; target.xCookedSamples[2] = new double[] { -1, -1, 1 }; target.yCookedSamples = new double[3][]; target.yCookedSamples[0] = new double[] { -1, -1, 1 }; target.yCookedSamples[1] = new double[] { -1, 1, -1 }; target.yCookedSamples[2] = new double[] { 1, -1, -1 }; double[,] expected = new double[, ] { { -1, -1, 3 }, { -1, 3, -1 }, { 3, -1, -1 } }; target.Train(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.AreEqual(expected[i, j], target.w[i, j], 1e-1); } } }