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 ComplexTest()
        {
            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));

            inLayer.Neurons[0].ConnectTo(midLayer1.Neurons[0], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[1].ConnectTo(midLayer1.Neurons[0], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[2].ConnectTo(midLayer1.Neurons[0], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[3].ConnectTo(midLayer1.Neurons[0], Neuron.VEGETATIVE_STATE, false);

            inLayer.Neurons[0].ConnectTo(midLayer1.Neurons[1], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[1].ConnectTo(midLayer1.Neurons[1], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[2].ConnectTo(midLayer1.Neurons[1], Neuron.VEGETATIVE_STATE, false);

            inLayer.Neurons[0].ConnectTo(midLayer1.Neurons[2], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[1].ConnectTo(midLayer1.Neurons[2], Neuron.VEGETATIVE_STATE, false);

            inLayer.Neurons[0].ConnectTo(outLayer.Neurons[0], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[1].ConnectTo(outLayer.Neurons[0], Neuron.VEGETATIVE_STATE, true);
            inLayer.Neurons[2].ConnectTo(outLayer.Neurons[0], Neuron.VEGETATIVE_STATE, true);
            inLayer.Neurons[3].ConnectTo(outLayer.Neurons[0], Neuron.VEGETATIVE_STATE, true);
            inLayer.Neurons[4].ConnectTo(outLayer.Neurons[0], Neuron.VEGETATIVE_STATE, true);


            midLayer1.Neurons[2].ConnectTo(outLayer.Neurons[1], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[2].ConnectTo(outLayer.Neurons[1], Neuron.VEGETATIVE_STATE, true);
            inLayer.Neurons[3].ConnectTo(outLayer.Neurons[1], Neuron.VEGETATIVE_STATE, true);
            inLayer.Neurons[4].ConnectTo(outLayer.Neurons[1], Neuron.VEGETATIVE_STATE, true);

            midLayer1.Neurons[1].ConnectTo(outLayer.Neurons[2], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[3].ConnectTo(outLayer.Neurons[2], Neuron.VEGETATIVE_STATE, true);
            inLayer.Neurons[4].ConnectTo(outLayer.Neurons[2], Neuron.VEGETATIVE_STATE, true);

            midLayer1.Neurons[0].ConnectTo(outLayer.Neurons[3], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[4].ConnectTo(outLayer.Neurons[3], Neuron.VEGETATIVE_STATE, true);

            inLayer.Neurons[0].ConnectTo(outLayer.Neurons[4], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[1].ConnectTo(outLayer.Neurons[4], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[2].ConnectTo(outLayer.Neurons[4], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[3].ConnectTo(outLayer.Neurons[4], Neuron.VEGETATIVE_STATE, false);
            inLayer.Neurons[4].ConnectTo(outLayer.Neurons[4], Neuron.VEGETATIVE_STATE, false);

            network.ClearStates();
            inLayer.Neurons[0].State = 1;

            network.Tick(0.1);
            network.Tick(0.1);

            Assert.IsTrue(outLayer.Neurons[0].State > Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[1].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[2].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[3].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[4].State <= Neuron.VEGETATIVE_STATE);


            network.ClearStates();
            inLayer.Neurons[0].State = 1;
            inLayer.Neurons[1].State = 1;

            network.Tick(0.1);
            network.Tick(0.1);

            Assert.AreEqual(TestCase.ResultType.OkPositive, testCase.Test(network));

            Assert.IsTrue(outLayer.Neurons[0].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[1].State > Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[2].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[3].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[4].State <= Neuron.VEGETATIVE_STATE);



            network.ClearStates();
            inLayer.Neurons[0].State = 1;
            inLayer.Neurons[1].State = 1;
            inLayer.Neurons[2].State = 1;

            network.Tick(0.1);
            network.Tick(0.1);
            Assert.AreEqual(TestCase.ResultType.OkPositive, testCase.Test(network));

            Assert.IsTrue(outLayer.Neurons[0].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[1].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[2].State > Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[3].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[4].State <= Neuron.VEGETATIVE_STATE);



            network.ClearStates();
            inLayer.Neurons[0].State = 1;
            inLayer.Neurons[1].State = 1;
            inLayer.Neurons[2].State = 1;
            inLayer.Neurons[3].State = 1;

            network.Tick(0.1);
            network.Tick(0.1);
            Assert.AreEqual(TestCase.ResultType.OkPositive, testCase.Test(network));

            Assert.IsTrue(outLayer.Neurons[0].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[1].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[2].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[3].State > Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[4].State <= Neuron.VEGETATIVE_STATE);

            network.ClearStates();
            inLayer.Neurons[0].State = 1;
            inLayer.Neurons[1].State = 1;
            inLayer.Neurons[2].State = 1;
            inLayer.Neurons[3].State = 1;
            inLayer.Neurons[4].State = 1;

            network.Tick(0.1);
            network.Tick(0.1);
            Assert.AreEqual(TestCase.ResultType.OkPositive, testCase.Test(network));

            Assert.IsTrue(outLayer.Neurons[0].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[1].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[2].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[3].State <= Neuron.VEGETATIVE_STATE);
            Assert.IsTrue(outLayer.Neurons[4].State > Neuron.VEGETATIVE_STATE);
        }
        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);
            }
        }