示例#1
0
        static void Main(string[] args)
        {
            ServiceEvaNN serviceEvaNN = new ServiceEvaNN();

            NetworkStructure netStructure = new NetworkStructure
            {
                InputVectorLength = 10,
                NeuronsByLayers   = new[] { 230, 150, 120, 1 }
            };

            TrainingConfiguration trainConfig = new TrainingConfiguration
            {
                TrainingAlgorithmType = TrainingAlgorithmType.RProp,
                StartIteration        = 0,
                EndIteration          = 10,
                InputDatasetFilename  = "TrainingSets//inputSets.txt",
                OutputDatasetFilename = "TrainingSets//outputSets.txt",
                MemoryFolder          = "Memory"
            };

            bool creatingSucceed = serviceEvaNN.CreateNetwork(trainConfig.MemoryFolder, netStructure);

            if (creatingSucceed)
            {
                //serviceEvaNN.CalculateStatistic(trainConfig);
                serviceEvaNN.Train(trainConfig,
                                   true,
                                   ProcessPriorityClass.Normal,
                                   true);
                serviceEvaNN.CalculateStatistic(trainConfig);
            }

            Console.WriteLine("Done!");
            Console.ReadKey();
        }
示例#2
0
        public void TestRProp()
        {
            // Arrange:
            ServiceEvaNN serviceEvaNN = new ServiceEvaNN();

            NetworkStructure netStructure = new NetworkStructure
            {
                InputVectorLength = 2,
                NeuronsByLayers   = new[] { 23, 15, 1 }
            };

            TrainingConfiguration trainConfig = new TrainingConfiguration
            {
                TrainingAlgorithmType = TrainingAlgorithmType.RProp,
                StartIteration        = 0,
                EndIteration          = 100,
                InputDatasetFilename  = "TrainingSetsTest//inputSets.txt",
                OutputDatasetFilename = "TrainingSetsTest//outputSets.txt",
                MemoryFolder          = "MemoryRProp"
            };

            if (!Directory.Exists("TrainingSetsTest"))
            {
                Directory.CreateDirectory("TrainingSetsTest");
                CreateDataSets(trainConfig);
            }

            if (File.Exists(trainConfig.MemoryFolder + "//memory.txt"))
            {
                File.Delete(trainConfig.MemoryFolder + "//memory.txt");
            }

            bool creatingSucceed = serviceEvaNN.CreateNetwork(trainConfig.MemoryFolder, netStructure);

            if (creatingSucceed)
            {
                serviceEvaNN.Train(trainConfig,
                                   true,
                                   ProcessPriorityClass.Normal,
                                   true);
            }

            // Asserts:
            double tolerance = 0.15;

            double[] result0 = serviceEvaNN.Handle(new double[] { 0, 0 });
            Assert.IsNotNull(result0);
            Assert.AreEqual(0.0, result0[0], tolerance);

            double[] result1 = serviceEvaNN.Handle(new double[] { 0, 1 });
            Assert.IsNotNull(result1);
            Assert.AreEqual(0.0, result1[0], tolerance);

            double[] result2 = serviceEvaNN.Handle(new double[] { 1, 0 });
            Assert.IsNotNull(result2);
            Assert.AreEqual(0.0, result2[0], tolerance);

            double[] result3 = serviceEvaNN.Handle(new double[] { 1, 1 });
            Assert.IsNotNull(result3);
            Assert.AreEqual(1.0, result3[0], tolerance);
        }