/// <summary> /// Create and return a SteadyStateNeatEvolutionAlgorithm object (specific to fitness-based evaluations) ready for /// running the /// NEAT algorithm/search based on the given genome factory and genome list. Various sub-parts of the algorithm are /// also constructed and connected up. /// </summary> /// <param name="genomeFactory">The genome factory from which to generate new genomes</param> /// <param name="genomeList">The current genome population</param> /// <param name="startingEvaluations">The number of evaluations that have been executed prior to the current run.</param> /// <returns>Constructed evolutionary algorithm</returns> public override INeatEvolutionAlgorithm<NeatGenome> CreateEvolutionAlgorithm( IGenomeFactory<NeatGenome> genomeFactory, List<NeatGenome> genomeList, ulong startingEvaluations) { FileDataLogger logger = null; // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy<NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy<NeatGenome>(distanceMetric, ParallelOptions); // Create complexity regulation strategy. var complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(ComplexityRegulationStrategy, Complexitythreshold); // Initialize the logger if (_generationalLogFile != null) { logger = new FileDataLogger(_generationalLogFile); } // Create the evolution algorithm. var ea = new SteadyStateNeatEvolutionAlgorithm<NeatGenome>(NeatEvolutionAlgorithmParameters, speciationStrategy, complexityRegulationStrategy, _batchSize, _populationEvaluationFrequency, RunPhase.Primary, logger); // Create IBlackBox evaluator. var mazeNavigationEvaluator = new MazeNavigationMCNSEvaluator(MaxDistanceToTarget, MaxTimesteps, MazeVariant, MinSuccessDistance, _behaviorCharacterizationFactory); // Create genome decoder. var genomeDecoder = CreateGenomeDecoder(); // Create a novelty archive. AbstractNoveltyArchive<NeatGenome> archive = new BehavioralNoveltyArchive<NeatGenome>(_archiveAdditionThreshold, _archiveThresholdDecreaseMultiplier, _archiveThresholdIncreaseMultiplier, _maxGenerationArchiveAddition, _maxGenerationsWithoutArchiveAddition); // IGenomeEvaluator<NeatGenome> fitnessEvaluator = // new SerialGenomeBehaviorEvaluator<NeatGenome, IBlackBox>(genomeDecoder, mazeNavigationEvaluator, // _nearestNeighbors, archive); IGenomeEvaluator<NeatGenome> fitnessEvaluator = new ParallelGenomeBehaviorEvaluator<NeatGenome, IBlackBox>(genomeDecoder, mazeNavigationEvaluator, SelectionType.SteadyState, SearchType.MinimalCriteriaNoveltySearch, _nearestNeighbors, archive); // Initialize the evolution algorithm. ea.Initialize(fitnessEvaluator, genomeFactory, genomeList, 0, MaxEvaluations, archive); // Finished. Return the evolution algorithm return ea; }
/// <summary> /// Create and return a SteadyStateNeatEvolutionAlgorithm object (specific to fitness-based evaluations) ready for /// running the /// NEAT algorithm/search based on the given genome factory and genome list. Various sub-parts of the algorithm are /// also constructed and connected up. /// </summary> /// <param name="genomeFactory">The genome factory from which to generate new genomes</param> /// <param name="genomeList">The current genome population</param> /// <param name="startingEvaluations">The number of evaluations that have been executed prior to the current run.</param> /// <returns>Constructed evolutionary algorithm</returns> public override INeatEvolutionAlgorithm<NeatGenome> CreateEvolutionAlgorithm( IGenomeFactory<NeatGenome> genomeFactory, List<NeatGenome> genomeList, ulong startingEvaluations) { FileDataLogger logger = null; // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy<NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy<NeatGenome>(distanceMetric, ParallelOptions); // Create complexity regulation strategy. var complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(ComplexityRegulationStrategy, Complexitythreshold); // Initialize the logger if (_generationalLogFile != null) { logger = new FileDataLogger(_generationalLogFile); } // Create the evolution algorithm. var ea = new SteadyStateNeatEvolutionAlgorithm<NeatGenome>(NeatEvolutionAlgorithmParameters, speciationStrategy, complexityRegulationStrategy, _batchSize, _populationEvaluationFrequency, RunPhase.Primary, logger); // Create IBlackBox evaluator. var mazeNavigationEvaluator = new MazeNavigationRandomEvaluator(MaxDistanceToTarget, MaxTimesteps, MazeVariant, MinSuccessDistance); // Create genome decoder. var genomeDecoder = CreateGenomeDecoder(); IGenomeEvaluator<NeatGenome> fitnessEvaluator = new ParallelGenomeFitnessEvaluator<NeatGenome, IBlackBox>(genomeDecoder, mazeNavigationEvaluator, ParallelOptions); // Initialize the evolution algorithm. ea.Initialize(fitnessEvaluator, genomeFactory, genomeList, null, MaxEvaluations); // Finished. Return the evolution algorithm return ea; }
/// <summary> /// Configures and instantiates the initialization evolutionary algorithm. /// </summary> /// <param name="parallelOptions">Synchronous/Asynchronous execution settings.</param> /// <param name="genomeList">The initial population of genomes.</param> /// <param name="genomeFactory">The genome factory initialized by the main evolution thread.</param> /// <param name="genomeDecoder">The decoder to translate genomes into phenotypes.</param> /// <param name="startingEvaluations"> /// The number of evaluations that preceeded this from which this process will pick up /// (this is used in the case where we're restarting a run because it failed to find a solution in the allotted time). /// </param> public void InitializeAlgorithm(ParallelOptions parallelOptions, List<NeatGenome> genomeList, IGenomeFactory<NeatGenome> genomeFactory, IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, ulong startingEvaluations) { // Set the boiler plate algorithm parameters base.InitializeAlgorithm(parallelOptions, genomeList, genomeDecoder, startingEvaluations); // Create the initialization evolution algorithm. InitializationEa = new SteadyStateNeatEvolutionAlgorithm<NeatGenome>(NeatEvolutionAlgorithmParameters, SpeciationStrategy, ComplexityRegulationStrategy, _batchSize, _populationEvaluationFrequency, RunPhase.Initialization, _evolutionDataLogger, _initializationLogFieldEnableMap); // Create IBlackBox evaluator. MazeNavigationMCSInitializationEvaluator mazeNavigationEvaluator = new MazeNavigationMCSInitializationEvaluator(MaxDistanceToTarget, MaxTimesteps, _mazeVariant, MinSuccessDistance, _behaviorCharacterizationFactory, startingEvaluations); // Create a novelty archive. AbstractNoveltyArchive<NeatGenome> archive = new BehavioralNoveltyArchive<NeatGenome>(_archiveAdditionThreshold, _archiveThresholdDecreaseMultiplier, _archiveThresholdIncreaseMultiplier, _maxGenerationArchiveAddition, _maxGenerationsWithoutArchiveAddition); // IGenomeEvaluator<NeatGenome> fitnessEvaluator = // new SerialGenomeBehaviorEvaluator<NeatGenome, IBlackBox>(genomeDecoder, mazeNavigationEvaluator, // SelectionType.SteadyState, SearchType.NoveltySearch, // _nearestNeighbors, archive, _evaluationDataLogger, _serializeGenomeToXml); IGenomeEvaluator<NeatGenome> fitnessEvaluator = new ParallelGenomeBehaviorEvaluator<NeatGenome, IBlackBox>(genomeDecoder, mazeNavigationEvaluator, SelectionType.SteadyState, SearchType.NoveltySearch, _nearestNeighbors, archive, _evaluationDataLogger, _serializeGenomeToXml); // Only pull the number of genomes from the list equivalent to the initialization algorithm population size // (this is to handle the case where the list was created in accordance with the primary algorithm // population size, which could have been larger) genomeList = genomeList.Take(PopulationSize).ToList(); // Replace genome factory primary NEAT parameters with initialization parameters ((NeatGenomeFactory)genomeFactory).ResetNeatGenomeParameters(NeatGenomeParameters); // Initialize the evolution algorithm. InitializationEa.Initialize(fitnessEvaluator, genomeFactory, genomeList, PopulationSize, null, _maxEvaluations + startingEvaluations, archive); }