Example #1
0
        static void Main(string[] args)
        {
            INeuralNetworkBuilder <double> builder = new DoubleNeuralNetworkBuilder <BackPropagationNeuralNetwork>();

            builder.BuildNetwork(2, new int[] { 10, 20 }, 1); // no hidden layers
            INeuralNetwork <double> network = InitializeNeuralNetworkStartingValues(builder);

            int iterations = 100;

            double[][] input  = GetInput(iterations);
            double[][] output = GetAdditionOutput(input);

            bool   countedRight = false;
            Random rand         = new Random();
            int    iteration    = 1;

            while (!countedRight)
            {
                Console.WriteLine($"Iteration: { iteration }");
                for (int i = 0; i < iterations; ++i)
                {
                    (network as BackPropagationNeuralNetwork).Train(input, output);
                }

                int value1 = rand.Next(10); Console.WriteLine($"Value1 = { value1 }");
                int value2 = rand.Next(10); Console.WriteLine($"Value2 = { value2 }");
                int sum    = value1 + value2; Console.WriteLine($"Sum = { sum }");

                network.ApplyLearning(null);
                network.Input[0].Value = value1;
                network.Input[1].Value = value2;
                network.Pulse(null);
                double networkOutput = network.Output[0].Value; Console.WriteLine($"Neural Network output value = { networkOutput }");

                Console.WriteLine($"End of iteration { iteration }");
                Console.WriteLine("============================================================================");
                iteration++;

                if (sum == networkOutput)
                {
                    countedRight = true;
                }
            }

            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            INeuralNetworkBuilder <double> builder = new SigmoidNeuralNetworkBuilder <GeneticTrainingNeuralNetwork>();

            builder.BuildNetwork(9, null, 1); // no hidden layers
            INeuralNetwork <double> network = builder.InitializeNeuralNetworkWithData(new double[]
            {
                2, 0, 1,
                0, 1, 0,
                2, 0, 0
            }, null, null);

            network.LearningRate = 0.1;

            for (int i = 0; i < 10000; ++i)
            {
                // Calculates Sigmoid Neurons value.
                network.Pulse(null);
                // Function prepared for Genetic Training of Feed Forward Network
                network.ApplyLearning(null);
            }
        }