Beispiel #1
0
        /// <summary>
        /// Training FeedForward - NeuralNetwork
        /// </summary>
        /// <param name="trainingConfiguration"></param>
        /// <param name="printLearnStatistic"></param>
        /// <param name="processPriorityClass"></param>
        /// <param name="unsafeTrainingMode"></param>
        /// <param name="iterationsToPause"></param>
        public void Train(TrainingConfiguration trainingConfiguration,
                          bool printLearnStatistic = false,
                          ProcessPriorityClass processPriorityClass = ProcessPriorityClass.Normal,
                          bool unsafeTrainingMode = false,
                          int iterationsToPause   = -1)
        {
            // Check for unexistent network:
            if (_networkTeacher == null)
            {
                Logger.LogError(ErrorType.OperationWithNonexistentNetwork, "Training failed!");
                return;
            }

            // Check for set of iterations to pause:
            if (iterationsToPause == -1)
            {
                iterationsToPause = trainingConfiguration.EndIteration - trainingConfiguration.StartIteration;
            }

            // Print warning about using unsafe mode:
            if (unsafeTrainingMode)
            {
                Logger.LogWarning(WarningType.UsingUnsafeTrainingMode);
            }

            trainingConfiguration.MemoryFolder = trainingConfiguration.MemoryFolder == "" ? "Memory" : trainingConfiguration.MemoryFolder;

            // Start process timer:
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Set the process priority class:
            Process thisProc = Process.GetCurrentProcess();

            thisProc.PriorityClass = processPriorityClass;

            if (_networkTeacher.CheckMemory(trainingConfiguration.MemoryFolder) && _networkTeacher.CheckDatasets(trainingConfiguration.InputDatasetFilename, trainingConfiguration.OutputDatasetFilename, _networkStructure))
            {
                _networkTeacher.TrainNet(trainingConfiguration, iterationsToPause, unsafeTrainingMode);

                // Stopping timer and print spend time in [HH:MM:SS]:
                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;

                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);
                Console.WriteLine("Time spend: " + elapsedTime);

                if (printLearnStatistic)
                {
                    _networkTeacher.PrintLearningStatistic(trainingConfiguration, true, elapsedTime);
                }
            }
            else
            {
                stopWatch.Stop();
                Console.WriteLine("Training failed!");
            }
        }
        public void Train(TrainConfiguration trainConfiguration, int iterationToPause = 100)
        {
            if (_networkTeacher.CheckMemory(trainConfiguration.MemoryFolder))
            {
                _networkTeacher.TrainNets(trainConfiguration, iterationToPause);

                _networkTeacher.PrintLearnStatistic(trainConfiguration, true);

                if (_networkTeacher.CheckMemory(trainConfiguration.MemoryFolder))
                {
                    _networkTeacher.BackupMemory();
                }
            }
            else
            {
                Console.WriteLine("Train failed! Invalid memory!");
            }
        }