예제 #1
0
        public void GetVariousInstanceTest()
        {
            var           target             = new VariousInstanceProvider();
            StringBuilder erroneousInstances = new StringBuilder();
            int           count = 0;

            foreach (var id in target.GetDataDescriptors())
            {
                try {
                    target.LoadData(id);
                } catch (Exception ex) {
                    erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
                }
                count++;
            }
            Assert.IsTrue(count > 0, "No problem instances were found.");
            Assert.IsTrue(erroneousInstances.Length == 0, "Some instances could not be parsed: " + Environment.NewLine + erroneousInstances.ToString());
        }
        private GaussianProcessRegression CreateGaussianProcessRegressionSample()
        {
            var gpr        = new GaussianProcessRegression();
            var provider   = new VariousInstanceProvider();
            var instance   = provider.GetDataDescriptors().Where(x => x.Name.Contains("Spatial co-evolution")).Single();
            var regProblem = new RegressionProblem();

            regProblem.Load(provider.LoadData(instance));

            #region Algorithm Configuration
            gpr.Name        = "Gaussian Process Regression";
            gpr.Description = "A Gaussian process regression algorithm which solves the spatial co-evolution benchmark problem";
            gpr.Problem     = regProblem;

            gpr.CovarianceFunction     = new CovarianceSquaredExponentialIso();
            gpr.MeanFunction           = new MeanConst();
            gpr.MinimizationIterations = 20;
            gpr.Seed            = 0;
            gpr.SetSeedRandomly = true;
            #endregion

            gpr.Engine = new ParallelEngine.ParallelEngine();
            return(gpr);
        }
 public void GetVariousInstanceTest() {
   var target = new VariousInstanceProvider();
   StringBuilder erroneousInstances = new StringBuilder();
   int count = 0;
   foreach (var id in target.GetDataDescriptors()) {
     try {
       target.LoadData(id);
     } catch (Exception ex) {
       erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
     }
     count++;
   }
   Assert.IsTrue(count > 0, "No problem instances were found.");
   Assert.IsTrue(erroneousInstances.Length == 0, "Some instances could not be parsed: " + Environment.NewLine + erroneousInstances.ToString());
 }
예제 #4
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);
        }