示例#1
0
        /// <summary>
        /// Test a teacher.
        /// </summary>
        /// <param name="testNumber">The number of the test.</param>
        /// <param name="testDescription">The description of the test.</param>
        /// <param name="teacher">The teacher to test.</param>
        /// <param name="network">The network to train.</param>
        /// <param name="maxIterationCount">The maximum number of iterations.</param>
        /// <param name="maxTolerableNetworkError">The maximum tolerable network error.</param>
        private static void Test(int testNumber, string testDescription, ITeacher teacher, INetwork network, int maxIterationCount, double maxTolerableNetworkError)
        {
            // Print the number of the test and its description.
            Console.WriteLine("Test " + testNumber + " : " + testDescription);

            // Run the teacher (i.e. train the network).
            DateTime    startTime   = DateTime.Now;
            TrainingLog trainingLog = teacher.Train(network, maxIterationCount, maxTolerableNetworkError);
            DateTime    endTime     = DateTime.Now;

            // Print the results.
            Console.WriteLine("Test " + testNumber + " : Duration : " + (endTime - startTime));
            Console.WriteLine("Test " + testNumber + " : Number of iterations taken : " + trainingLog.IterationCount);
            Console.WriteLine("Test " + testNumber + " : Network error achieved : " + trainingLog.NetworkError);
            foreach (TrainingPattern trainingPattern in teacher.TrainingSet.TrainingPatterns)
            {
                double[] outputVector = network.Evaluate(trainingPattern.InputVector);
                Console.WriteLine(
                    TrainingPattern.VectorToString(trainingPattern.InputVector) +
                    " -> " +
                    TrainingPattern.VectorToString(outputVector)
                    );
            }
        }