public void Render() { NEATGenome genome = (NEATGenome)this.pop.BestGenome; Substrate substrate = SubstrateFactory.factorSandwichSubstrate(resolution, resolution); HyperNEATCODEC codec = new HyperNEATCODEC(); NEATNetwork phenotype = (NEATNetwork)codec.Decode(this.pop, substrate, genome); TrialEvaluation trial = new TrialEvaluation(phenotype, this.testCase); IntPair actualPos = trial.Query(resolution); // clear what was there before GridCanvas.Children.Clear(); // double boxWidth = GridCanvas.ActualWidth / resolution; double boxHeight = GridCanvas.ActualHeight / resolution; double delta = 2.0 / resolution; int index = 0; for (int row = 0; row < resolution; row++) { double y = -1 + (row * delta); double boxY = row * boxHeight; for (int col = 0; col < resolution; col++) { double x = -1 + (col * delta); double boxX = col * boxWidth; Rectangle r = new Rectangle(); r.SetValue(Canvas.LeftProperty, boxX); r.SetValue(Canvas.TopProperty, boxY); r.Width = boxWidth; r.Height = boxHeight; if (this.testCase.GetPixel(x, y) > 0) { r.Fill = Brushes.Blue; } else { double d = trial.Output[index]; int c = trial.Normalize(d, 255); SolidColorBrush b = new SolidColorBrush(Color.FromRgb(255, (byte)c, 255)); r.Fill = b; r.Stroke = Brushes.Black; } GridCanvas.Children.Add(r); index++; } } Rectangle target = new Rectangle(); target.SetValue(Canvas.LeftProperty, actualPos.X * boxWidth); target.SetValue(Canvas.TopProperty, actualPos.Y * boxHeight); target.Width = boxWidth; target.Height = boxHeight; target.Fill = Brushes.Red; GridCanvas.Children.Add(target); }
/// <summary> /// Create an initial random population. /// </summary> public void Reset() { // create the genome factory if (IsHyperNEAT) { CODEC = new HyperNEATCODEC(); GenomeFactory = new FactorHyperNEATGenome(); } else { CODEC = new NEATCODEC(); GenomeFactory = new FactorNEATGenome(); } // create the new genomes Species.Clear(); // reset counters GeneIdGenerate.CurrentID = 1; InnovationIDGenerate.CurrentID = 1; EncogRandom rnd = RandomNumberFactory.Factor(); // create one default species BasicSpecies defaultSpecies = new BasicSpecies(); defaultSpecies.Population = this; // create the initial population for (int i = 0; i < PopulationSize; i++) { NEATGenome genome = GenomeFactory.Factor(rnd, this , InputCount, OutputCount, InitialConnectionDensity); defaultSpecies.Add(genome); } defaultSpecies.Leader = defaultSpecies.Members[0]; Species.Add(defaultSpecies); // create initial innovations Innovations = new NEATInnovationList(this); }