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);
        }
Example #2
0
        public double CalculateScore(IMLMethod phenotype)
        {
            BoxTrialCase test = new BoxTrialCase(new Random());
            TrialEvaluation eval = new TrialEvaluation(phenotype, test);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    IntPair targetPos = eval.Test.InitTestCase(i);
                    IntPair actualPos = eval.Query(this.resolution);

                    eval.Accumulate(
                            CalcRealDistanceSquared(targetPos, actualPos),
                            Math.Max(0.0, eval.MaxActivation - eval.MinActivation));
                }
            }

            return eval.CalculateFitness();
        }
Example #3
0
        public double CalculateScore(IMLMethod phenotype)
        {
            BoxTrialCase    test = new BoxTrialCase(new Random());
            TrialEvaluation eval = new TrialEvaluation(phenotype, test);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    IntPair targetPos = eval.Test.InitTestCase(i);
                    IntPair actualPos = eval.Query(this.resolution);

                    eval.Accumulate(
                        CalcRealDistanceSquared(targetPos, actualPos),
                        Math.Max(0.0, eval.MaxActivation - eval.MinActivation));
                }
            }

            return(eval.CalculateFitness());
        }
        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);
        }