Ejemplo 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);
                }
            }
        }