Пример #1
0
        /// <summary>
        /// Обучение нейросети
        /// </summary>
        public void TrainNet()
        {
            #region Preparing learning DATA

            var vectorLoader = new WordVectorLoader("vectorizedData");
            Console.WriteLine("Load input & output sets...");
            var inputDataSets = vectorLoader.LoadVectorsData(_receptors, _numberOfOutputClasses, out var outputDataSets);

            #endregion

            #region Net training

            Console.WriteLine("Training net...");
            try
            {
                using (var progress = new ProgressBar())
                {
                    for (int iteration = 0; iteration < Iteration; iteration++)
                    {
                        // Calculating learn-speed rate:
                        var learningSpeed = 0.01 * Math.Pow(0.1, iteration / 150000);
                        for (int k = 0; k < inputDataSets.Count; k++)
                        {
                            _net.Handle(inputDataSets[k]);
                            _net.Teach(inputDataSets[k], outputDataSets[k], learningSpeed);
                        }

                        progress.Report((double)iteration / 100);
                        TestResult(TestVectors, iteration);
                    }

                    // Save network memory:
                    _net.SaveMemory();
                }

                Console.WriteLine("Training success!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Training failed!" + ex.Message);
            }

            #endregion
        }
Пример #2
0
        public void PreparingLearningData(bool primaryLoad = true, bool withMerging = false)
        {
            #region Load data from files
            var stopWatch    = Stopwatch.StartNew();
            var vectorLoader = new WordVectorLoader();
            Console.WriteLine("Load input & output sets...");

            var inputDataSets = primaryLoad
                ? vectorLoader.LoadVectorsData("vectorizedData", out var outputDataSets)
                : vectorLoader.LoadSecondaryVectorsData("data", out outputDataSets);

            ShowTime(stopWatch.Elapsed);
            #endregion

            #region Vector merging

            if (withMerging)
            {
                Console.WriteLine("Start vector merging...");
                _merger = new Merger();
                var list = _merger.MergeItems(inputDataSets, outputDataSets);
                Console.WriteLine("Save results...");

                _fileManager.SaveVectors(list[0], "inputSets.txt");
                _fileManager.SaveVectors(list[1], "outputSets.txt");
            }
            else
            {
                Console.WriteLine("Save results...");

                _fileManager.SaveVectors(inputDataSets, "inputSets.txt");
                _fileManager.SaveVectors(outputDataSets, "outputSets.txt");
            }

            ShowTime(stopWatch.Elapsed); stopWatch.Stop();
            Console.WriteLine("Save result done!");
            #endregion
        }