private static void MNISTTrainNetwork(FeedforwardNeuralNetwork fnn, TrainingExample[] trainingExamples, TrainingExample[] testExamples)
        {
            Console.WriteLine("\nBeginning neural network training procedure.\n");
            Console.WriteLine("Enter desired number of epochs.");
            string epochsStr = Console.ReadLine();
            int    epochs    = Convert.ToInt32(epochsStr);

            do
            {
                Console.WriteLine("Please wait for training cycle to complete...");
                var timer = Stopwatch.StartNew();
                fnn.TrainEpochs(trainingExamples, epochs);
                Console.WriteLine("Training cycle completed in " + timer.Elapsed + ".");
                Console.WriteLine("Test network? Enter Y for yes or anything else for no.");
                string inputStr = Console.ReadLine();
                char   input    = Convert.ToChar(inputStr);
                if (input == 'Y')
                {
                    MNISTTestNetwork(fnn, testExamples);
                }
                Console.WriteLine("Continue training? Enter 0 for no or a valid number of epochs for yes.");
                epochsStr = Console.ReadLine();
                epochs    = Convert.ToInt32(epochsStr);
            } while (epochs > 0);
        }
        public static void DecimalBinaryExample()
        {
            int[] layers = new int[] { 2, 5, 4 };
            FeedforwardNeuralNetwork fnn = new FeedforwardNeuralNetwork(layers, 1.0F, 0.1F);

            DecimalBinaryTestNetwork(fnn);
            Matrix[]          expectedOutputs = { new Matrix(new float[4, 1] {
                    { 1 },
                    { 0 },
                    { 0 },
                    { 0 }
                }),
                                                  new Matrix(new float[4,          1] {
                    { 0 },
                    { 1 },
                    { 0 },
                    { 0 }
                }),
                                                  new Matrix(new float[4,          1] {
                    { 0 },
                    { 0 },
                    { 1 },
                    { 0 }
                }),
                                                  new Matrix(new float[4,          1] {
                    { 0 },
                    { 0 },
                    { 0 },
                    { 1 }
                }) };
            Matrix[]          inputs = { new Matrix(new float[2, 1] {
                    { 0 },
                    { 0 }
                }),
                                         new Matrix(new float[2,          1] {
                    { 0 },
                    { 1 }
                }),
                                         new Matrix(new float[2,          1] {
                    { 1 },
                    { 0 }
                }),
                                         new Matrix(new float[2,          1] {
                    { 1 },
                    { 1 }
                }) };
            TrainingExample[] examples = new TrainingExample[4];
            for (int i = 0; i < 4; ++i)
            {
                examples[i] = new TrainingExample(inputs[i], expectedOutputs[i]);
            }
            fnn.TrainEpochs(examples, 1000);
            DecimalBinaryTestNetwork(fnn);
        }
 public static void DecimalBinaryExample()
 {
     int[] layers = new int[] { 2, 5, 4 };
     FeedforwardNeuralNetwork fnn = new FeedforwardNeuralNetwork(layers, 1.0F, 0.1F);
     DecimalBinaryTestNetwork(fnn);
     Matrix[] expectedOutputs = { new Matrix(new float[4,1]{ {1},
                                                             {0},
                                                             {0},
                                                             {0}}),
                                  new Matrix(new float[4,1]{ {0},
                                                             {1},
                                                             {0},
                                                             {0}}),
                                  new Matrix(new float[4,1]{ {0},
                                                             {0},
                                                             {1},
                                                             {0}}),
                                  new Matrix(new float[4,1]{ {0},
                                                             {0},
                                                             {0},
                                                             {1}})};
     Matrix[] inputs =          { new Matrix(new float[2,1]{ {0},
                                                             {0}}),
                                  new Matrix(new float[2,1]{ {0},
                                                             {1}}),
                                  new Matrix(new float[2,1]{ {1},
                                                             {0}}),
                                  new Matrix(new float[2,1]{ {1},
                                                             {1}})};
     TrainingExample[] examples = new TrainingExample[4];
     for (int i = 0; i < 4; ++i) {
         examples[i] = new TrainingExample(inputs[i], expectedOutputs[i]);
     }
     fnn.TrainEpochs(examples, 1000);
     DecimalBinaryTestNetwork(fnn);
 }
 private static void MNISTTrainNetwork(FeedforwardNeuralNetwork fnn, TrainingExample[] trainingExamples, TrainingExample[] testExamples)
 {
     Console.WriteLine("\nBeginning neural network training procedure.\n");
     Console.WriteLine("Enter desired number of epochs.");
     string epochsStr = Console.ReadLine();
     int epochs = Convert.ToInt32(epochsStr);
     do {
         Console.WriteLine("Please wait for training cycle to complete...");
         var timer = Stopwatch.StartNew();
         fnn.TrainEpochs(trainingExamples, epochs);
         Console.WriteLine("Training cycle completed in " + timer.Elapsed + ".");
         Console.WriteLine("Test network? Enter Y for yes or anything else for no.");
         string inputStr = Console.ReadLine();
         char input = Convert.ToChar(inputStr);
         if (input == 'Y') {
             MNISTTestNetwork(fnn, testExamples);
         }
         Console.WriteLine("Continue training? Enter 0 for no or a valid number of epochs for yes.");
         epochsStr = Console.ReadLine();
         epochs = Convert.ToInt32(epochsStr);
     } while (epochs > 0);
 }