Beispiel #1
0
        public void Init()
        {
            var innovations = new InnovationCollection();

            var neuronGenes = Enumerable.Range(0, 3).Select(i => {
                var inId = innovations.GetInitialNeuronInnovationId(i);
                return(new NeuronGene(inId, NeuronType.HiddenNeuron));
            }).ToGeneList();

            var synapseGenes = Enumerable.Range(0, 3).Select(i => {
                var inId = innovations.GetSynapseInnovationId(i, i + 1);
                return(new SynapseGene(inId, i, i + 1, true));
            }).ToGeneList();

            var protoGenotype = new Genotype(neuronGenes, synapseGenes);

            var phenotypes = Enumerable.Range(0, 100).Select(_ => {
                var gt = Genotype.FromPrototype(protoGenotype);
                var pt = new Phenotype(gt);
                return(pt);
            }).ToArray();

            var distanceMetric = new NEAT.DistanceMetric(0.0f, 0.0f, 35.0f);
            var speciation     = new NEAT.Speciation(10, 50.0f, 0.2f, distanceMetric);

            species = speciation.Speciate(new NEAT.Specie[0], phenotypes);
        }
        public void Init()
        {
            var innovations = new InnovationCollection();

              var neuronGenes = Enumerable.Range(0, 3).Select(i => {
            var inId = innovations.GetInitialNeuronInnovationId(i);
            return new NeuronGene(inId, NeuronType.HiddenNeuron);
              }).ToGeneList();

              var synapseGenes = Enumerable.Range(0, 3).Select(i => {
            var inId = innovations.GetSynapseInnovationId(i, i + 1);
            return new SynapseGene(inId, i, i + 1, true);
              }).ToGeneList();

              var protoGenotype = new Genotype(neuronGenes, synapseGenes);

              var phenotypes = Enumerable.Range(0, 100).Select(_ => {
            var gt = Genotype.FromPrototype(protoGenotype);
            var pt = new Phenotype(gt);
            return pt;
              }).ToArray();

              var distanceMetric = new NEAT.DistanceMetric(0.0f, 0.0f, 35.0f);
              var speciation = new NEAT.Speciation(10, 50.0f, 0.2f, distanceMetric);
              species = speciation.Speciate(new NEAT.Specie[0], phenotypes);
        }
Beispiel #3
0
        public Genotype Crossover(Phenotype a, Phenotype b)
        {
            if (a == b)
            {
                return(new Genotype(a.Genotype));
            }

            var aGenotype       = new Genotype(a.Genotype);
            var bGenotype       = new Genotype(b.Genotype);
            var newNeuronGenes  = CrossoverGenes <NeuronGene>(aGenotype.NeuronGenes, bGenotype.NeuronGenes, a.AdjustedFitness, b.AdjustedFitness);
            var newSynapseGenes = CrossoverGenes <SynapseGene>(aGenotype.SynapseGenes, bGenotype.SynapseGenes, a.AdjustedFitness, b.AdjustedFitness);

            return(new Genotype(newNeuronGenes, newSynapseGenes));
        }
        public void TestSpecie()
        {
            var specie = new Specie(13, protoGenotype, 0, 0, 0.0f);

              for (int i = 0; i < 100; i++) {
            var gt = Genotype.FromPrototype(protoGenotype);
            var pt = new Phenotype(gt);
            specie.Add(pt);
              }

              foreach (var pt in specie) {
            pt.AdjustedFitness = 1.0f / (float)specie.Count;
              }

              Assert.AreEqual(0.0f, specie.MeanFitness, 0.001f);
              Assert.AreEqual(0.01f, specie.MeanAdjustedFitness, 0.001f);
              Assert.AreEqual(100, specie.Count);
        }
Beispiel #5
0
        public void TestSpecie()
        {
            var specie = new Specie(13, protoGenotype, 0, 0, 0.0f);

            for (int i = 0; i < 100; i++)
            {
                var gt = Genotype.FromPrototype(protoGenotype);
                var pt = new Phenotype(gt);
                specie.Add(pt);
            }

            foreach (var pt in specie)
            {
                pt.AdjustedFitness = 1.0f / (float)specie.Count;
            }

            Assert.AreEqual(0.0f, specie.MeanFitness, 0.001f);
            Assert.AreEqual(0.01f, specie.MeanAdjustedFitness, 0.001f);
            Assert.AreEqual(100, specie.Count);
        }
        public void Init()
        {
            var innovations = new InnovationCollection();

              var neuronGenes = Enumerable.Range(0, 3).Select(i => {
            var inId = innovations.GetInitialNeuronInnovationId(i);
            return new NeuronGene(inId, NeuronType.HiddenNeuron);
              }).ToGeneList();

              var synapseGenes = Enumerable.Range(0, 3).Select(i => {
            var inId = innovations.GetSynapseInnovationId(i, i + 1);
            return new SynapseGene(inId, i, i + 1, true);
              }).ToGeneList();

              var protoGenotype = new Genotype(neuronGenes, synapseGenes);

              phenotypes = Enumerable.Range(0, 100).Select(_ => {
            var gt = Genotype.FromPrototype(protoGenotype);
            var pt = new Phenotype(gt);
            return pt;
              }).ToArray();
        }
Beispiel #7
0
        public void Init()
        {
            var innovations = new InnovationCollection();

            var neuronGenes = Enumerable.Range(0, 3).Select(i => {
                var inId = innovations.GetInitialNeuronInnovationId(i);
                return(new NeuronGene(inId, NeuronType.HiddenNeuron));
            }).ToGeneList();

            var synapseGenes = Enumerable.Range(0, 3).Select(i => {
                var inId = innovations.GetSynapseInnovationId(i, i + 1);
                return(new SynapseGene(inId, i, i + 1, true));
            }).ToGeneList();

            var protoGenotype = new Genotype(neuronGenes, synapseGenes);

            phenotypes = Enumerable.Range(0, 100).Select(_ => {
                var gt = Genotype.FromPrototype(protoGenotype);
                var pt = new Phenotype(gt);
                return(pt);
            }).ToArray();
        }
        public void TestMultipointCrossover()
        {
            var innovationIdsA = new int[]{1, 2, 3, 4, 5, 8};
              var neuronGenesA = innovationIdsA.Select(i => new NeuronGene(i, NeuronType.HiddenNeuron)).ToGeneList();

              var innovationIdsB = new int[]{1, 2, 3, 4, 5, 6, 7, 9, 10};
              var neuronGenesB = innovationIdsB.Select(i => new NeuronGene(i, NeuronType.HiddenNeuron)).ToGeneList();

              var expectedInnovationIds = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

              var genotypeA = new Genotype(neuronGenesA, new GeneList<SynapseGene>(0));
              var genotypeB = new Genotype(neuronGenesB, new GeneList<SynapseGene>(0));

              var phenotypeA = new Phenotype(genotypeA);
              var phenotypeB = new Phenotype(genotypeB);

              var crossover = new MultipointCrossover();
              var offspring = crossover.Crossover(phenotypeA, phenotypeB);

              var offspringInnovationIds = offspring.NeuronGenes.Select(g =>
            g.InnovationId).ToArray();

              Assert.AreEqual(expectedInnovationIds, offspringInnovationIds);
        }
Beispiel #9
0
        public void TestMultipointCrossover()
        {
            var innovationIdsA = new int[] { 1, 2, 3, 4, 5, 8 };
            var neuronGenesA   = innovationIdsA.Select(i => new NeuronGene(i, NeuronType.HiddenNeuron)).ToGeneList();

            var innovationIdsB = new int[] { 1, 2, 3, 4, 5, 6, 7, 9, 10 };
            var neuronGenesB   = innovationIdsB.Select(i => new NeuronGene(i, NeuronType.HiddenNeuron)).ToGeneList();

            var expectedInnovationIds = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var genotypeA = new Genotype(neuronGenesA, new GeneList <SynapseGene>(0));
            var genotypeB = new Genotype(neuronGenesB, new GeneList <SynapseGene>(0));

            var phenotypeA = new Phenotype(genotypeA);
            var phenotypeB = new Phenotype(genotypeB);

            var crossover = new MultipointCrossover();
            var offspring = crossover.Crossover(phenotypeA, phenotypeB);

            var offspringInnovationIds = offspring.NeuronGenes.Select(g =>
                                                                      g.InnovationId).ToArray();

            Assert.AreEqual(expectedInnovationIds, offspringInnovationIds);
        }