예제 #1
0
        /// <summary>
        /// Test for provided digit
        /// </summary>
        /// <returns>Object containing test results</returns>
        public TestResult Test(Digit digit)
        {
            List <float> networkOutput = network.Run(digit.DigitPixels);
            float        max           = networkOutput.Max();
            int          indexOfMax    = networkOutput.IndexOf(max);

            return(new TestResult {
                Label = digit.Label.ToString(), ClassifiedAs = indexOfMax.ToString(), Correct = digit.Label == indexOfMax
            });
        }
예제 #2
0
        /// <summary>
        /// Trains network with use of provided digit
        /// </summary>
        /// <returns></returns>
        public TrainingResult Train(Digit digit)
        {
            List <float> expectedOutput = GetExpectedOutput(digit.Label);
            List <float> actualOutput = network.Run(digit.DigitPixels);
            List <float> nextLayerDeltas, currentLayerDeltas;

            List <Layer> layers = network.GetLayers();

            nextLayerDeltas = GetLastLayerDeltas(expectedOutput, actualOutput, layers.Last());

            for (int i = layers.Count - 2; i >= 0; i--)
            {
                currentLayerDeltas = GetCurrentDeltas(layers[i], layers[i + 1], nextLayerDeltas);
                UpdateWeights(layers[i + 1], nextLayerDeltas);
                nextLayerDeltas = currentLayerDeltas;
            }
            UpdateWeights(layers[0], nextLayerDeltas);

            return(new TrainingResult(expectedOutput, actualOutput));
        }