Exemple #1
0
        public OffspringSelectionGeneticAlgorithm CreateGeSymbolicRegressionSample()
        {
            var ga = new OffspringSelectionGeneticAlgorithm();

            #region Problem Configuration
            var problem = new HeuristicLab.Problems.GrammaticalEvolution.GESymbolicRegressionSingleObjectiveProblem();

            #endregion
            #region Algorithm Configuration
            ga.Name        = "Grammatical Evolution - Symbolic Regression (Poly-10)";
            ga.Description = "Grammatical evolution algorithm for solving a symbolic regression problem problem";
            ga.Problem     = problem;
            problem.Load(new PolyTen().GenerateRegressionData());

            // must occur after loading problem data because the grammar creates symbols for random constants once the data is loaded
            var consts = problem.SymbolicExpressionTreeGrammar.AllowedSymbols.OfType <Constant>().ToList();
            foreach (var c in consts)
            {
                problem.SymbolicExpressionTreeGrammar.RemoveSymbol(c);
            }

            SamplesUtils.ConfigureOsGeneticAlgorithmParameters <GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
                ga, 1000, 1, 50, 0.05, 200);
            #endregion

            return(ga);
        }
        public static OffspringSelectionGeneticAlgorithm CreateGpTimeSeriesSample()
        {
            var problem = new SymbolicTimeSeriesPrognosisSingleObjectiveProblem();

            problem.Name             = "Symbolic time series prognosis problem (Mackey Glass t=17)";
            problem.ProblemData.Name = "Mackey Glass t=17";
            problem.MaximumSymbolicExpressionTreeLength.Value             = 125;
            problem.MaximumSymbolicExpressionTreeDepth.Value              = 12;
            problem.EvaluatorParameter.Value.HorizonParameter.Value.Value = 10;

            foreach (var symbol in problem.SymbolicExpressionTreeGrammar.Symbols)
            {
                if (symbol is Exponential || symbol is Logarithm)
                {
                    symbol.Enabled = false;
                }
                else if (symbol is AutoregressiveTargetVariable)
                {
                    symbol.Enabled = true;
                    var autoRegressiveSymbol = symbol as AutoregressiveTargetVariable;
                    autoRegressiveSymbol.MinLag = -30;
                    autoRegressiveSymbol.MaxLag = -1;
                }
            }

            var osga = new OffspringSelectionGeneticAlgorithm();

            osga.Name        = "Genetic Programming - Time Series Prediction (Mackey-Glass-17)";
            osga.Description = "A genetic programming algorithm for creating a time-series model for the Mackey-Glass-17 time series.";
            osga.Problem     = problem;
            SamplesUtils.ConfigureOsGeneticAlgorithmParameters <GenderSpecificSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>
                (osga, popSize: 100, elites: 1, maxGens: 25, mutationRate: 0.15);
            osga.MaximumSelectionPressure.Value = 100;
            return(osga);
        }
        public static void ConfigureOsGeneticAlgorithmParameters <S, C, M>(OffspringSelectionGeneticAlgorithm ga, int popSize, int elites, int maxGens, double mutationRate = 0.05, double maxSelPres = 100, int tournGroupSize = 0)
            where S : ISelector
            where C : ICrossover
            where M : IManipulator
        {
            ga.Elites.Value                   = elites;
            ga.MaximumGenerations.Value       = maxGens;
            ga.MutationProbability.Value      = mutationRate;
            ga.PopulationSize.Value           = popSize;
            ga.MaximumSelectionPressure.Value = maxSelPres;
            ga.Seed.Value                       = 0;
            ga.SetSeedRandomly.Value            = true;
            ga.ComparisonFactorLowerBound.Value = 1;
            ga.ComparisonFactorUpperBound.Value = 1;

            ga.Selector = ga.SelectorParameter.ValidValues
                          .OfType <S>()
                          .First();

            ga.Crossover = ga.CrossoverParameter.ValidValues
                           .OfType <C>()
                           .First();

            ga.Mutator = ga.MutatorParameter.ValidValues
                         .OfType <M>()
                         .First();

            var tSelector = ga.Selector as TournamentSelector;

            if (tSelector != null)
            {
                tSelector.GroupSizeParameter.Value.Value = tournGroupSize;
            }
            ga.Engine = new ParallelEngine.ParallelEngine();
        }
Exemple #4
0
        public OffspringSelectionGeneticAlgorithm CreateGeArtificialAntSample()
        {
            OffspringSelectionGeneticAlgorithm ga = new OffspringSelectionGeneticAlgorithm();

            #region Problem Configuration
            var problem = new HeuristicLab.Problems.GrammaticalEvolution.GEArtificialAntProblem();
            #endregion
            #region Algorithm Configuration
            ga.Name        = "Grammatical Evolution - Artificial Ant (SantaFe)";
            ga.Description = "Grammatical evolution algorithm for solving a artificial ant problem";
            ga.Problem     = problem;
            SamplesUtils.ConfigureOsGeneticAlgorithmParameters <GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
                ga, 200, 1, 50, 0.05, 200);
            #endregion

            return(ga);
        }
        public static OffspringSelectionGeneticAlgorithm CreateGpMultiplexerSample()
        {
            var problem = new HeuristicLab.Problems.GeneticProgramming.Boolean.MultiplexerProblem();

            problem.Name = "11-Multiplexer Problem";
            problem.Encoding.TreeLength = 50;
            problem.Encoding.TreeDepth  = 50;

            var osga = new OffspringSelectionGeneticAlgorithm();

            osga.Name        = "Genetic Programming - Multiplexer 11 Problem";
            osga.Description = "A genetic programming algorithm that solves the 11-bit multiplexer problem.";
            osga.Problem     = problem;
            SamplesUtils.ConfigureOsGeneticAlgorithmParameters <GenderSpecificSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>
                (osga, popSize: 100, elites: 1, maxGens: 50, mutationRate: 0.25);
            osga.MaximumSelectionPressure.Value = 200;
            return(osga);
        }
Exemple #6
0
        private OffspringSelectionGeneticAlgorithm CreateGpSymbolicRegressionSample()
        {
            var osga = new OffspringSelectionGeneticAlgorithm();

            #region Problem Configuration
            var provider    = new VariousInstanceProvider(seed);
            var instance    = provider.GetDataDescriptors().First(x => x.Name.StartsWith("Spatial co-evolution"));
            var problemData = (RegressionProblemData)provider.LoadData(instance);
            var problem     = new SymbolicRegressionSingleObjectiveProblem();
            problem.ProblemData = problemData;
            problem.Load(problemData);
            problem.BestKnownQuality.Value = 1.0;

            #region configure grammar

            var grammar = (TypeCoherentExpressionGrammar)problem.SymbolicExpressionTreeGrammar;
            grammar.ConfigureAsDefaultRegressionGrammar();

            //symbols square, power, squareroot, root, log, exp, sine, cosine, tangent, variable
            var square       = grammar.Symbols.OfType <Square>().Single();
            var power        = grammar.Symbols.OfType <Power>().Single();
            var squareroot   = grammar.Symbols.OfType <SquareRoot>().Single();
            var root         = grammar.Symbols.OfType <Root>().Single();
            var log          = grammar.Symbols.OfType <Logarithm>().Single();
            var exp          = grammar.Symbols.OfType <Exponential>().Single();
            var sine         = grammar.Symbols.OfType <Sine>().Single();
            var cosine       = grammar.Symbols.OfType <Cosine>().Single();
            var tangent      = grammar.Symbols.OfType <Tangent>().Single();
            var variable     = grammar.Symbols.OfType <Variable>().Single();
            var powerSymbols = grammar.Symbols.Single(s => s.Name == "Power Functions");
            powerSymbols.Enabled = true;

            square.Enabled          = true;
            square.InitialFrequency = 1.0;
            foreach (var allowed in grammar.GetAllowedChildSymbols(square))
            {
                grammar.RemoveAllowedChildSymbol(square, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(square, 0))
            {
                grammar.RemoveAllowedChildSymbol(square, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(square, variable);

            power.Enabled = false;

            squareroot.Enabled = false;
            foreach (var allowed in grammar.GetAllowedChildSymbols(squareroot))
            {
                grammar.RemoveAllowedChildSymbol(squareroot, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(squareroot, 0))
            {
                grammar.RemoveAllowedChildSymbol(squareroot, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(squareroot, variable);

            root.Enabled = false;

            log.Enabled          = true;
            log.InitialFrequency = 1.0;
            foreach (var allowed in grammar.GetAllowedChildSymbols(log))
            {
                grammar.RemoveAllowedChildSymbol(log, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(log, 0))
            {
                grammar.RemoveAllowedChildSymbol(log, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(log, variable);

            exp.Enabled          = true;
            exp.InitialFrequency = 1.0;
            foreach (var allowed in grammar.GetAllowedChildSymbols(exp))
            {
                grammar.RemoveAllowedChildSymbol(exp, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(exp, 0))
            {
                grammar.RemoveAllowedChildSymbol(exp, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(exp, variable);

            sine.Enabled = false;
            foreach (var allowed in grammar.GetAllowedChildSymbols(sine))
            {
                grammar.RemoveAllowedChildSymbol(sine, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(sine, 0))
            {
                grammar.RemoveAllowedChildSymbol(sine, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(sine, variable);

            cosine.Enabled = false;
            foreach (var allowed in grammar.GetAllowedChildSymbols(cosine))
            {
                grammar.RemoveAllowedChildSymbol(cosine, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(cosine, 0))
            {
                grammar.RemoveAllowedChildSymbol(cosine, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(cosine, variable);

            tangent.Enabled = false;
            foreach (var allowed in grammar.GetAllowedChildSymbols(tangent))
            {
                grammar.RemoveAllowedChildSymbol(tangent, allowed);
            }
            foreach (var allowed in grammar.GetAllowedChildSymbols(tangent, 0))
            {
                grammar.RemoveAllowedChildSymbol(tangent, allowed, 0);
            }
            grammar.AddAllowedChildSymbol(tangent, variable);
            #endregion

            problem.SymbolicExpressionTreeGrammar = grammar;

            // configure remaining problem parameters
            problem.MaximumSymbolicExpressionTreeLength.Value = 50;
            problem.MaximumSymbolicExpressionTreeDepth.Value  = 12;
            problem.MaximumFunctionDefinitions.Value          = 0;
            problem.MaximumFunctionArguments.Value            = 0;

            var evaluator = new SymbolicRegressionConstantOptimizationEvaluator();
            evaluator.ConstantOptimizationIterations.Value = 5;
            problem.EvaluatorParameter.Value = evaluator;
            problem.RelativeNumberOfEvaluatedSamplesParameter.Hidden = true;
            problem.SolutionCreatorParameter.Hidden = true;
            #endregion

            #region Algorithm Configuration
            osga.Problem     = problem;
            osga.Name        = "Offspring Selection Genetic Programming - Symbolic Regression";
            osga.Description = "Genetic programming with strict offspring selection for solving a benchmark regression problem.";
            SamplesUtils.ConfigureOsGeneticAlgorithmParameters <GenderSpecificSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(osga, 100, 1, 25, 0.2, 50);
            var mutator = (MultiSymbolicExpressionTreeManipulator)osga.Mutator;
            mutator.Operators.OfType <FullTreeShaker>().Single().ShakingFactor = 0.1;
            mutator.Operators.OfType <OnePointShaker>().Single().ShakingFactor = 1.0;

            osga.Analyzer.Operators.SetItemCheckedState(
                osga.Analyzer.Operators
                .OfType <SymbolicRegressionSingleObjectiveOverfittingAnalyzer>()
                .Single(), false);
            osga.Analyzer.Operators.SetItemCheckedState(
                osga.Analyzer.Operators
                .OfType <SymbolicDataAnalysisAlleleFrequencyAnalyzer>()
                .First(), false);

            osga.ComparisonFactorModifierParameter.Hidden         = true;
            osga.ComparisonFactorLowerBoundParameter.Hidden       = true;
            osga.ComparisonFactorUpperBoundParameter.Hidden       = true;
            osga.OffspringSelectionBeforeMutationParameter.Hidden = true;
            osga.SuccessRatioParameter.Hidden    = true;
            osga.SelectedParentsParameter.Hidden = true;
            osga.ElitesParameter.Hidden          = true;

            #endregion
            return(osga);
        }