Пример #1
0
        public void TrainNetwork()
        {
            var network = CreateNetwork();

            for (int i = 0; i < 50; i++)
            {
                RunTrainning((bytes) =>
                {
                    var value = network.Train(bytes.Select(x => (double)x).ToArray(), 0.0005);
                }, 20);
            }
            network.SaveNetwork(NetworkJsonPath);

            Dictionary <int, int> groups = new Dictionary <int, int>();
            int index = 0;

            RunTrainning((bytes) =>
            {
                var value     = network.Process(bytes.Select(x => (double)x).ToArray()).ToList();
                var max       = value.Max();
                groups[index] = value.IndexOf(max);
                index++;
            }, 10);
            network = NeuralNetworkUtils.LoadNetwork(NetworkJsonPath);
            groups  = new Dictionary <int, int>();
            index   = 0;
            RunTrainning((bytes) =>
            {
                var value     = network.Process(bytes.Select(x => (double)x).ToArray()).ToList();
                var max       = value.Max();
                groups[index] = value.IndexOf(max);
                index++;
            }, 10);
            Assert.AreEqual(10, groups.Count);
        }
Пример #2
0
        private static Network CreateNetwork()
        {
            var network = NeuralNetworkUtils.CreateNeuralNetwork(28, 28, 10);

            return(network);
        }