Esempio n. 1
0
        private static void GeneralizeAllChamps()
        {
            string[] xmls = Directory.GetFiles(_currentDir, "champion_genome*.xml", SearchOption.AllDirectories);
            Console.WriteLine($"Found {xmls.Length} champion genomes");

            int count      = xmls.Length;
            int iterations = GetIntegerConsoleInput("Enter number of iterations:");

            NextExperiment();

            EvaluationInfo[] results = new EvaluationInfo[count];
            for (int i = 0; i < count; i++)
            {
                results[i] = _experiment.TestSavedChampion(xmls[i], iterations, 1, true, true)[0];
            }

            try
            {
                string genDataFile = $"{_currentDir}/{DATA_FILE_GEN}";

                using (StreamWriter sw = File.AppendText(genDataFile))
                {
                    sw.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", "Genome", "Iterations", "Mean", "Standard Deviation", "Max", "Min");

                    for (int i = 0; i < count; i++)
                    {
                        EvaluationInfo res = results[i];

                        sw.WriteLine(string.Format(CultureInfo.InvariantCulture,
                                                   "{0},{1},{2:F4},{3:F4},{4:F4},{5:F4}",
                                                   xmls[i], res.Iterations, res.ObjectiveFitnessMean, res.ObjectiveFitnessStandardDeviation, res.ObjectiveFitnessMax, res.ObjectiveFitnessMin));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Warn($"Could not write to generalization file: {ex.Message}", ex);
            }

            Console.WriteLine("Done. Press any key to exit...");
            Console.ReadKey();
        }