Ejemplo n.º 1
0
        /**
         * Compute the collective offspring the entire species (the sum of all
         * individual's offspring) is assigned skim is fractional offspring left
         * over from a previous subspecies that was counted. These fractional parts
         * are kept until they add up to 1
         */


        public double CountOffspring(double skim)
        {
            ExpectedOffspring = 0;
            const double y1 = 1.0;
            double       r2 = skim;
            int          n2 = 0;

            foreach (var t in Individuals.Cast <NEATIndividual>())
            {
                double x1 = t.ExpectedOffspring;
                int    n1 = (int)(x1 / y1);
                double r1 = x1 - ((int)(x1 / y1) * y1);
                n2 = n2 + n1;
                r2 = r2 + r1;

                if (r2 >= 1.0)
                {
                    n2 = n2 + 1;
                    r2 = r2 - 1.0;
                }
            }

            ExpectedOffspring = n2;
            return(r2);
        }
Ejemplo n.º 2
0
        /**
         * Remove the individuals from current subspecies who have been mark as
         * eliminate the remain individuals will be allow to reproduce
         */
        public void RemovePoorFitnessIndividuals()
        {
            // create a new list, contain the non eliminate individuals
            IList <Individual> remainIndividuals = new List <Individual>();

            foreach (var ind in Individuals.Cast <NEATIndividual>())
            {
                if (!ind.Eliminate)
                {
                    remainIndividuals.Add(ind);
                }
            }
            Individuals = remainIndividuals;
        }
Ejemplo n.º 3
0
        /**
         * Adjust the fitness of the individuals within this subspecies. We will use
         * the adjusted fitness to determine the expected offsprings within each
         * subspecies.
         */
        public void AdjustFitness(IEvolutionState state, int dropoffAge, double ageSignificance)
        {
            int ageDebt = (Age - AgeOfLastImprovement + 1) - dropoffAge;

            if (ageDebt == 0)
            {
                ageDebt = 1;
            }

            foreach (NEATIndividual ind in Individuals.Cast <NEATIndividual>())
            {
                // start to adjust the fitness with age information
                ind.AdjustedFitness = ind.Fitness.Value;

                // Make fitness decrease after a stagnation point dropoffAge
                // Added an if to keep species pristine until the dropoff point
                if (ageDebt >= 1)
                {
                    ind.AdjustedFitness = ind.AdjustedFitness * 0.01;
                }

                // Give a fitness boost up to some young age (niching)
                // The age-significance parameter is a system parameter
                // If it is 1, then young species get no fitness boost
                if (Age <= 10)
                {
                    ind.AdjustedFitness = ind.AdjustedFitness * ageSignificance;
                }

                // Do not allow negative fitness
                if (ind.AdjustedFitness < 0.0)
                {
                    ind.AdjustedFitness = 0.0001;
                }

                // Share fitness with the species
                // This is the explicit fitness sharing, where the the original
                // fitness
                // are dividing by the number of individuals in the species.
                // By using this, a species cannot afford to become too big even if
                // many of its
                // individual perform well
                ind.AdjustedFitness = ind.AdjustedFitness / Individuals.Count;
            }
        }