Esempio n. 1
0
        private void Mutate(IGenome genome, double soften = 1)
        {
            if (new Random().NextDouble() < GenerationParameters.MutateAddNodeProbability / Math.Max(soften, 1))
            {
                genome.MutateAddNode();
            }
            else if (new Random().NextDouble() < GenerationParameters.MutateAddGeneProbability / Math.Max(soften, 1))
            {
                genome.MutateAddGene(Population.Genomes.SelectMany(g => g.Genes));
            }
            else
            {
                if (new Random().NextDouble() < GenerationParameters.MutateAllGeneWeightsProbability)
                {
                    genome.MutateGeneWeights(GeneMutationType.AdjustWeight, GeneParameters.MutateGeneWeightFactor, 1);
                }

                if (new Random().NextDouble() < GenerationParameters.MutateGeneExpressionProbability)
                {
                    genome.MutateGeneExpression();
                }

                if (new Random().NextDouble() < GenerationParameters.MutateGeneReExpressionProbability)
                {
                    genome.MutateGeneReExpress();
                }

                IGene geneCandidate = genome.Genes[new Random().Next(genome.Genes.Count)];

                if (new Random().NextDouble() < GenerationParameters.MutateGeneWeightProbability)
                {
                    geneCandidate.MutateWeight(GeneMutationType.AdjustWeight, GeneParameters.MutateGeneWeightFactor);
                }
            }
        }
Esempio n. 2
0
        public void Spawn(int size, IGenome initialGenome = null)
        {
            IGenome genome = initialGenome ?? new Genome(numberOfInputs, numberOfOutputs);

            if (initialGenome == null)
            {
                genome.MutateGeneWeights(GeneMutationType.ReplaceWeight, 1, 1);
            }

            Genomes = Enumerable.Range(0, size).Select(i => genome.Copy()).ToList();
        }