public void ComplexLearnTest() { var network = new Network(); var inLayer = network.NewLayer("in") .Add(3, typeof(AnyNeuron)); var midLayer1 = network.NewLayer("mid") .Add(3, typeof(AllWithBlockingNeuron)) .Add(3, typeof(AnyWithBlockingNeuron)); var outLayer = network.NewLayer("out") .Add(3, typeof(AnyWithBlockingNeuron)) ; var testcase = new ComplexLearnCase(); inLayer.ConnetToLayer(midLayer1, network, null, false); inLayer.ConnetToLayer(midLayer1, network, null, true); midLayer1.ConnetToLayer(outLayer, network, null, false); midLayer1.ConnetToLayer(outLayer, network, null, true); int i = 0; while (network.SumOfEasinessToLearn() > 0.00001) { i++; if (i > 100000) { break; } network.StudyIteration(testcase, 2, 1); } for (int ii = 0; ii < 100; ii++) { network.ClearStates(); testcase.setRandomInitState(network); network.Tick(0.1); network.Tick(0.1); var result = testcase.Test(network); Assert.IsTrue(result == TestCase.ResultType.OkNegative || result == TestCase.ResultType.OkPositive, "Test " + ii); } }
public void ComplexLearnWithPredefinedNetworkTest() { var testcase = new ComplexLearnCase(); var network = new Network(); var inLayer = network.NewLayer("in") .Add(5, typeof(AnyNeuron)); var midLayer1 = network.NewLayer("mid") .Add(3, typeof(AllWithBlockingNeuron)); var outLayer = network.NewLayer("out") .Add(4, typeof(AnyWithBlockingNeuron)) .Add(1, typeof(AllWithBlockingNeuron)); var random = new Random(); inLayer.Neurons[0].ConnectTo(midLayer1.Neurons[0], random.NextDouble(), false); inLayer.Neurons[1].ConnectTo(midLayer1.Neurons[0], random.NextDouble(), false); inLayer.Neurons[2].ConnectTo(midLayer1.Neurons[0], random.NextDouble(), false); inLayer.Neurons[3].ConnectTo(midLayer1.Neurons[0], random.NextDouble(), false); inLayer.Neurons[0].ConnectTo(midLayer1.Neurons[1], random.NextDouble(), false); inLayer.Neurons[1].ConnectTo(midLayer1.Neurons[1], random.NextDouble(), false); inLayer.Neurons[2].ConnectTo(midLayer1.Neurons[1], random.NextDouble(), false); inLayer.Neurons[0].ConnectTo(midLayer1.Neurons[2], random.NextDouble(), false); inLayer.Neurons[1].ConnectTo(midLayer1.Neurons[2], random.NextDouble(), false); inLayer.Neurons[0].ConnectTo(outLayer.Neurons[0], random.NextDouble(), false); inLayer.Neurons[1].ConnectTo(outLayer.Neurons[0], random.NextDouble(), true); inLayer.Neurons[2].ConnectTo(outLayer.Neurons[0], random.NextDouble(), true); inLayer.Neurons[3].ConnectTo(outLayer.Neurons[0], random.NextDouble(), true); inLayer.Neurons[4].ConnectTo(outLayer.Neurons[0], random.NextDouble(), true); midLayer1.Neurons[2].ConnectTo(outLayer.Neurons[1], random.NextDouble(), false); inLayer.Neurons[2].ConnectTo(outLayer.Neurons[1], random.NextDouble(), true); inLayer.Neurons[3].ConnectTo(outLayer.Neurons[1], random.NextDouble(), true); inLayer.Neurons[4].ConnectTo(outLayer.Neurons[1], random.NextDouble(), true); midLayer1.Neurons[1].ConnectTo(outLayer.Neurons[2], random.NextDouble(), false); inLayer.Neurons[3].ConnectTo(outLayer.Neurons[2], random.NextDouble(), true); inLayer.Neurons[4].ConnectTo(outLayer.Neurons[2], random.NextDouble(), true); midLayer1.Neurons[0].ConnectTo(outLayer.Neurons[3], random.NextDouble(), false); inLayer.Neurons[4].ConnectTo(outLayer.Neurons[3], random.NextDouble(), true); inLayer.Neurons[0].ConnectTo(outLayer.Neurons[4], random.NextDouble(), false); inLayer.Neurons[1].ConnectTo(outLayer.Neurons[4], random.NextDouble(), false); inLayer.Neurons[2].ConnectTo(outLayer.Neurons[4], random.NextDouble(), false); inLayer.Neurons[3].ConnectTo(outLayer.Neurons[4], random.NextDouble(), false); inLayer.Neurons[4].ConnectTo(outLayer.Neurons[4], random.NextDouble(), false); int i = 0; while (network.SumOfEasinessToLearn() > 0.00001) { i++; if (i > 100000) { break; } network.StudyIteration(testcase, 2, 1); } for (int ii = 0; ii < 100; ii++) { network.ClearStates(); testcase.setRandomInitState(network); network.Tick(0.1); network.Tick(0.1); var result = testcase.Test(network); Assert.IsTrue(result == TestCase.ResultType.OkNegative || result == TestCase.ResultType.OkPositive, "Test " + ii); } }