public TrainingRecord[] Parse(string imagesFile, string labelsFile)
        {
            var records = new List<TrainingRecord>();

            using (var imagesFileReader = new BinaryReader(File.Open(imagesFile, FileMode.Open)))
            using (var labelsFileReader = new BinaryReader(File.Open(labelsFile, FileMode.Open)))
            {
                imagesFileReader.ReadInt32();
                int images = ReadBigEndianInt32(imagesFileReader);
                int columns = ReadBigEndianInt32(imagesFileReader);
                int rows = ReadBigEndianInt32(imagesFileReader);
                int imageSize = columns*rows;

                labelsFileReader.ReadInt32();
                int labels = ReadBigEndianInt32(labelsFileReader);

                Debug.Assert(images == labels);

                for (int i = 0; i < images; i++)
                {
                    var record = new TrainingRecord
                    {
                        Input = ConvertToInput(imagesFileReader.ReadBytes(imageSize)),
                        Output = ConvertToOutput(labelsFileReader.ReadByte())
                    };
                    records.Add(record);
                }

                return records.ToArray();
            }
        }
Esempio n. 2
0
        public double AccuracyFor(TrainingRecord[] trainingRecords)
        {
            int success = 0;

            foreach (var trainingRecord in trainingRecords)
            {
                double[] result = network.FeedForward(trainingRecord.Input);
                success += System.Math.Abs(trainingRecord.Output[GetMaxIndex(result)] - 1) < .001 ? 1 : 0;
            }

            return (double) success/trainingRecords.Length;
        }