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(); }
static void Main(string[] args) { // Prepare Neural Network double[] input = new double[] { 2, 1, 2, 1, 0, 0, 0, 2, 0 }; INeuralNetworkBuilder <double> builder = new DoubleNeuralNetworkBuilder <BackPropagationNeuralNetwork>(); builder.BuildNetwork(9, null, 1); // no hidden layers INeuralNetwork <double> network = builder.InitializeNeuralNetworkWithData(input, null, new double[] { 0 }); // Test output value // Single pulse of network //network.Pulse(null); // Test back propagation (network as BackPropagationNeuralNetwork).Train(input, new double[] { new Random().Next(1, 9) }); ; }