private NeatEvolutionAlgorithm <NeatGenome> GenerateTeam() { NeatEvolutionAlgorithmParameters neatParams = new NeatEvolutionAlgorithmParameters(); IDistanceMetric distanceMetric = new ManhattanDistanceMetric(0.4, 1.0, 0.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric); IComplexityRegulationStrategy complexityStrategy = new NullComplexityRegulationStrategy(); return(new NeatEvolutionAlgorithm <NeatGenome>(neatParams, speciationStrategy, complexityStrategy)); }
public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList, IGenomeListEvaluator <NeatGenome> eval = 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. IComplexityRegulationStrategy complexityRegulationStrategy = new NullComplexityRegulationStrategy();// ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create the MC evaluator PasswordCrackingEvaluator.Passwords = _passwords; // Create genome decoder. IGenomeDecoder <NeatGenome, MarkovChain> genomeDecoder = CreateGenomeDecoder(); // If we're running specially on Condor, skip this if (eval == null) { _evaluator = new PasswordCrackingEvaluator(_guesses, Hashed); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. // IGenomeListEvaluator<NeatGenome> innerEvaluator = new ParallelGenomeListEvaluator<NeatGenome, MarkovChain>(genomeDecoder, _evaluator, _parallelOptions); IGenomeListEvaluator <NeatGenome> innerEvaluator = new ParallelNEATGenomeListEvaluator <NeatGenome, MarkovChain>(genomeDecoder, _evaluator, this); /* * // Wrap the list evaluator in a 'selective' evaulator that will only evaluate new genomes. That is, we skip re-evaluating any genomes * // that were in the population in previous generations (elite genomes). This is determiend by examining each genome's evaluation info object. * IGenomeListEvaluator<NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator<NeatGenome>( * innerEvaluator, * SelectiveGenomeListEvaluator<NeatGenome>.CreatePredicate_OnceOnly()); */ // Initialize the evolution algorithm. ea.Initialize(innerEvaluator, genomeFactory, genomeList); } else { // Initialize the evolution algorithm. ea.Initialize(eval, genomeFactory, genomeList); } // Finished. Return the evolution algorithm return(ea); }
public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm( IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; // for matched genes the distance is their weight difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = new NullComplexityRegulationStrategy(); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(this.eaParams, speciationStrategy, complexityRegulationStrategy); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = this.CreateGenomeDecoder(); var evaluator = new Evaluator(); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. //IGenomeListEvaluator<NeatGenome> innerEvaluator = // new SerialGenomeListEvaluator<NeatGenome, IBlackBox>(genomeDecoder, evaluator); IGenomeListEvaluator <NeatGenome> innerEvaluator = new ParallelGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator); // Wrap the list evaluator in a 'selective' evaluator that will only evaluate new genomes. // That is, we skip re-evaluating any genomes that were in the population in previous // generations (elite genomes). This is determined by examining each genome's evaluation info object. IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>( innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); // Initialize the evolution algorithm. ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); ea.UpdateScheme = new UpdateScheme(1); // Finished. Return the evolution algorithm return(ea); }
/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome2 population and their associated/parent genome2 factory. /// </summary> public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // 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, new ParallelOptions()); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = new NullComplexityRegulationStrategy();// ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the phenome evaluator. _evaluator = new ForagingEvaluator <NeatGenome>(genomeDecoder, _world, _agentType, _navigationEnabled, _hidingEnabled) { MaxTimeSteps = _timeStepsPerGeneration, EvoParadigm = _paradigm, MemParadigm = _memory, GenerationsPerMemorySize = _memGens, MaxMemorySize = _maxMemorySize, TeachParadigm = _teaching, TrialId = TrialId, PredatorCount = _predCount, PredatorDistribution = PredatorDistribution, PredatorTypes = _predTypes, PredatorGenerations = _predGens, DistinguishPredators = _distinguishPreds, LogDiversity = _logDiversity }; // Initialize the evolution algorithm. ea.Initialize(_evaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
private static void Train() { File.WriteAllText($"{NeatConsts.experimentName}/fitness.csv", "generation,firness\n"); var neatGenomeFactory = new NeatGenomeFactory(NeatConsts.ViewX * NeatConsts.ViewY * NeatConsts.typeIds.Count, 1); var genomeList = neatGenomeFactory.CreateGenomeList(NeatConsts.SpecCount, 0); var eaParams = new NeatEvolutionAlgorithmParameters { SpecieCount = NeatConsts.SpecCount }; //var distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); var distanceMetric = new ManhattanDistanceMetric(); var parallelOptions = new ParallelOptions(); var speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric, parallelOptions); //var speciationStrategy = new KMeansClusteringStrategy<NeatGenome>(distanceMetric); //var speciationStrategy = new RandomClusteringStrategy<NeatGenome>(); var complexityRegulationStrategy = new NullComplexityRegulationStrategy(); //var complexityRegulationStrategy = new DefaultComplexityRegulationStrategy(ComplexityCeilingType.Relative, 0.50); var ea = new NeatEvolutionAlgorithm <NeatGenome>(eaParams, speciationStrategy, complexityRegulationStrategy); var activationScheme = NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(1); var genomeDecoder = new NeatGenomeDecoder(activationScheme); var phenomeEvaluator = new GameEvaluator(); var genomeListEvaluator = new ParallelGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, phenomeEvaluator, parallelOptions); ea.Initialize(genomeListEvaluator, neatGenomeFactory, genomeList); ea.UpdateScheme = new UpdateScheme(NeatConsts.LogRate); ea.StartContinue(); ea.UpdateEvent += Ea_UpdateEvent; while (ea.RunState != RunState.Paused) { } ea.Stop(); }