/// <summary> /// Completes the generation information history and exports it to file. /// </summary> public void CompleteAndExportGenerationHistory() { if (this._configuration.ScoreGenerationHistory && this._runEvaluator is IMetricRunEvaluator <TResult> metricRunEvaluator) { var scorer = new GenerationInformationScorer <TInstance, TResult>( this._genomeSorter, this._targetRunResultStorage, metricRunEvaluator); scorer.ScoreInformationHistory(this._informationHistory, this._trainingInstances, this._testInstances); RunStatisticTracker.ExportAverageIncumbentScores(this._informationHistory, this._configuration.EvaluationLimit); } RunStatisticTracker.ExportGenerationHistory(this._informationHistory); }
public void ExportAverageIncumbentScoresThrowsForMissingHistory() { Assert.Throws <ArgumentNullException>( () => RunStatisticTracker.ExportAverageIncumbentScores(informationHistory: null, evaluationLimit: 200)); }
public void ExportAverageIncumbentScoresDeterminesScoresCorrectly() { var incumbent = new ImmutableGenome(new Genome()); var strategy = typeof(GgaStrategy <TestInstance, TestResult>); // Check what happens if the first generation takes more than 100 evaluations. var generation0 = new GenerationInformation(0, TimeSpan.Zero, 150, strategy, incumbent, "id"); generation0.IncumbentTrainingScore = -34.5; generation0.IncumbentTestScore = -20; // Check what happens for multiple information objects within one evaluation level. var generation1 = new GenerationInformation(1, TimeSpan.Zero, 199, strategy, incumbent, "id"); generation1.IncumbentTrainingScore = 12.34; generation1.IncumbentTestScore = 28.6; // Check what happens for an evaluation number equal to a bound. var generation2 = new GenerationInformation(2, TimeSpan.Zero, 300, strategy, incumbent, "id"); generation2.IncumbentTrainingScore = 12.01; generation2.IncumbentTestScore = 29; // Check what happens if there is no information object in a certain level (301-400). var generation3 = new GenerationInformation(2, TimeSpan.Zero, 401, strategy, incumbent, "id"); generation3.IncumbentTrainingScore = 14; generation3.IncumbentTestScore = 286; // Make sure to try an evaluation limit higher than the last total number of evaluations. RunStatisticTracker.ExportAverageIncumbentScores( new List <GenerationInformation> { generation0, generation1, generation2, generation3 }, 600); var exported = File.ReadAllLines("scores.csv"); Assert.True(7 == exported.Length, "Expected seven lines: One legend and six evaluation levels."); Assert.True( "# Evaluations;Average Train Incumbent;Average Test Incumbent" == exported[0], "Legend is not as expected."); Assert.True( "100;;" == exported[1], "There should be an empty line as first information is only gathered at 150 evaluations."); Assert.True( "200;12.34;28.6" == exported[2], "First score line should use latest information."); Assert.True( "300;12.01;29" == exported[3], "Second score line should use information with evaluation number equal to the bound."); Assert.True( "400;12.01;29" == exported[4], "Third score line should not change scores."); Assert.True( "500;14;286" == exported[5], "Fourth score line should use the newest data again."); Assert.True( "600;14;286" == exported[6], "Fifth score line should be written to have scores until the limit."); }