Пример #1
0
        /// <summary>
        /// Create the next generation of programs.
        /// </summary>
        public void ComputeNextGeneration(int Generation)
        {
            if (m_PopulatonFactory == null)
            {
                m_PopulatonFactory = new GPPopulationFactory(this, this.Training.Columns);
            }
            //
            // Create the next generation of programs
            GPPopulation popNew = m_PopulatonFactory.ComputeNext(Generation, m_Population, m_Fitness, m_SeedPrograms);

            //
            // If the Population size changed, update the configuration
            if (popNew.Count != m_Population.Count)
            {
                this.Profile.PopulationSize = popNew.Count;
                Console.WriteLine("GPServer: Memory is low, Population size reduced to ({0})", popNew.Count);

                //
                // Reset the Fitness object
                m_Fitness.TerminateProcessingThreads();
                m_Fitness = null;
            }

            m_Population = popNew;

            //
            // Clear out any seed programs we just used
            ResetSeedPrograms();
        }
Пример #2
0
        /// <summary>
        /// Compute the fitness of the entire Population and return the value of
        /// the best program in the Population.
        /// </summary>
        public void EvaluateFitness(int Generation)
        {
            //
            // First time through the fitness object doesn't exist, so have to create it
            if (m_Fitness == null)
            {
                m_Fitness = new GPFitness(
                    this,
                    this.Training,
                    GPEnums.RESULTS_TOLERANCE,
                    m_FunctionSet.UseInputHistory);
            }

            m_BestProgram = m_Fitness.Compute(Generation, m_Population);

            //
            // Always simplify a program before it is transmitted.
            m_BestProgram.ConvertToTree(this.FunctionSet, false);
            m_BestProgram.Edit();
            m_BestProgram.ConvertToArray(this.FunctionSet);

            //
            // Obtain the Population stats
            m_Population.ComputeComplexity(
                out m_PopulationComplexityMin,
                out m_PopulationComplexityMax,
                out m_PopulationComplexityAve);
        }
Пример #3
0
        /// <summary>
        /// Creates the next generation of programs.  This method also keeps tabs on memory
        /// as it creates the new Population.  If we run out of physical memory then the
        /// new Population size is changed to wherever we ran out of memory.
        /// </summary>
        /// <param name="nGeneration">Which generation is currently being processed</param>
        /// <param name="Population">Reference to the Population just computed for fitness</param>
        /// <param name="Fitness">Fitness object with the fitness computation results</param>
        /// <param name="AutoReproduce">List of programs to automatically reproduce into the next generation</param>
        /// <returns>Reference to the new Population to use</returns>
        public GPPopulation ComputeNext(int nGeneration, GPPopulation Population, GPFitness Fitness, List <GPProgram> AutoReproduce)
        {
            m_PopCurrent = Population;
            m_Fitness    = Fitness;

            //
            // Setup the program selection delegate
            switch (m_ModelerConfig.Profile.Reproduction)
            {
            case GPEnums.Reproduction.Tournament:
                ExecProgramSelection = new DELProgramSelection(Fitness.FitnessSelection.SelectProgramTournament);
                break;

            case GPEnums.Reproduction.OverSelection:
                ExecProgramSelection = new DELProgramSelection(Fitness.FitnessSelection.SelectProgramOverSelection);
                break;
            }

            //
            // Create a Tree Factory object - It helps in support of the mutation and
            // crossover operations
            m_TreeFactory = new GPProgramTreeFactory(m_ModelerConfig, m_InputDimension);

            return(ComputeNext(Population, Fitness, AutoReproduce));
        }
Пример #4
0
 /// <summary>
 /// This method instructs the server object to clean up as much memory
 /// as possible.
 /// </summary>
 public void ForceCleanup()
 {
     m_Population = null;
     m_Fitness.TerminateProcessingThreads();
     m_Fitness  = null;
     m_Training = null;
     System.GC.Collect();
 }
Пример #5
0
        public GPPopulation ComputeNext(GPPopulation PopCurrent, GPFitness Fitness, List <GPProgram> AutoReproduce)
        {
            GPPopulation PopNew = new GPPopulation(m_ModelerConfig);

            //
            // Add the new programs into the next generation automatically
            foreach (GPProgram Seed in AutoReproduce)
            {
                PopNew.Programs.Add(Seed);
            }
            //
            // Automatically reproduce the best program into the next generation
            PopNew.Programs.Add((GPProgram)Fitness.BestProgramRef.Clone());

            //
            // Now, go ahead and fill out the rest of the Population
            while (PopNew.Count < m_ModelerConfig.Profile.PopulationSize)
            {
                //
                // Make a probabilistic selection between...
                //	Reproduction
                //	Mutation
                //	Crossover
                double Choice     = GPUtilities.rngNextDouble();
                double Cumulative = m_ModelerConfig.Profile.ProbabilityReproductionD;
                bool   bSelected  = false;

                if (Choice <= Cumulative)
                {
                    Reproduce(PopNew, Fitness.FitnessSelection);
                    bSelected = true;
                }
                Cumulative += m_ModelerConfig.Profile.ProbabilityMutationD;
                if (!bSelected && (Choice <= Cumulative))
                {
                    Mutate(PopNew, Fitness.FitnessSelection);
                    bSelected = true;
                }
                Cumulative += m_ModelerConfig.Profile.ProbabilityCrossoverD;
                if (!bSelected && (Choice <= Cumulative))
                {
                    Crossover(PopNew, Fitness.FitnessSelection);
                    bSelected = true;
                }

                //
                // Only check every 100 times to save a little time on doing this
                // check.
                if (PopNew.Count % 100 == 0)
                {
                    if (!CheckMemory())
                    {
                        //
                        // Do a garbage collect just to be sure and check again
                        System.GC.Collect();
                        if (!CheckMemory())
                        {
                            break;
                        }
                    }
                }
            }

            return(PopNew);
        }