Example #1
0
        private IGenome GetRandomGenomeBiasFitness(IEnumerable <IGenome> genomes)
        {
            double fitnessThreshold = RandomHelpers.GetRandomBiasingLow(1, 5);

            fitnessThreshold = genomes.Max(g => g.Fitness) / fitnessThreshold;

            return(genomes.OrderBy(g => g.Fitness).Where(g => g.Fitness >= fitnessThreshold).First());
        }
Example #2
0
        private double GetSoftenFactor(double fitness, IEnumerable <IGenome> genomes)
        {
            double fitnessThreshold = RandomHelpers.GetRandomBiasingLow(1, 5);

            fitnessThreshold = genomes.Max(g => g.Fitness) / fitnessThreshold;

            return(fitness > fitnessThreshold ? new Random().Next(2, 4) : 1);
        }
Example #3
0
        private ISpecies GetRandomSpeciesBiasFitness(IEnumerable <ISpecies> species)
        {
            if (!species.Any())
            {
                return(Population.BestSpecies);
            }

            double fitnessThreshold = RandomHelpers.GetRandomBiasingLow(1, 5);

            fitnessThreshold = species.Max(s => s.Fitness) / fitnessThreshold;

            return(species.OrderBy(s => s.Fitness).Where(s => s.Fitness >= fitnessThreshold).First());
        }
Example #4
0
        public INode MutateAddNode()
        {
            int innovation = (int)RandomHelpers.GetRandomBiasingLow(
                Genes.Min(g => g.Innovation), Genes.Max(g => g.Innovation)
                );

            IGene oldGene = Genes.FirstOrDefault(g => g.Innovation <= innovation);

            if (oldGene == null)
            {
                oldGene = Genes[new Random().Next(Genes.Count)];
            }

            INode newNode = new Node(NodeType.Hidden);

            // Disable the old connection
            oldGene.IsExpressed = false;

            // Add new connections
            IGene newGeneIn = new Gene(
                oldGene.NodeOut,
                newNode,
                GetNextInnovation(),
                1
                );

            IGene newGeneOut = new Gene(
                newNode,
                oldGene.NodeIn,
                GetNextInnovation(),
                oldGene.Weight
                );

            Nodes.Add(newNode);

            Genes.Add(newGeneIn);
            Genes.Add(newGeneOut);

            return(newNode);
        }