/// <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 genome population and their associated/parent genome 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 weight 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 = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. PreyCaptureEvaluator evaluator = new PreyCaptureEvaluator(_trialsPerEvaluation, _gridSize, _preyInitMoves, _preySpeed, _sensorRange, _maxTimesteps); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // TODO: evaluation scheme that re-evaluates existing genomes and takes average over time. // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> genomeListEvaluator = new ParallelGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _parallelOptions); // Initialize the evolution algorithm. ea.Initialize(genomeListEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
public ScatterPlotView(IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder, IClusteringDataset dataset, int nbClusters) : this() { this.dataset = dataset; this.nbClusters = nbClusters; this.decoder = genomeDecoder; }
/// <summary> /// Construct with the provided genome decoder and phenome evaluator. /// </summary> /// <param name="genomeDecoder">Genome decoder.</param> /// <param name="phenomeEvaluationScheme">Phenome evaluation scheme.</param> /// <param name="degreeOfParallelism">The desired degree of parallelism.</param> public ParallelGenomeListEvaluator( IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluationScheme <TPhenome> phenomeEvaluationScheme, int degreeOfParallelism) { // This class should only be used with evaluation schemes that use evaluators with state, // otherwise ParallelGenomeListEvaluatorStateless should be used. if (!phenomeEvaluationScheme.EvaluatorsHaveState) { throw new ArgumentException(nameof(phenomeEvaluationScheme)); } // Reject degreeOfParallelism values less than 2. -1 should have been resolved to an actual number by the time // this constructor is invoked, and 1 is nonsensical for a parallel evaluator. if (degreeOfParallelism < 2) { throw new ArgumentException(nameof(degreeOfParallelism)); } _genomeDecoder = genomeDecoder; _phenomeEvaluationScheme = phenomeEvaluationScheme; _parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = degreeOfParallelism }; // Create a pool of phenome evaluators. // Note. the pool is initialised with a number of pre-constructed evaluators that matches // degreeOfParallelism. We don't expect the pool to be asked for more than this number of // evaluators at any given point in time. _evaluatorPool = new PhenomeEvaluatorStackPool <TPhenome>( phenomeEvaluationScheme, degreeOfParallelism); }
public double[] GetChampOutput(int nodeDepth, int nodeSiblingNum, int maxDepth, int maxBranching) { IGenomeDecoder <NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); IBlackBox box = decoder.Decode(contentEA.CurrentChampGenome); // Normalize nodeDepth and nodeSiblingNum to range of 0-1. This may affect outputs? double normDepth = (double)nodeDepth / (double)maxDepth; double normSib; if (nodeDepth == 0) { normSib = 0; // Only one node at depth 0, prevent a divide by 0 error } else { normSib = (double)nodeSiblingNum / (double)(Mathf.Pow(maxBranching, nodeDepth) - 1); } box.InputSignalArray[0] = normDepth; box.InputSignalArray[1] = normSib; box.ResetState(); box.Activate(); //Debug.Log("(" + normDepth + "," + normSib + ") -> (" + box.OutputSignalArray[0] + "," + box.OutputSignalArray[1] + "," + box.OutputSignalArray[2] + "," //+ box.OutputSignalArray[3] + "," + box.OutputSignalArray[4] + "," + box.OutputSignalArray[5] + ")"); double[] outputs = new double[box.OutputCount]; for (int i = 0; i < box.OutputCount; i++) { outputs[i] = box.OutputSignalArray[i]; } return(outputs); }
public void Init(SnakeRunnerSmart snakeRunner, IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder) { _snakeRunner = snakeRunner; _sw = _snakeRunner.SnakeWorld; _genomeDecoder = genomeDecoder; this.Size = new Size((_sw.Width + 2) * _scaleFactor, (_sw.Height + 6) * _scaleFactor); }
/// <summary> /// Construct with the provided <see cref="IGenomeDecoder"/> and <see cref="IPhenomeEvaluator"/>. /// Phenome caching is enabled by default. /// </summary> public SerialGenomeListEvaluator( IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; }
/// <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, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = 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. IGenomeListEvaluator <NeatGenome> genomeListEvaluator = new ParallelCoevolutionListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, PhenomeEvaluator); // Wrap a hall of fame evaluator around the baseline evaluator. genomeListEvaluator = new ParallelHallOfFameListEvaluator <NeatGenome, IBlackBox>(50, 0.5, ea, genomeListEvaluator, genomeDecoder, PhenomeEvaluator); // Initialize the evolution algorithm. ea.Initialize(genomeListEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
public MultiObjectiveListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IMultiObjectiveEvaluator <TPhenome> phenomeEvaluator, INoveltyScorer <TGenome> noveltyScorer, IList <IObjectiveScorer <TGenome> > objectiveScorers, IMultiObjectiveScorer multiObjectiveScorer, bool enableMultiThreading, ParallelOptions options) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; _noveltyScorer = noveltyScorer; _objectiveScorers = objectiveScorers; for (int i = 0; i < _objectiveScorers.Count; i++) { _objectiveScorers[i].Objective = i + 1; } _multiObjectiveScorer = multiObjectiveScorer; _parallelOptions = options; _generation = 0; // Determine the appropriate evaluation method. if (enableMultiThreading) { _evalMethod = EvaluateParallel; } else { _evalMethod = EvaluateSerial; } }
/// <summary> /// Construct the view with an appropriately configured world and a genome decoder for decoding genomes as they are passed into RefreshView(). /// </summary> public PreyCaptureView(IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder, PreyCaptureWorld world) { try { InitializeComponent(); _genomeDecoder = genomeDecoder; _world = world; // Create a bitmap for the picturebox. int width = Width; int height = Height; _image = new Bitmap(width, height, ViewportPixelFormat); pbx.Image = _image; // Create background thread for running simulation alongside NEAT algorithm. _simThread = new Thread(new ThreadStart(SimulationThread)); _simThread.IsBackground = true; _simThread.Start(); } finally { _initializing = false; } }
public void Initialize(IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, IMapClusteringDataset dataset, MapClusteringEvaluator evaluator, int nbClusters) { this.dataset = dataset; this.nbClusters = nbClusters; this.decoder = genomeDecoder; this.evaluator = evaluator; samples = dataset.GetSamplesMatrix(); outputs = new double[nbClusters, samples.GetLength(1), samples.GetLength(2)]; this.nbInputs = samples.GetLength(0); maxValue = 0.0; for (var i = 0; i < samples.GetLength(0); i++) { for (var j = 0; j < samples.GetLength(1); j++) { for (var k = 0; k < samples.GetLength(2); k++) { var value = samples[i, j, k]; if (value > maxValue) maxValue = value; } } } maxValue *= 2; // margin }
/// <summary> /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and ParallelOptions. /// </summary> public ParallelGenomeListEvaluator( IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluationScheme <TPhenome> phenomeEvaluatorScheme, ParallelOptions parallelOptions) { // This class should only be used with evaluation schemes that use evaluators with state, // otherwise ParallelGenomeListEvaluatorStateless should be used. if (!phenomeEvaluatorScheme.EvaluatorsHaveState) { throw new ArgumentException(nameof(phenomeEvaluatorScheme)); } _genomeDecoder = genomeDecoder; _phenomeEvaluationScheme = phenomeEvaluatorScheme; _parallelOptions = parallelOptions; // Resolve concurrency level. int concurrencyLevel = parallelOptions.MaxDegreeOfParallelism; if (concurrencyLevel == -1) { concurrencyLevel = Environment.ProcessorCount; } // Create a pool of phenome evaluators. // Note. the pool is initialised with a number of pre-constructed evaluators that matches // MaxDegreeOfParallelism. We don't expect the pool to be asked for more than this number of // evaluators at any given point in time. _evaluatorPool = new PhenomeEvaluatorStackPool <TPhenome>( phenomeEvaluatorScheme, concurrencyLevel); }
public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new KMeansClusteringStrategy <NeatGenome>(distanceMetric); IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create black box evaluator AgarEvaluator evaluator = new AgarEvaluator(_optimizer); IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); IGenomeListEvaluator <NeatGenome> innerEvaluator = new UnitySingleGenomeEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _optimizer); IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>(innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); //ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); 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 genome population and their associated/parent genome 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, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. _evaluator = CreateEvaluator(); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> innerEvaluator = new SerialGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, _evaluator); /*new ParallelGenomeListEvaluator<NeatGenome, IBlackBox>(genomeDecoder, _evaluator, _parallelOptions);*/ // 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 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); // Finished. Return the evolution algorithm return(ea); }
public ScatterPlotView(IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, IClusteringDataset dataset, int nbClusters) : this() { this.dataset = dataset; this.nbClusters = nbClusters; this.decoder = genomeDecoder; }
/// <summary> /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and ParalleOptions. /// Phenome caching is enabled by default. /// The number of parallel threads defaults to Environment.ProcessorCount. /// </summary> public ParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator, ParallelOptions options) //: this(genomeDecoder, phenomeEvaluator, options, true) : this(genomeDecoder, phenomeEvaluator, options, false) { }
public IPDDomain(IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder, ref IPDExperiment.Info info) { InitializeComponent(); try { _genomeDecoder = genomeDecoder; _info = info; _players = new IPDPlayer[info.OpponentPool.Length + 1]; _players[0] = new Players.IPDPlayerPhenome(null); Array.Copy(info.OpponentPool, 0, _players, 1, info.OpponentPool.Length); _games = new IPDGame[info.OpponentPool.Length + 1, info.OpponentPool.Length + 1]; for (int i = 1; i < _players.Length; i++) { for (int j = 1; j < _players.Length; j++) { _games[i, j] = info.OpponentPoolGames[i - 1, j - 1]; } } SuspendLayout(); CreateTable(); CreateArchiveGraph(); CreateInfoLabel(); CreateSSButtons(); ResumeLayout(); } catch { } }
private static void TestGenome(IGenomeDecoder<NeatGenome, IBlackBox> decoder, NeatGenome genome) { // Decode the genome into a phenome (neural network). IBlackBox phenome = decoder.Decode(genome); List<string> lines = new List<string>(); double v = 0f; while (v < Math.PI * 2f) { phenome.ResetState(); phenome.InputSignalArray[0] = v; phenome.Activate(); double result = phenome.OutputSignalArray[0]; lines.Add(string.Format("{0}\t{1}", v, result)); v += 0.1d; } System.IO.File.WriteAllLines(@"output.csv", lines); }
public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new KMeansClusteringStrategy <NeatGenome>(distanceMetric); IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create black box evaluator SimpleEvaluator evaluator = new SimpleEvaluator(_optimizer); IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); IGenomeListEvaluator <NeatGenome> innerEvaluator = new UnityParallelListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _optimizer); IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>(innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); //ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); //ea.Initialize(innerEvaluator, genomeFactory, genomeList);//this can be used if the currentGeneration does not need to be updated at the start of the training ea.Initialize(innerEvaluator, genomeFactory, genomeList, true); return(ea); }
/// <summary> /// Constructs with the details of teh function regression problem to be visualized. /// </summary> /// <param name="func">The function being regressed.</param> /// <param name="xMin">The minimum value of the input range being sampled.</param> /// <param name="xIncr">The increment between input sample values.</param> /// <param name="sampleCount">The number of samples over the input range.</param> /// <param name="genomeDecoder">Genome decoder.</param> public FunctionRegressionView2D(IFunction func, double xMin, double xIncr, int sampleCount, IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder) { InitializeComponent(); InitGraph(string.Empty, string.Empty, string.Empty); _func = func; _xMin = xMin; _xIncr = xIncr; _sampleCount = sampleCount; _genomeDecoder = genomeDecoder; // Prebuild plot point objects. _plotPointListTarget = new PointPairList(); _plotPointListResponse = new PointPairList(); double[] args = new double[]{xMin}; for(int i=0; i<sampleCount; i++, args[0] += xIncr) { _plotPointListTarget.Add(args[0], _func.GetValue(args)); _plotPointListResponse.Add(args[0], 0.0); } // Bind plot points to graph. zed.GraphPane.AddCurve("Target", _plotPointListTarget, Color.Black, SymbolType.None); zed.GraphPane.AddCurve("Network Response", _plotPointListResponse, Color.Red, SymbolType.None); }
public void Initialize(IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder, IMapClusteringDataset dataset, MapClusteringEvaluator evaluator, int nbClusters) { this.dataset = dataset; this.nbClusters = nbClusters; this.decoder = genomeDecoder; this.evaluator = evaluator; samples = dataset.GetSamplesMatrix(); outputs = new double[nbClusters, samples.GetLength(1), samples.GetLength(2)]; this.nbInputs = samples.GetLength(0); maxValue = 0.0; for (var i = 0; i < samples.GetLength(0); i++) { for (var j = 0; j < samples.GetLength(1); j++) { for (var k = 0; k < samples.GetLength(2); k++) { var value = samples[i, j, k]; if (value > maxValue) { maxValue = value; } } } } maxValue *= 2; // margin }
private static void Backprop(NeatGenome genome, IGenomeDecoder<NeatGenome, IBlackBox> decoder, double learningRate) { var phenome = decoder.Decode(genome); var network = (FastCyclicNetwork)phenome; network.Momentum = 0; network.BackpropLearningRate = learningRate; //Console.WriteLine("Weights Before:"); //PrintWeights(network); //Console.WriteLine(); network.Train(new double[] { 0.3, 0.3 }, new double[] { 0.9 }); Console.WriteLine("Weights:"); PrintWeights(network); Console.WriteLine(); network.Train(new double[] { 0.3, 0.3 }, new double[] { 0.9 }); Console.WriteLine("Weights:"); PrintWeights(network); Console.WriteLine(); }
/** * Assigns an AI brain to this player. This is used when * loading a brain from an existing neural network xml champion file. */ public AIFighter getFighterBrain() { //try to load a champion file. If any issues, use default AI. try { // Initialise log4net (log to console). XmlConfigurator.Configure(new FileInfo("log4net.properties")); // Experiment classes encapsulate much of the nuts and bolts of setting up a NEAT search. AIExperiment experiment = new AIExperiment(new AIFighterEvaluatorFactory()); // Load config XML. XmlDocument xmlConfig = new XmlDocument(); xmlConfig.Load("ai.config.xml"); experiment.Initialize("AI", xmlConfig.DocumentElement); // assign genome decoder for reading champion files IGenomeDecoder <NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); //load existing champion file into a genome string championFileLocation = "coevolution_champion.xml"; XmlReader xr = XmlReader.Create(championFileLocation); NeatGenome genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false)[0]; //decode genome into a usable AIFighter brain. return(new AIFighter(decoder.Decode(genome))); } catch (System.Exception e) { Debug.Log("Unable to load CHAMPION xml file. It may not exist.\n" + e); return(null); } }
/// <summary> /// Construct the view with an appropriately configured world and a genome decoder for decoding genomes as they are passed into RefreshView(). /// </summary> public PreyCaptureView(IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder, PreyCaptureWorld world) { try { InitializeComponent(); _genomeDecoder = genomeDecoder; _world = world; // Create a bitmap for the picturebox. int width = Width; int height = Height; _image = new Bitmap(width, height, ViewportPixelFormat); pbx.Image = _image; // Create background thread for running simulation alongside NEAT algorithm. _simThread = new Thread(new ThreadStart(SimulationThread)); _simThread.IsBackground = true; _simThread.Start(); } finally { _initializing = false; } }
/// <summary> /// Create a new genome list evaluator. /// </summary> /// <typeparam name="TGenome">Genome type.</typeparam> /// <typeparam name="TPhenome">Phenome type.</typeparam> /// <param name="genomeDecoder">Genome decoder, for decoding a genome to a phenome.</param> /// <param name="phenomeEvaluationScheme">Phenome evaluation scheme.</param> /// <param name="degreeOfParallelism">The number of CPU threads to distribute work to.</param> /// <returns>A new instance of <see cref="IGenomeListEvaluator{TGenome}"/>.</returns> public static IGenomeListEvaluator <TGenome> CreateEvaluator <TGenome, TPhenome>( IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluationScheme <TPhenome> phenomeEvaluationScheme, int degreeOfParallelism) where TGenome : IGenome where TPhenome : class, IDisposable { // Reject nonsensical values for degreeOfParallelism. if (degreeOfParallelism < 1) { throw new ArgumentException(nameof(degreeOfParallelism)); } // Create a serial (single threaded) evaluator if degreeOfParallelism is one. if (degreeOfParallelism == 1) { return(new SerialGenomeListEvaluator <TGenome, TPhenome>(genomeDecoder, phenomeEvaluationScheme)); } // Create a parallel (multi-threaded) evaluator for degreeOfParallelism > 1. if (phenomeEvaluationScheme.EvaluatorsHaveState) { return(new ParallelGenomeListEvaluator <TGenome, TPhenome>(genomeDecoder, phenomeEvaluationScheme, degreeOfParallelism)); } // else return(new ParallelGenomeListEvaluatorStateless <TGenome, TPhenome>(genomeDecoder, phenomeEvaluationScheme, degreeOfParallelism)); }
/// <summary> /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator. /// Phenome caching is enabled by default. /// </summary> public SerialGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; _enablePhenomeCaching = true; _evaluationMethod = Evaluate_Caching; }
private static void BackpropEpochs(NeatGenome genome, IGenomeDecoder <NeatGenome, IBlackBox> decoder, double learningRate, int epochs) { var phenome = decoder.Decode(genome); var network = (FastCyclicNetwork)phenome; network.Momentum = 0; network.BackpropLearningRate = learningRate; //Console.WriteLine("Weights Before:"); //PrintWeights(network); //Console.WriteLine(); //double[][] inputs = TrainXOR(epochs, network); for (int i = 0; i < epochs; i++) { network.Train(new double[] { 0.3, 0.3 }, new double[] { 0.9 }); } Console.WriteLine("Weights After:"); PrintWeights(network); Console.WriteLine(); //RunXor(network, inputs); }
/// <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="mazeEnvironment">The maze on which to evaluate the navigators.</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 override void InitializeAlgorithm(ParallelOptions parallelOptions, List <NeatGenome> genomeList, IGenomeFactory <NeatGenome> genomeFactory, MazeStructure mazeEnvironment, 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 GenerationalComplexifyingEvolutionAlgorithm <NeatGenome>(SpeciationStrategy, ComplexityRegulationStrategy, RunPhase.Initialization); // Create IBlackBox evaluator. MazeNavigatorFitnessInitializationEvaluator mazeNavigatorEvaluator = new MazeNavigatorFitnessInitializationEvaluator(MinSuccessDistance, MaxDistanceToTarget, mazeEnvironment, startingEvaluations); // Create the genome evaluator IGenomeEvaluator <NeatGenome> fitnessEvaluator = new ParallelGenomeFitnessEvaluator <NeatGenome, IBlackBox>( genomeDecoder, mazeNavigatorEvaluator, parallelOptions); // 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 is quite likely 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, null, null); }
/// <summary> /// Construct with the provided IGenomeDecoder, ICoevolutionPhenomeEvaluator and ParalleOptions. /// The number of parallel threads defaults to Environment.ProcessorCount. /// </summary> public MusicListModulesEvaluator(String name, int parasiteGenomesPerEvaluation, int hallOfFameGenomesPerEvaluation, ModuleNeatEvolutionAlgorithm <TGenome> algorithm, List <ModuleNeatEvolutionAlgorithm <TGenome> > eaParasites, IGenomeDecoder <TGenome, TPhenome> genomeDecoder, ICoevolutionPhenomeListEvaluator <TPhenome> phenomeListEvaluator, ParallelOptions options) { Debug.Assert(parasiteGenomesPerEvaluation >= 0); Debug.Assert(hallOfFameGenomesPerEvaluation >= 0); HostName = name; _parasiteGenomesPerEvaluation = parasiteGenomesPerEvaluation; _hallOfFameGenomesPerEvaluation = hallOfFameGenomesPerEvaluation; _genomeDecoder = genomeDecoder; _phenomeListEvaluator = phenomeListEvaluator; _parallelOptions = options; _eaParasites = eaParasites; _hallOfFame = new List <TGenome>(); _random = new Random(); _parasiteGenomes = new List <TGenome> [MusicEnvironment.MODULE_COUNT - 1]; for (int i = 0; i < _parasiteGenomes.Length; i++) { _parasiteGenomes[i] = new List <TGenome>(); } algorithm.UpdateEvent += new EventHandler(eaParasite_UpdateEvent); }
private static void Backprop(NeatGenome genome, IGenomeDecoder <NeatGenome, IBlackBox> decoder, double learningRate) { var phenome = decoder.Decode(genome); var network = (FastCyclicNetwork)phenome; network.Momentum = 0; network.BackpropLearningRate = learningRate; //Console.WriteLine("Weights Before:"); //PrintWeights(network); //Console.WriteLine(); network.Train(new double[] { 0.3, 0.3 }, new double[] { 0.9 }); Console.WriteLine("Weights:"); PrintWeights(network); Console.WriteLine(); network.Train(new double[] { 0.3, 0.3 }, new double[] { 0.9 }); Console.WriteLine("Weights:"); PrintWeights(network); Console.WriteLine(); }
/// <summary> /// Construct with the provided genome decoder and phenome evaluator. /// </summary> /// <param name="genomeDecoder">Genome decoder.</param> /// <param name="phenomeEvaluationScheme">Phenome evaluation scheme.</param> /// <param name="degreeOfParallelism">The desired degree of parallelism.</param> public ParallelGenomeListEvaluatorStateless( IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluationScheme <TPhenome> phenomeEvaluationScheme, int degreeOfParallelism) { // This class can only accept an evaluation scheme that uses a stateless evaluator. if (phenomeEvaluationScheme.EvaluatorsHaveState) { throw new ArgumentException(nameof(phenomeEvaluationScheme)); } // Reject degreeOfParallelism values less than 2. -1 should have been resolved to an actual number by the time // this constructor is invoked, and 1 is nonsensical for a parallel evaluator. if (degreeOfParallelism < 2) { throw new ArgumentException(nameof(degreeOfParallelism)); } _genomeDecoder = genomeDecoder; _phenomeEvaluationScheme = phenomeEvaluationScheme; _phenomeEvaluator = phenomeEvaluationScheme.CreateEvaluator(); _parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = degreeOfParallelism }; }
public MultiObjectiveListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IMultiObjectiveEvaluator <TPhenome> phenomeEvaluator, INoveltyScorer <TGenome> noveltyScorer, IGeneticDiversityScorer <TGenome> geneticDiversityScorer, IMultiObjectiveScorer multiObjectiveScorer, bool enableMultiThreading, ParallelOptions options) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; _noveltyScorer = noveltyScorer; _geneticDiversityScorer = geneticDiversityScorer; _multiObjectiveScorer = multiObjectiveScorer; _parallelOptions = options; _generation = 0; // Determine the appropriate evaluation method. if (enableMultiThreading) { _evalMethod = EvaluateParallel; } else { _evalMethod = EvaluateSerial; } }
/// <summary> /// Constructs with the details of teh function regression problem to be visualized. /// </summary> /// <param name="func">The function being regressed.</param> /// <param name="xMin">The minimum value of the input range being sampled.</param> /// <param name="xIncr">The increment between input sample values.</param> /// <param name="sampleCount">The number of samples over the input range.</param> /// <param name="genomeDecoder">Genome decoder.</param> public FunctionRegressionView2D(IFunction func, double xMin, double xIncr, int sampleCount, IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder) { InitializeComponent(); InitGraph(string.Empty, string.Empty, string.Empty); _func = func; _xMin = xMin; _xIncr = xIncr; _sampleCount = sampleCount; _genomeDecoder = genomeDecoder; // Prebuild plot point objects. _plotPointListTarget = new PointPairList(); _plotPointListResponse = new PointPairList(); double[] args = new double[] { xMin }; for (int i = 0; i < sampleCount; i++, args[0] += xIncr) { _plotPointListTarget.Add(args[0], _func.GetValue(args)); _plotPointListResponse.Add(args[0], 0.0); } // Bind plot points to graph. zed.GraphPane.AddCurve("Target", _plotPointListTarget, Color.Black, SymbolType.None); zed.GraphPane.AddCurve("Network Response", _plotPointListResponse, Color.Red, SymbolType.None); }
/// <summary> /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator. /// </summary> public CoroutinedListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator, NeatSupervisor neatSupervisor) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; _neatSupervisor = neatSupervisor; }
public EvaluateWorker(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeTickEvaluator <TPhenome, TGenome>[] phenomeEvaluators, TGenome[] genomes, EventWaitHandle waitHandle, Func <double> worldTick) { _genomeDecoder = genomeDecoder; _phenomeEvaluators = phenomeEvaluators; _genomes = genomes; _waitHandle = waitHandle; _worldTick = worldTick; }
/// <summary> /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator. /// </summary> public UnityParallelListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator, Optimizer opt) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; _optimizer = opt; }
/// <summary> /// Construct with the provided IGenomeDecoder, IPhenomeEvaluator and ParalleOptions. /// Phenome caching is enabled by default. /// The number of parallel threads defaults to Environment.ProcessorCount. /// </summary> public CacheFirstParallelGenomeListEvaluator(IGenomeDecoder <TGenome, TPhenome> genomeDecoder, IPhenomeEvaluator <TPhenome> phenomeEvaluator, ParallelOptions options) { _genomeDecoder = genomeDecoder; _phenomeEvaluator = phenomeEvaluator; _parallelOptions = options; }
public OCRClassificationView(IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, IClassificationDataset dataset, IViewableEvaluator evaluator) : this() { this.decoder = genomeDecoder; this.dataset = dataset; this.evaluator = evaluator; dataset.LoadFromFile(@"Datasets\semeion.samples.data"); sampleCount = dataset.InputSamples.Count(); }
//static IGenomeDecoder<NeatGenome, MarkovChain> _genomeDecoder; //static PasswordCrackingEvaluator _passwordCrackingEvaluator; public static void Evaluate(IGenomeDecoder<NeatGenome, MarkovChain> genomeDecoder, PasswordCrackingEvaluator passwordCrackingEvaluator, PasswordEvolutionExperiment experiment) { string[] genomeFiles = Directory.GetFiles(@"..\..\..\experiments\genomes\", "*.xml"); XmlDocument doc = new XmlDocument(); int genomeNumber; foreach (string genomeFile in genomeFiles) { // Read in genome doc.Load(genomeFile); //NeatGenome genome = NeatGenomeXmlIO.LoadGenome(doc, false); //NeatGenomeFactory genomeFactory = (NeatGenomeFactory)CreateGenomeFactory(); NeatGenome genome = experiment.LoadPopulation(XmlReader.Create(genomeFile))[0]; MarkovChain phenome = experiment.CreateGenomeDecoder().Decode(genome);//genomeDecoder.Decode(genome); string[] filePath = genomeFile.Split('\\'); string[] fileName = (filePath[filePath.Length - 1]).Split('-'); String fileNumber = (fileName[1]).Split('.')[0]; genomeNumber = Convert.ToInt32(fileNumber); //FileStream fs = File.Open(@"..\..\..\experiments\genomes\genome-results\genome-"+genomeNumber+"-results.txt", FileMode.CreateNew, FileAccess.Write); TextWriter tw = new StreamWriter(@"..\..\..\experiments\genomes\genome-results\genome-" + genomeNumber + "-results.txt"); // Evaluate if (null == phenome) { // Non-viable genome. tw.WriteLine("0.0 0.0"); } else { FitnessInfo fitnessInfo = passwordCrackingEvaluator.Evaluate(phenome); double val = fitnessInfo._fitness; double val2 = fitnessInfo._alternativeFitness; tw.WriteLine(fitnessInfo._fitness + " " + fitnessInfo._alternativeFitness); } tw.Close(); File.Create(@"..\..\..\experiments\genomes\genome-finished\genome-" + genomeNumber + "-finished.txt"); } // Write results?? -> genome_#_results // Write finished flag -> genome_#_finished }
public MapClusteringView(IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, IMapClusteringDataset dataset, MapClusteringEvaluator evaluator, int nbClusters) : this() { this.dataset = dataset; this.nbClusters = nbClusters; this.decoder = genomeDecoder; this.evaluator = evaluator; samples = dataset.GetSamplesMatrix(); outputs = new double[nbClusters, samples.GetLength(1), samples.GetLength(2)]; inputView.LabelName = "Input"; outputView.LabelName = "Output"; inputView.SetDimensions(samples.GetLength(0), samples.GetLength(1), samples.GetLength(2)); outputView.SetDimensions(nbClusters, samples.GetLength(1), samples.GetLength(2)); maxValue = 0.0; minValue = double.PositiveInfinity; for (var i = 0; i < samples.GetLength(0); i++) { for (var j = 0; j < samples.GetLength(1); j++) { for (var k = 0; k < samples.GetLength(2); k++) { var value = samples[i, j, k]; if (value > maxValue) maxValue = value; if (value < minValue) minValue = value; } } } // Add some margin maxValue *= 2; minValue *= 2; inputView.OnClusterChanged += (id) => { currentInputIdx = id; RefreshInput(); }; outputView.OnClusterChanged += (id) => { currentClusterIdx = id; RefreshOutput(); }; RefreshInput(); }
/// <summary> /// Construct with the provided IGenomeDecoder, this is used to decode genome(s) into IBlackBox controllers. /// </summary> public Box2dDomainView(IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder) { InitializeComponent(); _genomeDecoder = genomeDecoder; // Init openGL viewport / debug drawing object. openGlControl.InitializeContexts(); InitDebugDraw(); // Create background thread for running simulation alongside NEAT algorithm. _simThread = new Thread(new ThreadStart(SimulationThread)); _simThread.IsBackground = true; _simThread.Start(); }
public MazeNavigationView(IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, MazeNavigationWorld<ITrialInfo> world) { InitializeComponent(); _genomeDecoder = genomeDecoder; _world = world; // Create a bitmap for the picturebox. int width = Width; int height = Height; _image = new Bitmap(width, height, ViewportPixelFormat); pbx.Image = _image; // Create background thread for running simulation alongside NEAT algorithm. //_simThread = new Thread(new ThreadStart(SimulationThread)); //_simThread.IsBackground = true; //_simThread.Start(); }
private static void BackpropEpochs(NeatGenome genome, IGenomeDecoder<NeatGenome, IBlackBox> decoder, double learningRate, int epochs) { var phenome = decoder.Decode(genome); var network = (FastCyclicNetwork)phenome; network.Momentum = 0; network.BackpropLearningRate = learningRate; //Console.WriteLine("Weights Before:"); //PrintWeights(network); //Console.WriteLine(); //double[][] inputs = TrainXOR(epochs, network); for(int i = 0; i < epochs; i++) network.Train(new double[] { 0.3, 0.3 }, new double[] { 0.9 }); Console.WriteLine("Weights After:"); PrintWeights(network); Console.WriteLine(); //RunXor(network, inputs); }
/// <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="mazeEnvironment">The maze on which to evaluate the navigators.</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 override void InitializeAlgorithm(ParallelOptions parallelOptions, List<NeatGenome> genomeList, IGenomeFactory<NeatGenome> genomeFactory, MazeStructure mazeEnvironment, 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 GenerationalNeatEvolutionAlgorithm<NeatGenome>(SpeciationStrategy, ComplexityRegulationStrategy, RunPhase.Initialization); // Create IBlackBox evaluator. MazeNavigatorFitnessInitializationEvaluator mazeNavigatorEvaluator = new MazeNavigatorFitnessInitializationEvaluator(MaxTimesteps, MinSuccessDistance, MaxDistanceToTarget, mazeEnvironment, startingEvaluations); // Create the genome evaluator IGenomeEvaluator<NeatGenome> fitnessEvaluator = new ParallelGenomeFitnessEvaluator<NeatGenome, IBlackBox>( genomeDecoder, mazeNavigatorEvaluator, parallelOptions); // 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 is quite likely 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, null, null); }
public MapClusteringScatterPlotView(IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, IMapClusteringDataset dataset, MapClusteringEvaluator evaluator, int nbClusters) : this() { Initialize(genomeDecoder, dataset, evaluator, nbClusters); }
private void SetResolution(int visualFieldResolution) { _visualFieldResolution = visualFieldResolution; _visualPixelSize = BoxesVisualDiscriminationEvaluator.VisualFieldEdgeLength / _visualFieldResolution; _visualOriginPixelXY = -1 + (_visualPixelSize/2.0); _genomeDecoder = _experiment.CreateGenomeDecoder(visualFieldResolution, _experiment.LengthCppnInput); _box = null; // If we have a cached genome then re-decode it using the new decoder (with the updated resolution). if(null != _neatGenome) { _box = _genomeDecoder.Decode(_neatGenome); } }
public NeatInteractiveEvolutionAlgorithm<NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory<NeatGenome> genomeFactory, List<NeatGenome> genomeList) { _genomeDecoder = CreateGenomeDecoder(); var ea = new NeatInteractiveEvolutionAlgorithm< NeatGenome>(_eaParams); ea.Initialize(genomeList); 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); }
/// <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="mazeEnvironment">The maze on which to evaluate the navigators.</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 abstract void InitializeAlgorithm(ParallelOptions parallelOptions, List<NeatGenome> genomeList, IGenomeFactory<NeatGenome> genomeFactory, MazeStructure mazeEnvironment, IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, ulong startingEvaluations);
/// <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="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 virtual void InitializeAlgorithm(ParallelOptions parallelOptions, List<NeatGenome> genomeList, IGenomeDecoder<NeatGenome, IBlackBox> genomeDecoder, ulong startingEvaluations) { ParallelOptions = parallelOptions; InitialPopulation = genomeList; StartingEvaluations = startingEvaluations; GenomeDecoder = genomeDecoder; // 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); SpeciationStrategy = new ParallelKMeansClusteringStrategy<NeatGenome>(distanceMetric, parallelOptions); // Create complexity regulation strategy. ComplexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(ComplexityRegulationStrategyDefinition, ComplexityThreshold); }
/// <summary> /// Construct with the provided IGenomeDecoder, this is used to decode genome(s) into IBlackBox controllers. /// </summary> public SinglePoleBalancingSwingUpView(IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder) : base(genomeDecoder) {}
/// <summary> /// Construct with the provided IGenomeDecoder, this is used to decode genome(s) into IBlackBox controllers. /// </summary> public WalkerBox2dView(IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder) : base(genomeDecoder) {}
const float __TwelveDegrees = (float)(Math.PI / 15.0); //= 0.2094384; #endregion #region Constructor /// <summary> /// Construct with the provided IGenomeDecoder, this is used to decode genome(s) into IBlackBox controllers. /// </summary> public InvertedDoublePendulumView(IGenomeDecoder<NeatGenome,IBlackBox> genomeDecoder) : base(genomeDecoder) {}