예제 #1
0
        /// <summary>
        /// Trains the network
        /// </summary>
        /// <param name="network">the network to train</param>
        private static void Train(Network network)
        {
            Tuple <double[], double[]>[] _trainingData = GetMNISTData(true, 60000);
            Tuple <double[], double[]>[] _testingData  = GetMNISTData(false, 5000);

            NetworkTrainer _trainer = new NetworkTrainer(network);

            foreach (Tuple <int, double?> _result in _trainer.StochasticGradientDescent(10000, _trainingData, 1000, 100, .05, _testingData))
            {
                Console.WriteLine($"Epoch {_result.Item1}: {_result.Item2}% error");
            }
        }
예제 #2
0
        public ParkingSpaceClassifier()
        {
            //int dataWidth = 4;
            //int dataHeight = 4;
            //int inputSize = dataWidth * dataHeight;
            //Net = new Network(inputSize, new[] { 20, 10 }, 1);

            //NetworkTrainer trainer = new NetworkTrainer(Net);
            ////--------------------------------------------------
            //// Training data
            //List<Tuple<Bitmap, Bitmap>> training = new List<Tuple<Bitmap, Bitmap>>();
            //int trainingSize = 1000;
            //for (int i = 0; i < trainingSize;i++)
            //	training.Add(GenerateLabeled(dataWidth, dataHeight));
            ////--------------------------------------------------
            //// Test data
            //List<Tuple<Bitmap, Bitmap>> test = new List<Tuple<Bitmap, Bitmap>>();
            //int testSize = 200;
            //for (int i = 0; i < testSize; i++)
            //	test.Add(GenerateLabeled(dataWidth, dataHeight));

            //Error = trainer.StochasticGradientDescent(trainingSize, training.Select(t => Flatten(t)).ToArray(), 1000, 100, .05, test.Select(t => Flatten(t)).ToArray());

            if (File.Exists("./data/MNIST_weights.dat"))
            {
                Load();
            }
            else
            {
                Net = new Network(784, new[] { 100, 50 }, 10);
            }

            Iterations = 1000;
            NetworkTrainer trainer = new NetworkTrainer(Net);

            Tuple <double[], double[]>[] _testData     = GetTestData();
            Tuple <double[], double[]>[] _trainingData = GetTrainingData();
            Error = trainer.StochasticGradientDescent(10000, _trainingData, Iterations, 100, .05, _testData);
        }