コード例 #1
0
        private IRegressionProblemData LoadDefaultTowerProblem()
        {
            RegressionRealWorldInstanceProvider provider = new RegressionRealWorldInstanceProvider();
            var tower = new HeuristicLab.Problems.Instances.DataAnalysis.Tower();

            return(provider.LoadData(tower));
        }
コード例 #2
0
        public void GetRealWorldInstanceTest()
        {
            var           target             = new RegressionRealWorldInstanceProvider();
            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());
        }
コード例 #3
0
 public void GetRealWorldInstanceTest() {
   var target = new RegressionRealWorldInstanceProvider();
   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 GeneticAlgorithm CreateGpSymbolicRegressionSample()
        {
            GeneticAlgorithm ga = new GeneticAlgorithm();

            #region Problem Configuration
            SymbolicRegressionSingleObjectiveProblem symbRegProblem = new SymbolicRegressionSingleObjectiveProblem();
            symbRegProblem.Name        = "Tower Symbolic Regression Problem";
            symbRegProblem.Description = "Tower Dataset (downloaded from: http://www.symbolicregression.com/?q=towerProblem)";
            RegressionRealWorldInstanceProvider provider = new RegressionRealWorldInstanceProvider();
            var instance         = provider.GetDataDescriptors().Where(x => x.Name.Equals("Tower")).Single();
            var towerProblemData = (RegressionProblemData)provider.LoadData(instance);
            towerProblemData.TargetVariableParameter.Value = towerProblemData.TargetVariableParameter.ValidValues
                                                             .First(v => v.Value == "towerResponse");
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "x1"), true);
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "x7"), false);
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "x11"), false);
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "x16"), false);
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "x21"), false);
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "x25"), false);
            towerProblemData.InputVariables.SetItemCheckedState(
                towerProblemData.InputVariables.Single(x => x.Value == "towerResponse"), false);
            towerProblemData.TrainingPartition.Start = 0;
            towerProblemData.TrainingPartition.End   = 3136;
            towerProblemData.TestPartition.Start     = 3136;
            towerProblemData.TestPartition.End       = 4999;
            towerProblemData.Name        = "Data imported from towerData.txt";
            towerProblemData.Description = "Chemical concentration at top of distillation tower, dataset downloaded from: http://vanillamodeling.com/realproblems.html, best R² achieved with nu-SVR = 0.97";
            symbRegProblem.ProblemData   = towerProblemData;

            // configure grammar
            var grammar = new TypeCoherentExpressionGrammar();
            grammar.ConfigureAsDefaultRegressionGrammar();
            grammar.Symbols.OfType <VariableCondition>().Single().InitialFrequency = 0.0;
            var varSymbol = grammar.Symbols.OfType <Variable>().Where(x => !(x is LaggedVariable)).Single();
            varSymbol.WeightMu               = 1.0;
            varSymbol.WeightSigma            = 1.0;
            varSymbol.WeightManipulatorMu    = 0.0;
            varSymbol.WeightManipulatorSigma = 0.05;
            varSymbol.MultiplicativeWeightManipulatorSigma = 0.03;
            var constSymbol = grammar.Symbols.OfType <Constant>().Single();
            constSymbol.MaxValue         = 20;
            constSymbol.MinValue         = -20;
            constSymbol.ManipulatorMu    = 0.0;
            constSymbol.ManipulatorSigma = 1;
            constSymbol.MultiplicativeManipulatorSigma   = 0.03;
            symbRegProblem.SymbolicExpressionTreeGrammar = grammar;

            // configure remaining problem parameters
            symbRegProblem.BestKnownQuality.Value                    = 0.97;
            symbRegProblem.FitnessCalculationPartition.Start         = 0;
            symbRegProblem.FitnessCalculationPartition.End           = 2300;
            symbRegProblem.ValidationPartition.Start                 = 2300;
            symbRegProblem.ValidationPartition.End                   = 3136;
            symbRegProblem.RelativeNumberOfEvaluatedSamples.Value    = 1;
            symbRegProblem.MaximumSymbolicExpressionTreeLength.Value = 150;
            symbRegProblem.MaximumSymbolicExpressionTreeDepth.Value  = 12;
            symbRegProblem.MaximumFunctionDefinitions.Value          = 0;
            symbRegProblem.MaximumFunctionArguments.Value            = 0;

            symbRegProblem.EvaluatorParameter.Value = new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator();
            #endregion
            #region Algorithm Configuration
            ga.Problem     = symbRegProblem;
            ga.Name        = "Genetic Programming - Symbolic Regression";
            ga.Description = "A standard genetic programming algorithm to solve a symbolic regression problem (tower dataset)";
            SamplesUtils.ConfigureGeneticAlgorithmParameters <TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(
                ga, 1000, 1, 50, 0.15, 5);
            var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator;
            mutator.Operators.OfType <FullTreeShaker>().Single().ShakingFactor = 0.1;
            mutator.Operators.OfType <OnePointShaker>().Single().ShakingFactor = 1.0;

            ga.Analyzer.Operators.SetItemCheckedState(
                ga.Analyzer.Operators
                .OfType <SymbolicRegressionSingleObjectiveOverfittingAnalyzer>()
                .Single(), false);
            ga.Analyzer.Operators.SetItemCheckedState(
                ga.Analyzer.Operators
                .OfType <SymbolicDataAnalysisAlleleFrequencyAnalyzer>()
                .First(), false);
            #endregion
            return(ga);
        }