[15712] | 1 | using System;
|
---|
[15784] | 2 | using System.Collections;
|
---|
| 3 | using System.Collections.Generic;
|
---|
[15712] | 4 | using System.Linq;
|
---|
| 5 | using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration;
|
---|
[15726] | 6 | using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration;
|
---|
[15784] | 7 | using HeuristicLab.Common;
|
---|
[15712] | 8 | using HeuristicLab.Core;
|
---|
| 9 | using HeuristicLab.Problems.DataAnalysis;
|
---|
[15776] | 10 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
[15712] | 11 | using HeuristicLab.Random;
|
---|
| 12 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 13 |
|
---|
| 14 | namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
|
---|
[15724] | 15 | [TestClass]
|
---|
[15712] | 16 | public class MctsSymbolicRegressionTest {
|
---|
| 17 | private const int Seed = 1234;
|
---|
| 18 | private IRandom rand;
|
---|
| 19 |
|
---|
[15723] | 20 | private const double SuccessThreshold = 0.9999999;
|
---|
[15712] | 21 |
|
---|
[15723] | 22 | private GrammarEnumerationAlgorithm alg;
|
---|
| 23 | private RegressionProblem problem;
|
---|
| 24 |
|
---|
[15712] | 25 | [TestInitialize]
|
---|
| 26 | public void InitTest() {
|
---|
| 27 | rand = new FastRandom(Seed);
|
---|
[15723] | 28 |
|
---|
| 29 | alg = new GrammarEnumerationAlgorithm();
|
---|
| 30 | problem = new RegressionProblem();
|
---|
| 31 | alg.Problem = problem;
|
---|
| 32 | alg.GuiUpdateInterval = int.MaxValue;
|
---|
[15849] | 33 | foreach (IGrammarEnumerationAnalyzer grammarEnumerationAnalyzer in alg.Analyzers) {
|
---|
| 34 | alg.Analyzers.SetItemCheckedState(grammarEnumerationAnalyzer, grammarEnumerationAnalyzer is RSquaredEvaluator);
|
---|
| 35 | }
|
---|
[15712] | 36 | }
|
---|
| 37 |
|
---|
[15746] | 38 | [TestCleanup]
|
---|
[15724] | 39 | public void Cleanup() {
|
---|
| 40 | if (alg.BestTrainingSentence != null) {
|
---|
[15821] | 41 | Console.WriteLine("Training: " + alg.Grammar.ToInfixString(alg.BestTrainingSentence));
|
---|
[15724] | 42 | }
|
---|
| 43 | }
|
---|
[15723] | 44 |
|
---|
[15724] | 45 |
|
---|
[15726] | 46 | private void EvaluateGrammarEnumeration() {
|
---|
[15723] | 47 | // Evaluate results
|
---|
| 48 | var eps = 1.0 - SuccessThreshold;
|
---|
| 49 |
|
---|
| 50 | // Check if algorithm terminated correctly
|
---|
[15746] | 51 | Assert.IsTrue(alg.Results.ContainsKey("Best solution (Training)"), "No training solution returned!");
|
---|
[15723] | 52 |
|
---|
| 53 | // Check resultss
|
---|
[15746] | 54 | Assert.AreEqual(1.0, ((IRegressionSolution)alg.Results["Best solution (Training)"].Value).TestRSquared, eps, "Test quality too low!");
|
---|
[15723] | 55 | }
|
---|
| 56 |
|
---|
| 57 |
|
---|
[15712] | 58 | [TestMethod]
|
---|
[15723] | 59 | [TestProperty("Goal", "structure search")]
|
---|
[15784] | 60 | public void NoConstants_Nguyen1() {
|
---|
[15712] | 61 | // x³ + x² + x
|
---|
[15861] | 62 | alg.OptimizeConstants = false;
|
---|
[15860] | 63 | alg.MaxComplexity = 6;
|
---|
[15784] | 64 | alg.Problem.ProblemData = new NguyenFunctionOne(Seed).GenerateRegressionData();
|
---|
[15726] | 65 |
|
---|
| 66 | alg.Start();
|
---|
| 67 |
|
---|
[15849] | 68 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
[15834] | 69 | TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First();
|
---|
[15726] | 70 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 71 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 72 |
|
---|
| 73 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
[15849] | 74 | constSymbol, varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, mulSymbol,
|
---|
| 75 | constSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, addSymbol,
|
---|
| 76 | constSymbol, varSymbol, mulSymbol, addSymbol,
|
---|
| 77 | constSymbol, addSymbol
|
---|
[15726] | 78 | });
|
---|
| 79 |
|
---|
[15832] | 80 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 81 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
[15726] | 82 |
|
---|
[15860] | 83 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15726] | 84 |
|
---|
[15746] | 85 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
[15726] | 86 |
|
---|
[15746] | 87 | // Evaluate
|
---|
| 88 | EvaluateGrammarEnumeration();
|
---|
[15712] | 89 | }
|
---|
[15723] | 90 |
|
---|
[15773] | 91 | // Too "large" target model for now...
|
---|
| 92 | //[TestMethod]
|
---|
[15723] | 93 | [TestProperty("Goal", "structure search")]
|
---|
[15784] | 94 | public void NoConstants_Nguyen2() {
|
---|
[15712] | 95 | // x^4 + x³ + x² + x
|
---|
[15860] | 96 | alg.MaxComplexity = 11;
|
---|
[15776] | 97 | alg.Problem.ProblemData = new NguyenFunctionTwo(Seed).GenerateRegressionData();
|
---|
[15726] | 98 |
|
---|
| 99 | alg.Start();
|
---|
[15773] | 100 | EvaluateGrammarEnumeration();
|
---|
| 101 | }
|
---|
[15726] | 102 |
|
---|
[15773] | 103 | // Too "large" target model for now...
|
---|
| 104 | //[TestMethod]
|
---|
| 105 | [TestProperty("Goal", "structure search")]
|
---|
[15784] | 106 | public void NoConstants_Nguyen3() {
|
---|
[15773] | 107 | // x^5 + x^4 + x^3 + x^2 + x
|
---|
[15860] | 108 | alg.MaxComplexity = 32;
|
---|
[15776] | 109 | alg.Problem.ProblemData = new NguyenFunctionThree(Seed).GenerateRegressionData();
|
---|
[15746] | 110 |
|
---|
[15773] | 111 | alg.Start();
|
---|
[15746] | 112 |
|
---|
[15773] | 113 | EvaluateGrammarEnumeration();
|
---|
| 114 | }
|
---|
[15746] | 115 |
|
---|
[15784] | 116 | [TestMethod]
|
---|
[15773] | 117 | [TestProperty("Goal", "structure search")]
|
---|
[15784] | 118 | public void NoConstants_Nguyen6() {
|
---|
[15773] | 119 | // sin(x) + sin(x + x²)
|
---|
[15861] | 120 | alg.OptimizeConstants = false;
|
---|
[15860] | 121 | alg.MaxComplexity = 4;
|
---|
[15776] | 122 | alg.Problem.ProblemData = new NguyenFunctionSix(Seed).GenerateRegressionData();
|
---|
[15746] | 123 |
|
---|
[15773] | 124 | alg.Start();
|
---|
[15784] | 125 |
|
---|
[15849] | 126 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
[15834] | 127 | TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First();
|
---|
[15784] | 128 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 129 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 130 | TerminalSymbol sinSymbol = alg.Grammar.Sin;
|
---|
| 131 |
|
---|
[15849] | 132 | // c * sin(c x + c) + c * sin(c * x * x + c * x) + c
|
---|
[15784] | 133 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
[15849] | 134 | varSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol,
|
---|
| 135 | varSymbol, varSymbol, mulSymbol, constSymbol, mulSymbol, varSymbol, constSymbol, mulSymbol, addSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 136 | constSymbol, addSymbol
|
---|
[15784] | 137 | });
|
---|
| 138 |
|
---|
[15832] | 139 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 140 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
[15784] | 141 |
|
---|
[15860] | 142 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15784] | 143 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 144 |
|
---|
[15773] | 145 | EvaluateGrammarEnumeration();
|
---|
| 146 | }
|
---|
[15746] | 147 |
|
---|
[15773] | 148 | [TestMethod]
|
---|
| 149 | [TestProperty("Goal", "structure search")]
|
---|
[15784] | 150 | public void NoConstants_Nguyen9() {
|
---|
[15861] | 151 | // sin(x) + sin(y²)
|
---|
| 152 | alg.OptimizeConstants = false;
|
---|
[15860] | 153 | alg.MaxComplexity = 3;
|
---|
[15776] | 154 | alg.Problem.ProblemData = new NguyenFunctionNine(Seed).GenerateRegressionData();
|
---|
[15746] | 155 |
|
---|
[15773] | 156 | alg.Start();
|
---|
[15791] | 157 |
|
---|
[15834] | 158 | TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First(v => v.StringRepresentation == "X");
|
---|
| 159 | TerminalSymbol ySymbol = alg.Grammar.VarTerminals.First(v => v.StringRepresentation == "Y");
|
---|
[15849] | 160 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
[15791] | 161 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 162 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 163 | TerminalSymbol sinSymbol = alg.Grammar.Sin;
|
---|
| 164 |
|
---|
[15849] | 165 | // c*sin(c*x + c) + c*sin(c*y*y + c) + c
|
---|
[15791] | 166 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
[15849] | 167 | xSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol,
|
---|
| 168 | ySymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 169 | constSymbol, addSymbol
|
---|
[15791] | 170 | });
|
---|
| 171 |
|
---|
[15832] | 172 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 173 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
[15791] | 174 |
|
---|
[15860] | 175 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15791] | 176 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 177 |
|
---|
[15726] | 178 | EvaluateGrammarEnumeration();
|
---|
[15712] | 179 | }
|
---|
[15723] | 180 |
|
---|
[15773] | 181 | // Too much variables for now...
|
---|
| 182 | //[TestMethod]
|
---|
[15734] | 183 | [TestProperty("Goal", "structure search")]
|
---|
| 184 | public void MctsSymbReg_NoConstants_Poly10() {
|
---|
[15860] | 185 | alg.MaxComplexity = 10;
|
---|
[15776] | 186 | alg.Problem.ProblemData = new PolyTen(Seed).GenerateRegressionData();
|
---|
[15734] | 187 |
|
---|
| 188 | alg.Start();
|
---|
[15773] | 189 | EvaluateGrammarEnumeration();
|
---|
| 190 | }
|
---|
[15734] | 191 |
|
---|
[15784] | 192 | [TestMethod]
|
---|
| 193 | [TestProperty("Goal", "structure search")]
|
---|
| 194 | public void NoConstants_Inverse() {
|
---|
[15861] | 195 | // x / (log(x)*x + x)
|
---|
| 196 | alg.OptimizeConstants = false;
|
---|
[15860] | 197 | alg.MaxComplexity = 4;
|
---|
[15734] | 198 |
|
---|
[15784] | 199 | var x = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() + 1.1).ToList();
|
---|
[15791] | 200 | var y = x.Select(xi => xi / (Math.Log(xi) * xi + xi)).ToList();
|
---|
[15784] | 201 | alg.Problem.ProblemData = new RegressionProblemData(new Dataset(new List<string>() { "x", "y" }, new List<IList>() { x, y }), "x".ToEnumerable(), "y");
|
---|
| 202 |
|
---|
| 203 | alg.Start();
|
---|
| 204 | EvaluateGrammarEnumeration();
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[15859] | 207 | [TestMethod]
|
---|
| 208 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 209 | public void Constants_Nguyen7() {
|
---|
| 210 | // log(x+1) + log(x*x + 1)
|
---|
[15860] | 211 | alg.MaxComplexity = 3;
|
---|
[15859] | 212 | alg.Problem.ProblemData = new NguyenFunctionSeven().GenerateRegressionData();
|
---|
[15784] | 213 |
|
---|
[15859] | 214 | alg.Start();
|
---|
| 215 |
|
---|
| 216 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
| 217 | TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First();
|
---|
| 218 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 219 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 220 | TerminalSymbol logSymbol = alg.Grammar.Log;
|
---|
| 221 |
|
---|
| 222 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
| 223 | varSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, logSymbol, constSymbol, mulSymbol,
|
---|
| 224 | varSymbol, varSymbol, mulSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, logSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 225 | constSymbol, addSymbol
|
---|
| 226 | });
|
---|
| 227 |
|
---|
| 228 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 229 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
| 230 |
|
---|
[15860] | 231 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15859] | 232 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 233 |
|
---|
| 234 | // Evaluate
|
---|
| 235 | EvaluateGrammarEnumeration();
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | [TestMethod]
|
---|
| 239 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 240 | public void Constants_Nguyen12() {
|
---|
| 241 | // x*x*x*x - x*x*x + y*y/2 -y
|
---|
[15860] | 242 | alg.MaxComplexity = 10;
|
---|
[15859] | 243 | alg.Problem.ProblemData = new NguyenFunctionTwelve().GenerateRegressionData();
|
---|
| 244 |
|
---|
| 245 | alg.Start();
|
---|
| 246 |
|
---|
| 247 | // Evaluate
|
---|
| 248 | EvaluateGrammarEnumeration();
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | [TestMethod]
|
---|
| 252 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 253 | public void Constants_Keijzer3() {
|
---|
| 254 | // 0.3*x*sin(2*pi*x)
|
---|
[15860] | 255 | alg.MaxComplexity = 2;
|
---|
[15859] | 256 | alg.Problem.ProblemData = new KeijzerFunctionThree().GenerateRegressionData();
|
---|
| 257 |
|
---|
| 258 | alg.Start();
|
---|
| 259 |
|
---|
| 260 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
| 261 | TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First();
|
---|
| 262 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 263 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 264 |
|
---|
| 265 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
| 266 | constSymbol, varSymbol, mulSymbol, constSymbol, addSymbol, alg.Grammar.Sin,
|
---|
| 267 | varSymbol, mulSymbol,
|
---|
| 268 | constSymbol, mulSymbol,
|
---|
| 269 | constSymbol, addSymbol
|
---|
| 270 | });
|
---|
| 271 |
|
---|
| 272 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 273 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
| 274 |
|
---|
[15860] | 275 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15859] | 276 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 277 |
|
---|
| 278 | // Evaluate
|
---|
| 279 | EvaluateGrammarEnumeration();
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | [TestMethod]
|
---|
| 283 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 284 | public void Constants_Keijzer5() {
|
---|
| 285 | // (30*x*z) / ((x - 10)*y*y)
|
---|
[15860] | 286 | alg.MaxComplexity = 5;
|
---|
[15859] | 287 | alg.Problem.ProblemData = new KeijzerFunctionFive().GenerateRegressionData();
|
---|
| 288 |
|
---|
| 289 | alg.Start();
|
---|
| 290 |
|
---|
| 291 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
| 292 | TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First(s => s.StringRepresentation == "X");
|
---|
| 293 | TerminalSymbol ySymbol = alg.Grammar.VarTerminals.First(s => s.StringRepresentation == "Y");
|
---|
| 294 | TerminalSymbol zSymbol = alg.Grammar.VarTerminals.First(s => s.StringRepresentation == "Z");
|
---|
| 295 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 296 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 297 | TerminalSymbol invSymbol = alg.Grammar.Inv;
|
---|
| 298 |
|
---|
| 299 | // 30 * x * z * 1/(x*y*y - 10*y*y)
|
---|
| 300 | // --> x z * c * x y * y * c * y y * c * + c + inv c +
|
---|
| 301 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
| 302 | xSymbol, zSymbol, mulSymbol, constSymbol, mulSymbol,
|
---|
| 303 | xSymbol, ySymbol, mulSymbol, ySymbol, mulSymbol, constSymbol, mulSymbol,
|
---|
| 304 | ySymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, addSymbol, constSymbol, addSymbol, invSymbol,
|
---|
| 305 | constSymbol, addSymbol
|
---|
| 306 | });
|
---|
| 307 |
|
---|
| 308 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 309 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
| 310 |
|
---|
[15860] | 311 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15859] | 312 |
|
---|
| 313 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 314 |
|
---|
| 315 | // Evaluate
|
---|
| 316 | EvaluateGrammarEnumeration();
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 | [TestMethod]
|
---|
| 321 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 322 | public void Constants_Keijzer12() {
|
---|
| 323 | // x*x*x*x - x*x*x + y*y/2 - y
|
---|
[15860] | 324 | alg.MaxComplexity = 10;
|
---|
[15859] | 325 | alg.Problem.ProblemData = new KeijzerFunctionTwelve().GenerateRegressionData();
|
---|
| 326 |
|
---|
| 327 | alg.Start();
|
---|
| 328 |
|
---|
| 329 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
| 330 | TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First();
|
---|
| 331 | TerminalSymbol ySymbol = alg.Grammar.VarTerminals.Last();
|
---|
| 332 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 333 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 334 |
|
---|
| 335 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
| 336 | xSymbol, xSymbol, mulSymbol, xSymbol, mulSymbol, xSymbol, mulSymbol, constSymbol, mulSymbol,
|
---|
| 337 | xSymbol, xSymbol, mulSymbol, xSymbol, mulSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 338 | ySymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 339 | ySymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 340 | constSymbol, addSymbol
|
---|
| 341 | });
|
---|
| 342 |
|
---|
| 343 | var x = alg.Grammar.ToInfixString(targetSolution);
|
---|
| 344 |
|
---|
| 345 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 346 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
| 347 |
|
---|
[15860] | 348 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15859] | 349 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 350 |
|
---|
| 351 | // Evaluate
|
---|
| 352 | EvaluateGrammarEnumeration();
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | [TestMethod]
|
---|
| 356 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 357 | public void Constants_Keijzer14() {
|
---|
| 358 | // 8 / (2 + x*x + y*y
|
---|
[15860] | 359 | alg.MaxComplexity = 4;
|
---|
[15859] | 360 | alg.Problem.ProblemData = new KeijzerFunctionFourteen().GenerateRegressionData();
|
---|
| 361 |
|
---|
| 362 | alg.Start();
|
---|
| 363 |
|
---|
| 364 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
| 365 | TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First();
|
---|
| 366 | TerminalSymbol ySymbol = alg.Grammar.VarTerminals.Last();
|
---|
| 367 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 368 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 369 | TerminalSymbol divSymbol = alg.Grammar.Inv;
|
---|
| 370 |
|
---|
| 371 |
|
---|
| 372 | // x x mul c mul y y mul c mul add const add inv const mul const add
|
---|
| 373 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
| 374 | xSymbol, xSymbol, mulSymbol, constSymbol, mulSymbol,
|
---|
| 375 | ySymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 376 | constSymbol, addSymbol, divSymbol,
|
---|
| 377 | constSymbol, mulSymbol,
|
---|
| 378 | constSymbol, addSymbol
|
---|
| 379 | });
|
---|
| 380 |
|
---|
| 381 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 382 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
| 383 |
|
---|
[15860] | 384 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15859] | 385 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 386 |
|
---|
| 387 | // Evaluate
|
---|
| 388 | EvaluateGrammarEnumeration();
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 | [TestMethod]
|
---|
| 393 | [TestProperty("Goal", "structure search + const op")]
|
---|
| 394 | public void Constants_Keijzer15() {
|
---|
| 395 | // x*x*x / 5 + y*y*y / 2 - y - x
|
---|
[15860] | 396 | alg.MaxComplexity = 8;
|
---|
[15859] | 397 | alg.Problem.ProblemData = new KeijzerFunctionFifteen().GenerateRegressionData();
|
---|
| 398 |
|
---|
| 399 | alg.Start();
|
---|
| 400 |
|
---|
| 401 | TerminalSymbol constSymbol = alg.Grammar.Const;
|
---|
| 402 | TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First();
|
---|
| 403 | TerminalSymbol ySymbol = alg.Grammar.VarTerminals.Last();
|
---|
| 404 | TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
|
---|
| 405 | TerminalSymbol addSymbol = alg.Grammar.Addition;
|
---|
| 406 |
|
---|
| 407 | // x x * x * const * y y * y * const * + y const * + x const * const +
|
---|
| 408 | SymbolString targetSolution = new SymbolString(new[] {
|
---|
| 409 | xSymbol, xSymbol, mulSymbol, xSymbol, mulSymbol, constSymbol, mulSymbol,
|
---|
| 410 | ySymbol, ySymbol, mulSymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 411 | ySymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 412 | xSymbol, constSymbol, mulSymbol, addSymbol,
|
---|
| 413 | constSymbol, addSymbol
|
---|
| 414 | });
|
---|
| 415 |
|
---|
| 416 | int targetSolutionHash = alg.Grammar.Hasher.CalcHashCode(targetSolution);
|
---|
| 417 | int actualSolutionHash = alg.Grammar.Hasher.CalcHashCode(alg.BestTrainingSentence);
|
---|
| 418 |
|
---|
[15860] | 419 | Assert.IsTrue(alg.DistinctSentencesComplexity.ContainsKey(targetSolutionHash), "Actual solution was not generated!");
|
---|
[15859] | 420 | Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
|
---|
| 421 |
|
---|
| 422 | // Evaluate
|
---|
| 423 | EvaluateGrammarEnumeration();
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 |
|
---|
| 427 |
|
---|
| 428 |
|
---|
[15773] | 429 | #if false
|
---|
[15734] | 430 |
|
---|
| 431 | [TestMethod]
|
---|
| 432 | [TestProperty("Goal", "structure search")]
|
---|
| 433 | public void MctsSymbReg_NoConstants_15() {
|
---|
| 434 | alg.MaxTreeSize = 5;
|
---|
| 435 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 436 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("15")));
|
---|
| 437 | alg.Problem.ProblemData = regProblem;
|
---|
| 438 |
|
---|
| 439 | alg.Start();
|
---|
[15773] | 440 | EvaluateGrammarEnumeration();
|
---|
[15734] | 441 | }
|
---|
| 442 |
|
---|
[15723] | 443 |
|
---|
[15712] | 444 | [TestMethod]
|
---|
| 445 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 446 | [TestProperty("Time", "short")]
|
---|
| 447 | public void MctsSymbReg_NoConstants_Nguyen7() {
|
---|
| 448 | // log(x + 1) + log(x² + 1)
|
---|
| 449 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
|
---|
| 450 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
|
---|
| 451 | TestGrammarEnumeration(regProblem);
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | [TestMethod]
|
---|
| 455 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 456 | [TestProperty("Time", "short")]
|
---|
| 457 | public void MctsSymbReg_NoConstants_Poly10_Part1() {
|
---|
| 458 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 459 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 460 |
|
---|
| 461 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 462 | // Y' = X1*X2 + X3*X4 + X5*X6
|
---|
| 463 | // simplify problem by changing target
|
---|
| 464 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 465 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 466 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 467 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 468 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 469 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 470 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 471 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 472 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 473 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 474 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 475 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 476 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 477 | ys[i] -= x1[i] * x7[i] * x9[i];
|
---|
| 478 | ys[i] -= x3[i] * x6[i] * x10[i];
|
---|
| 479 | }
|
---|
| 480 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 481 |
|
---|
| 482 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 483 |
|
---|
| 484 | TestGrammarEnumeration(modifiedProblemData);
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | [TestMethod]
|
---|
| 488 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 489 | [TestProperty("Time", "short")]
|
---|
| 490 | public void MctsSymbReg_NoConstants_Poly10_Part2() {
|
---|
| 491 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 492 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 493 |
|
---|
| 494 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 495 | // Y' = X1*X7*X9 + X3*X6*X10
|
---|
| 496 | // simplify problem by changing target
|
---|
| 497 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 498 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 499 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
[15784] | 500 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
[15712] | 501 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 502 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 503 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 504 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 505 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 506 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 507 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 508 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 509 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 510 | ys[i] -= x1[i] * x2[i];
|
---|
| 511 | ys[i] -= x3[i] * x4[i];
|
---|
| 512 | ys[i] -= x5[i] * x6[i];
|
---|
| 513 | }
|
---|
| 514 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 515 |
|
---|
| 516 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 517 |
|
---|
| 518 | TestGrammarEnumeration(modifiedProblemData);
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | [TestMethod]
|
---|
| 522 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 523 | [TestProperty("Time", "short")]
|
---|
| 524 | public void MctsSymbReg_NoConstants_Poly10_Part3() {
|
---|
| 525 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 526 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 527 |
|
---|
| 528 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 529 | // Y' = X1*X2 + X1*X7*X9
|
---|
| 530 | // simplify problem by changing target
|
---|
| 531 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 532 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 533 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 534 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 535 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 536 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 537 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 538 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 539 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 540 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 541 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 542 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 543 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 544 | ys[i] -= x3[i] * x4[i];
|
---|
| 545 | ys[i] -= x5[i] * x6[i];
|
---|
| 546 | ys[i] -= x3[i] * x6[i] * x10[i];
|
---|
| 547 | }
|
---|
| 548 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 549 |
|
---|
| 550 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 551 |
|
---|
| 552 | TestGrammarEnumeration(modifiedProblemData);
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | [TestMethod]
|
---|
| 556 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 557 | [TestProperty("Time", "short")]
|
---|
| 558 | public void MctsSymbReg_NoConstants_Poly10_Part4() {
|
---|
| 559 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 560 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 561 |
|
---|
| 562 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 563 | // Y' = X3*X4 + X5*X6 + X3*X6*X10
|
---|
| 564 | // simplify problem by changing target
|
---|
| 565 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 566 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 567 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 568 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 569 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 570 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 571 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 572 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 573 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 574 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 575 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 576 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 577 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 578 | ys[i] -= x1[i] * x2[i];
|
---|
| 579 | ys[i] -= x1[i] * x7[i] * x9[i];
|
---|
| 580 | }
|
---|
| 581 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 582 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 583 |
|
---|
| 584 |
|
---|
| 585 | TestGrammarEnumeration(modifiedProblemData);
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | [TestMethod]
|
---|
| 589 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 590 | [TestProperty("Time", "short")]
|
---|
| 591 | public void MctsSymbReg_NoConstants_Poly10_Part5() {
|
---|
| 592 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 593 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 594 |
|
---|
| 595 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 596 | // Y' = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9
|
---|
| 597 | // simplify problem by changing target
|
---|
| 598 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 599 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 600 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 601 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 602 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 603 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 604 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 605 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 606 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 607 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 608 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 609 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 610 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 611 | ys[i] -= x3[i] * x6[i] * x10[i];
|
---|
| 612 | }
|
---|
| 613 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 614 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 615 |
|
---|
| 616 |
|
---|
| 617 | TestGrammarEnumeration(modifiedProblemData);
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 | [TestMethod]
|
---|
| 621 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 622 | [TestProperty("Time", "short")]
|
---|
| 623 | public void MctsSymbReg_NoConstants_Poly10_Part6() {
|
---|
| 624 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 625 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 626 |
|
---|
| 627 | // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
|
---|
| 628 | // Y' = X1*X2 + X3*X4 + X5*X6 + X3*X6*X10
|
---|
| 629 | // simplify problem by changing target
|
---|
| 630 | var ds = ((Dataset)regProblem.Dataset).ToModifiable();
|
---|
| 631 | var ys = ds.GetDoubleValues("Y").ToArray();
|
---|
| 632 | var x1 = ds.GetDoubleValues("X1").ToArray();
|
---|
| 633 | var x2 = ds.GetDoubleValues("X2").ToArray();
|
---|
| 634 | var x3 = ds.GetDoubleValues("X3").ToArray();
|
---|
| 635 | var x4 = ds.GetDoubleValues("X4").ToArray();
|
---|
| 636 | var x5 = ds.GetDoubleValues("X5").ToArray();
|
---|
| 637 | var x6 = ds.GetDoubleValues("X6").ToArray();
|
---|
| 638 | var x7 = ds.GetDoubleValues("X7").ToArray();
|
---|
| 639 | var x8 = ds.GetDoubleValues("X8").ToArray();
|
---|
| 640 | var x9 = ds.GetDoubleValues("X9").ToArray();
|
---|
| 641 | var x10 = ds.GetDoubleValues("X10").ToArray();
|
---|
| 642 | for (int i = 0; i < ys.Length; i++) {
|
---|
| 643 | ys[i] -= x1[i] * x7[i] * x9[i];
|
---|
| 644 | }
|
---|
| 645 | ds.ReplaceVariable("Y", ys.ToList());
|
---|
| 646 | var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
|
---|
| 647 |
|
---|
| 648 | TestGrammarEnumeration(modifiedProblemData);
|
---|
| 649 | }
|
---|
| 650 |
|
---|
| 651 |
|
---|
| 652 | [TestMethod]
|
---|
| 653 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 654 | [TestProperty("Time", "long")]
|
---|
| 655 | public void MctsSymbReg_NoConstants_Poly10_250rows() {
|
---|
| 656 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
|
---|
| 657 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
|
---|
| 658 | regProblem.TrainingPartition.Start = 0;
|
---|
| 659 | regProblem.TrainingPartition.End = regProblem.Dataset.Rows;
|
---|
| 660 | regProblem.TestPartition.Start = 0;
|
---|
| 661 | regProblem.TestPartition.End = 2;
|
---|
| 662 | TestGrammarEnumeration(regProblem);
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | [TestMethod]
|
---|
| 666 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 667 | [TestProperty("Time", "long")]
|
---|
| 668 | public void MctsSymbReg_NoConstants_Poly10_10000rows() {
|
---|
| 669 | // as poly-10 but more rows
|
---|
| 670 | var x1 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 671 | var x2 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 672 | var x3 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 673 | var x4 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 674 | var x5 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 675 | var x6 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 676 | var x7 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 677 | var x8 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 678 | var x9 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 679 | var x10 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
|
---|
| 680 | var ys = new List<double>();
|
---|
| 681 | for (int i = 0; i < x1.Count; i++) {
|
---|
| 682 | ys.Add(x1[i] * x2[i] + x3[i] * x4[i] + x5[i] * x6[i] + x1[i] * x7[i] * x9[i] + x3[i] * x6[i] * x10[i]);
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | var ds = new Dataset(new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "y" },
|
---|
| 686 | new[] { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, ys });
|
---|
| 687 |
|
---|
| 688 |
|
---|
| 689 | var problemData = new RegressionProblemData(ds, new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }, "y");
|
---|
| 690 |
|
---|
| 691 | problemData.TrainingPartition.Start = 0;
|
---|
| 692 | problemData.TrainingPartition.End = problemData.Dataset.Rows;
|
---|
| 693 | problemData.TestPartition.Start = 0;
|
---|
| 694 | problemData.TestPartition.End = 2; // must not be empty
|
---|
| 695 |
|
---|
| 696 |
|
---|
| 697 | TestGrammarEnumeration(problemData);
|
---|
| 698 | }
|
---|
| 699 |
|
---|
| 700 | [TestMethod]
|
---|
| 701 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 702 | [TestProperty("Time", "short")]
|
---|
| 703 | public void MctsSymbReg_NoConstants_TwoVars() {
|
---|
| 704 |
|
---|
| 705 | // y = x1 + x2 + x1*x2 + x1*x2*x2 + x1*x1*x2
|
---|
| 706 | var x1 = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 707 | var x2 = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 708 | var ys = x1.Zip(x2, (x1i, x2i) => x1i + x2i + x1i * x2i + x1i * x2i * x2i + x1i * x1i * x2i).ToList();
|
---|
| 709 |
|
---|
| 710 | var ds = new Dataset(new string[] { "a", "b", "y" }, new[] { x1, x2, ys });
|
---|
| 711 | var problemData = new RegressionProblemData(ds, new string[] { "a", "b" }, "y");
|
---|
| 712 |
|
---|
| 713 | TestGrammarEnumeration(problemData);
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | [TestMethod]
|
---|
| 717 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 718 | [TestProperty("Time", "short")]
|
---|
| 719 | public void MctsSymbReg_NoConstants_Misleading() {
|
---|
| 720 |
|
---|
| 721 | // y = a + baaaaa (the effect of the second term should be very small)
|
---|
| 722 | // the alg will quickly find that a has big effect and will search below a
|
---|
| 723 | // since we prevent a + a... the algorithm must find the correct expression via a + b...
|
---|
| 724 | // however b has a small effect so the branch might not be identified as relevant
|
---|
| 725 | var @as = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 726 | var bs = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 727 | var cs = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() * 1.0e-3).ToList();
|
---|
| 728 | var ds = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 729 | var es = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
|
---|
| 730 | var ys = new double[@as.Count];
|
---|
| 731 | for (int i = 0; i < ys.Length; i++)
|
---|
| 732 | ys[i] = @as[i] + bs[i] + @as[i] * bs[i] * cs[i];
|
---|
| 733 |
|
---|
| 734 | var dataset = new Dataset(new string[] { "a", "b", "c", "d", "e", "y" }, new[] { @as, bs, cs, ds, es, ys.ToList() });
|
---|
| 735 |
|
---|
| 736 | var problemData = new RegressionProblemData(dataset, new string[] { "a", "b", "c", "d", "e" }, "y");
|
---|
| 737 |
|
---|
| 738 | TestGrammarEnumeration(problemData);
|
---|
| 739 | }
|
---|
| 740 |
|
---|
| 741 | [TestMethod]
|
---|
| 742 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 743 | [TestProperty("Time", "short")]
|
---|
| 744 | public void MctsSymbRegKeijzer7() {
|
---|
| 745 | // ln(x)
|
---|
| 746 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 747 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 7 f(")));
|
---|
| 748 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 749 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 750 | TestGrammarEnumeration(regProblem);
|
---|
| 751 | }
|
---|
| 752 |
|
---|
| 753 |
|
---|
| 754 | [TestMethod]
|
---|
| 755 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 756 | [TestProperty("Time", "short")]
|
---|
| 757 | public void MctsSymbRegBenchmarkNguyen5() {
|
---|
| 758 | // sin(x²)cos(x) - 1
|
---|
| 759 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 760 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F5 ")));
|
---|
| 761 | TestGrammarEnumeration(regProblem);
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | [TestMethod]
|
---|
| 765 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 766 | [TestProperty("Time", "short")]
|
---|
| 767 | public void MctsSymbRegBenchmarkNguyen6() {
|
---|
| 768 | // sin(x) + sin(x + x²)
|
---|
| 769 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 770 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 ")));
|
---|
| 771 | TestGrammarEnumeration(regProblem);
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | [TestMethod]
|
---|
| 775 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 776 | [TestProperty("Time", "short")]
|
---|
| 777 | public void MctsSymbRegBenchmarkNguyen7() {
|
---|
| 778 | // log(x + 1) + log(x² + 1)
|
---|
| 779 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
|
---|
| 780 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
|
---|
| 781 | TestGrammarEnumeration(regProblem);
|
---|
| 782 | }
|
---|
| 783 | [TestMethod]
|
---|
| 784 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 785 | [TestProperty("Time", "short")]
|
---|
| 786 | public void MctsSymbRegBenchmarkNguyen8() {
|
---|
| 787 | // Sqrt(x)
|
---|
| 788 | // = x ^ 0.5
|
---|
| 789 | // = exp(0.5 * log(x))
|
---|
| 790 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
|
---|
| 791 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F8 ")));
|
---|
| 792 | TestGrammarEnumeration(regProblem);
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | // [TestMethod]
|
---|
| 796 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 797 | [TestProperty("Time", "short")]
|
---|
| 798 | public void MctsSymbRegBenchmarkNguyen9() {
|
---|
| 799 | // sin(x) + sin(y²)
|
---|
| 800 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 801 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
|
---|
| 802 | TestGrammarEnumeration(regProblem);
|
---|
| 803 | }
|
---|
| 804 |
|
---|
| 805 | // [TestMethod]
|
---|
| 806 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 807 | [TestProperty("Time", "short")]
|
---|
| 808 | public void MctsSymbRegBenchmarkNguyen10() {
|
---|
| 809 | // 2sin(x)cos(y)
|
---|
| 810 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
|
---|
| 811 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F10 ")));
|
---|
| 812 | TestGrammarEnumeration(regProblem);
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 | [TestMethod]
|
---|
| 816 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 817 | [TestProperty("Time", "short")]
|
---|
| 818 | public void MctsSymbRegBenchmarkNguyen11() {
|
---|
| 819 | // x ^ y , x > 0, y > 0
|
---|
| 820 | // = exp(y * log(x))
|
---|
| 821 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
|
---|
| 822 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F11 ")));
|
---|
| 823 | TestGrammarEnumeration(regProblem);
|
---|
| 824 | }
|
---|
| 825 | [TestMethod]
|
---|
| 826 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 827 | [TestProperty("Time", "short")]
|
---|
| 828 | public void MctsSymbRegBenchmarkNguyen12() {
|
---|
| 829 | // x^4 - x³ + y²/2 - y
|
---|
| 830 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
|
---|
| 831 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F12 ")));
|
---|
| 832 | TestGrammarEnumeration(regProblem);
|
---|
| 833 | }
|
---|
| 834 |
|
---|
| 835 | [TestMethod]
|
---|
| 836 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 837 | [TestProperty("Time", "long")]
|
---|
| 838 | public void MctsSymbRegBenchmarkKeijzer5() {
|
---|
| 839 | // (30 * x * z) / ((x - 10) * y²)
|
---|
| 840 | // = 30 x z / (xy² - y²)
|
---|
| 841 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 842 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 5 f(")));
|
---|
| 843 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 844 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 845 | TestGrammarEnumeration(regProblem);
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | [TestMethod]
|
---|
| 849 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 850 | [TestProperty("Time", "short")]
|
---|
| 851 | public void MctsSymbRegBenchmarkKeijzer6() {
|
---|
| 852 | // Keijzer 6 f(x) = Sum(1 / i) From 1 to X , x \in [0..120]
|
---|
| 853 | // we can only approximate this
|
---|
| 854 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 855 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 6 f(")));
|
---|
| 856 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 857 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 858 | TestGrammarEnumeration(regProblem);
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | [TestMethod]
|
---|
| 862 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 863 | [TestProperty("Time", "short")]
|
---|
| 864 | public void MctsSymbRegBenchmarkKeijzer8() {
|
---|
| 865 | // sqrt(x)
|
---|
| 866 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 867 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 8 f(")));
|
---|
| 868 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 869 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 870 | TestGrammarEnumeration(regProblem);
|
---|
| 871 | }
|
---|
| 872 |
|
---|
| 873 | [TestMethod]
|
---|
| 874 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 875 | [TestProperty("Time", "short")]
|
---|
| 876 | public void MctsSymbRegBenchmarkKeijzer9() {
|
---|
| 877 | // arcsinh(x) i.e. ln(x + sqrt(x² + 1))
|
---|
| 878 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 879 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 9 f(")));
|
---|
| 880 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 881 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 882 | TestGrammarEnumeration(regProblem);
|
---|
| 883 | }
|
---|
| 884 |
|
---|
| 885 | [TestMethod]
|
---|
| 886 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 887 | [TestProperty("Time", "short")]
|
---|
| 888 | public void MctsSymbRegBenchmarkKeijzer11() {
|
---|
| 889 | // xy + sin( (x-1) (y-1) )
|
---|
| 890 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
|
---|
| 891 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 11 f(")));
|
---|
| 892 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 893 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 894 | TestGrammarEnumeration(regProblem);
|
---|
| 895 | }
|
---|
| 896 |
|
---|
| 897 | [TestMethod]
|
---|
| 898 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 899 | [TestProperty("Time", "short")]
|
---|
| 900 | public void MctsSymbRegBenchmarkKeijzer12() {
|
---|
| 901 | // x^4 - x³ + y² / 2 - y, same as Nguyen 12
|
---|
| 902 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 903 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 12 f(")));
|
---|
| 904 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 905 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 906 | TestGrammarEnumeration(regProblem);
|
---|
| 907 | }
|
---|
| 908 |
|
---|
| 909 | [TestMethod]
|
---|
| 910 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 911 | [TestProperty("Time", "short")]
|
---|
| 912 | public void MctsSymbRegBenchmarkKeijzer14() {
|
---|
| 913 | // 8 / (2 + x² + y²)
|
---|
| 914 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 915 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 14 f(")));
|
---|
| 916 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 917 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 918 | TestGrammarEnumeration(regProblem);
|
---|
| 919 | }
|
---|
| 920 |
|
---|
| 921 | [TestMethod]
|
---|
| 922 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 923 | [TestProperty("Time", "short")]
|
---|
| 924 | public void MctsSymbRegBenchmarkKeijzer15() {
|
---|
| 925 | // x³ / 5 + y³ / 2 - y - x
|
---|
| 926 | var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
|
---|
| 927 | var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 15 f(")));
|
---|
| 928 | // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
|
---|
| 929 | if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
|
---|
| 930 | TestGrammarEnumeration(regProblem);
|
---|
| 931 | }
|
---|
[15723] | 932 | #endif
|
---|
[15712] | 933 | }
|
---|
| 934 | }
|
---|