Esempio n. 1
0
 public OnlineTrainer(IErrorCalculator errorCalculator, ILearningProvider dataProvider, LearningAlgorithm learningAlgorithm)
 {
     ErrorCalculator   = errorCalculator;
     DataProvider      = dataProvider;
     LearningAlgorithm = learningAlgorithm;
     tester            = new NetworkTester(ErrorCalculator);
 }
Esempio n. 2
0
        /// <summary>
        /// Checks if new given network is better than current best. If it is, stores it as best.
        /// </summary>
        /// <param name="newNetwork"></param>
        /// <returns>True if best network was changed. Otherwise, false</returns>
        private bool UpdateBestNetwork(NeuralNetwork newNetwork)
        {
            var tester = new NetworkTester(ErrorCalculator);

            if (BestNetwork is null) //save new network as best
            {
                BestNetwork   = newNetwork;
                BestTestError = tester.TestNetwork(BestNetwork, DataProvider);
                return(true);
            }
            else // test new network and compare
            {
                var newNetworkError = tester.TestNetwork(newNetwork, DataProvider);
                if (newNetworkError < BestTestError)
                {
                    BestNetwork   = newNetwork;
                    BestTestError = newNetworkError;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }