private void PrintEAStats() { uint gensSinceLastLog = _ea.CurrentGeneration - _lastLog; if (gensSinceLastLog < 1) { gensSinceLastLog = 1; } _lastLog = _ea.CurrentGeneration; long spent = _timer.ElapsedMilliseconds - _lastLogTime; long timePerGen = spent / gensSinceLastLog; long gensRemaining = _maxGenerations - _ea.CurrentGeneration; long timeRemainingEst = gensRemaining * timePerGen; _lastLogTime = _timer.ElapsedMilliseconds; string log = $"Generation: {_ea.CurrentGeneration}/{_maxGenerations}, " + $"Time/gen: {timePerGen} ms, Est. time remaining: {Utilities.TimeToString(timeRemainingEst)} " + $"Fitness - Max: {_ea.Statistics._maxFitness:F4} Mean: {_ea.Statistics._meanFitness:F4}, " + $"Complexity - Max: {_ea.Statistics._maxComplexity:F0} Mean: {_ea.Statistics._meanComplexity:F2} " + $"Champ: {_ea.CurrentChampGenome.Complexity:F0} Strategy: {_ea.ComplexityRegulationMode}, " + $"Specie size - Max: {_ea.Statistics._maxSpecieSize:D} Min: {_ea.Statistics._minSpecieSize:D}, " + $"Generations since last improvement: {_ea.CurrentGeneration - _lastMaxFitnessImprovementGen}"; //TODO FIXME We had problems with the logger, it hangs at some point probably a buffer issue on the windows cmd??? //We had to disable the console appender on log4net and just log to the file, so there is now a console writeline instead _logger.Info(log); // Console.WriteLine(log); }
private EvaluationInfo[] TestGenome(NeatGenome genome, int iterations, int runs, bool createRecordings, bool generalize) { if (runs <= 0) { return(new EvaluationInfo[0]); } if (_ea != null && _ea.RunState == RunState.Running) { _ea.RequestPause(); } // Create the genome decoder IGenomeDecoder <NeatGenome, IBlackBox> decoder = CreateGenomeDecoder(); // Decode the genome (genotype => phenotype) IBlackBox phenome = decoder.Decode(genome); //TODO FIXME We had problems with the logger, it hangs at some point probably a buffer issue on the windows cmd??? //We had to disable the console appender on log4net and just log to the file, so there is now a console writeline instead Debug.On = true; _logger.Info($"Testing phenome {(generalize ? "generalization " : "")}(ID: {genome.Id})..."); Console.WriteLine($"Testing phenome (ID: {genome.Id})..."); EvaluationInfo[] fitness = new EvaluationInfo[runs]; CreateExperimentDirectoryIfNecessary(); // run evaluations double minFitness = double.MaxValue; double maxFitness = double.MinValue; for (int i = 0; i < runs; i++) { if (generalize) { fitness[i] = _evaluator.TestPhenomeGeneralization(phenome, iterations); fitness[i].GenomeId = genome.Id; } else { fitness[i] = _evaluator.TestPhenome(phenome, iterations); } if (fitness[i].ObjectiveFitnessMean < minFitness) { minFitness = fitness[i].ObjectiveFitnessMean; } if (fitness[i].ObjectiveFitnessMean > maxFitness) { maxFitness = fitness[i].ObjectiveFitnessMean; } if (createRecordings) { if (Recorder != null) { string recordingFile = generalize ? $"{RecordingGeneralizationFile($"{genome.Id}_{i}")}" : $"{RecordingFile($"{genome.Id}_{i}")}"; string tapeFile = generalize ? $"{TapeGeneralizationFile($"{genome.Id}_{i}")}" : $"{TapeFile($"{genome.Id}_{i}")}"; using (Bitmap bmp = Recorder.LifetimeToBitmap()) { bmp.Save(recordingFile, ImageFormat.Png); } if (Recorder.FinalTuringTape != null) { using (Bitmap bmp = Recorder.TapeToBitmap()) { bmp.Save(tapeFile, ImageFormat.Png); } } } else { _logger.Warn("Recorder was null"); break; } _logger.Info($"Run {i}: Achieved fitness: {fitness[i].ObjectiveFitnessMean:F4}"); Console.WriteLine($"Run {i}: Achieved fitness: {fitness[i].ObjectiveFitnessMean:F4}"); } } // evaluate runs if (runs > 1) { double[] fit = new double[runs]; for (int i = 0; i < runs; i++) { fit[i] = fitness[i].ObjectiveFitnessMean; } double mean = Utilities.Mean(fit); double sd = Utilities.StandartDeviation(fit); //TODO FIXME We had problems with the logger, it hangs at some point probably a buffer issue on the windows cmd??? //We had to disable the console appender on log4net and just log to the file, so there is now a console writeline instead _logger.Info($"Done. Average fitness: {mean:F4}, min fitness: {minFitness:F4}, max fitness: {maxFitness:F4}, sd: {sd:F4}"); Console.WriteLine($"Done. Average fitness: {mean:F4}, min fitness: {minFitness:F4}, max fitness: {maxFitness:F4}, sd: {sd:F4}"); } return(fitness); }