Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs @ 15725

Last change on this file since 15725 was 15724, checked in by lkammere, 7 years ago

#2886: Add parsing to infix form for debugging purpose.

File size: 28.3 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Optimization;
8using HeuristicLab.Problems.DataAnalysis;
9using HeuristicLab.Random;
10using Microsoft.VisualStudio.TestTools.UnitTesting;
11
12namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
13  [TestClass]
14  public class MctsSymbolicRegressionTest {
15    private const int Seed = 1234;
16    private IRandom rand;
17
18    private const double SuccessThreshold = 0.9999999;
19
20    private GrammarEnumerationAlgorithm alg;
21    private RegressionProblem problem;
22
23    [TestInitialize]
24    public void InitTest() {
25      Console.Write("init called... ");
26      rand = new FastRandom(Seed);
27
28      alg = new GrammarEnumerationAlgorithm();
29      problem = new RegressionProblem();
30      alg.Problem = problem;
31      alg.GuiUpdateInterval = int.MaxValue;
32    }
33
34    [TestCleanup()]
35    public void Cleanup() {
36      if (alg.BestTrainingSentence != null) {
37        Console.WriteLine("Training: " + alg.Grammar.PostfixToInfixParser(alg.BestTrainingSentence));
38      }
39      if (alg.BestTestSentence != null) {
40        Console.WriteLine("Test: " + alg.Grammar.PostfixToInfixParser(alg.BestTestSentence));
41      }
42    }
43
44
45    private void TestGrammarEnumeration(IRegressionProblemData problemData) {
46      alg.Problem.ProblemData = problemData;
47
48      // Run
49      alg.Start();
50
51      // Evaluate results
52      var eps = 1.0 - SuccessThreshold;
53
54      // Check if algorithm terminated correctly
55      Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (training)"), "No training solution returned!");
56      Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (test)"), "No test solution returned!");
57
58      // Check resultss
59      Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (training)"].Value).Value, eps, "Training quality too low!");
60      Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (test)"].Value).Value, eps, "Test quality too low!");
61
62      // Check overfitting
63      Assert.AreEqual(alg.Grammar.CalcHashCode(alg.BestTrainingSentence),
64                    alg.Grammar.CalcHashCode(alg.BestTestSentence),
65                    "Training and Test solution are not equal!");
66    }
67
68
69    #region test structure search (no constants)
70    [TestMethod]
71    [TestProperty("Goal", "structure search")]
72    public void MctsSymbReg_NoConstants_Nguyen1() {
73      // x³ + x² + x
74      alg.MaxTreeSize = 15;
75      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
76      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
77      TestGrammarEnumeration(regProblem);
78    }
79
80    [TestMethod]
81    [TestProperty("Goal", "structure search")]
82    public void MctsSymbReg_NoConstants_Nguyen2() {
83      // x^4 + x³ + x² + x
84      alg.MaxTreeSize = 20;
85      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
86      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 ")));
87      TestGrammarEnumeration(regProblem);
88    }
89
90    /*  NEXT UP
91    [TestMethod]
92    [TestProperty("Goal", "structure search")]
93    public void MctsSymbReg_NoConstants_Nguyen3() {
94      // x^5 + x^4 + x³ + x² + x
95      alg.MaxTreeSize = 25;
96      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
97      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));
98      TestGrammarEnumeration(regProblem);
99    }
100    [TestMethod]
101    [TestProperty("Goal", "structure search")]
102    public void MctsSymbReg_NoConstants_Nguyen4() {
103
104      // x^6 + x^5 + x^4 + x³ + x² + x
105      alg.MaxTreeSize = 30;
106      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
107      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 ")));
108      TestGrammarEnumeration(regProblem);
109    } */
110
111
112    #endregion
113
114    #region TODO
115
116#if false
117    [TestMethod]
118    [TestCategory("Algorithms.DataAnalysis")]
119    [TestProperty("Time", "short")]
120    public void MctsSymbReg_NoConstants_Nguyen7() {
121      // log(x + 1) + log(x² + 1)
122      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
123      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
124      TestGrammarEnumeration(regProblem);
125    }
126
127    [TestMethod]
128    [TestCategory("Algorithms.DataAnalysis")]
129    [TestProperty("Time", "short")]
130    public void MctsSymbReg_NoConstants_Poly10_Part1() {
131      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
132      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
133
134      //  Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
135      //  Y' = X1*X2 + X3*X4 + X5*X6
136      // simplify problem by changing target
137      var ds = ((Dataset)regProblem.Dataset).ToModifiable();
138      var ys = ds.GetDoubleValues("Y").ToArray();
139      var x1 = ds.GetDoubleValues("X1").ToArray();
140      var x2 = ds.GetDoubleValues("X2").ToArray();
141      var x3 = ds.GetDoubleValues("X3").ToArray();
142      var x4 = ds.GetDoubleValues("X4").ToArray();
143      var x5 = ds.GetDoubleValues("X5").ToArray();
144      var x6 = ds.GetDoubleValues("X6").ToArray();
145      var x7 = ds.GetDoubleValues("X7").ToArray();
146      var x8 = ds.GetDoubleValues("X8").ToArray();
147      var x9 = ds.GetDoubleValues("X9").ToArray();
148      var x10 = ds.GetDoubleValues("X10").ToArray();
149      for (int i = 0; i < ys.Length; i++) {
150        ys[i] -= x1[i] * x7[i] * x9[i];
151        ys[i] -= x3[i] * x6[i] * x10[i];
152      }
153      ds.ReplaceVariable("Y", ys.ToList());
154
155      var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
156
157      TestGrammarEnumeration(modifiedProblemData);
158    }
159
160    [TestMethod]
161    [TestCategory("Algorithms.DataAnalysis")]
162    [TestProperty("Time", "short")]
163    public void MctsSymbReg_NoConstants_Poly10_Part2() {
164      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
165      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
166
167      //  Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
168      //  Y' = X1*X7*X9 + X3*X6*X10
169      // simplify problem by changing target
170      var ds = ((Dataset)regProblem.Dataset).ToModifiable();
171      var ys = ds.GetDoubleValues("Y").ToArray();
172      var x1 = ds.GetDoubleValues("X1").ToArray();
173      var x2 = ds.GetDoubleValues("X2").ToArray();
174      var x3 = ds.GetDoubleValues("X3").ToArray();
175      var x4 = ds.GetDoubleValues("X4").ToArray();
176      var x5 = ds.GetDoubleValues("X5").ToArray();
177      var x6 = ds.GetDoubleValues("X6").ToArray();
178      var x7 = ds.GetDoubleValues("X7").ToArray();
179      var x8 = ds.GetDoubleValues("X8").ToArray();
180      var x9 = ds.GetDoubleValues("X9").ToArray();
181      var x10 = ds.GetDoubleValues("X10").ToArray();
182      for (int i = 0; i < ys.Length; i++) {
183        ys[i] -= x1[i] * x2[i];
184        ys[i] -= x3[i] * x4[i];
185        ys[i] -= x5[i] * x6[i];
186      }
187      ds.ReplaceVariable("Y", ys.ToList());
188
189      var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
190
191      TestGrammarEnumeration(modifiedProblemData);
192    }
193
194    [TestMethod]
195    [TestCategory("Algorithms.DataAnalysis")]
196    [TestProperty("Time", "short")]
197    public void MctsSymbReg_NoConstants_Poly10_Part3() {
198      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
199      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
200
201      //  Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
202      //  Y' = X1*X2 + X1*X7*X9
203      // simplify problem by changing target
204      var ds = ((Dataset)regProblem.Dataset).ToModifiable();
205      var ys = ds.GetDoubleValues("Y").ToArray();
206      var x1 = ds.GetDoubleValues("X1").ToArray();
207      var x2 = ds.GetDoubleValues("X2").ToArray();
208      var x3 = ds.GetDoubleValues("X3").ToArray();
209      var x4 = ds.GetDoubleValues("X4").ToArray();
210      var x5 = ds.GetDoubleValues("X5").ToArray();
211      var x6 = ds.GetDoubleValues("X6").ToArray();
212      var x7 = ds.GetDoubleValues("X7").ToArray();
213      var x8 = ds.GetDoubleValues("X8").ToArray();
214      var x9 = ds.GetDoubleValues("X9").ToArray();
215      var x10 = ds.GetDoubleValues("X10").ToArray();
216      for (int i = 0; i < ys.Length; i++) {
217        ys[i] -= x3[i] * x4[i];
218        ys[i] -= x5[i] * x6[i];
219        ys[i] -= x3[i] * x6[i] * x10[i];
220      }
221      ds.ReplaceVariable("Y", ys.ToList());
222
223      var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
224
225      TestGrammarEnumeration(modifiedProblemData);
226    }
227
228    [TestMethod]
229    [TestCategory("Algorithms.DataAnalysis")]
230    [TestProperty("Time", "short")]
231    public void MctsSymbReg_NoConstants_Poly10_Part4() {
232      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
233      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
234
235      //  Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
236      //  Y' = X3*X4 + X5*X6 + X3*X6*X10
237      // simplify problem by changing target
238      var ds = ((Dataset)regProblem.Dataset).ToModifiable();
239      var ys = ds.GetDoubleValues("Y").ToArray();
240      var x1 = ds.GetDoubleValues("X1").ToArray();
241      var x2 = ds.GetDoubleValues("X2").ToArray();
242      var x3 = ds.GetDoubleValues("X3").ToArray();
243      var x4 = ds.GetDoubleValues("X4").ToArray();
244      var x5 = ds.GetDoubleValues("X5").ToArray();
245      var x6 = ds.GetDoubleValues("X6").ToArray();
246      var x7 = ds.GetDoubleValues("X7").ToArray();
247      var x8 = ds.GetDoubleValues("X8").ToArray();
248      var x9 = ds.GetDoubleValues("X9").ToArray();
249      var x10 = ds.GetDoubleValues("X10").ToArray();
250      for (int i = 0; i < ys.Length; i++) {
251        ys[i] -= x1[i] * x2[i];
252        ys[i] -= x1[i] * x7[i] * x9[i];
253      }
254      ds.ReplaceVariable("Y", ys.ToList());
255      var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
256
257
258      TestGrammarEnumeration(modifiedProblemData);
259    }
260
261    [TestMethod]
262    [TestCategory("Algorithms.DataAnalysis")]
263    [TestProperty("Time", "short")]
264    public void MctsSymbReg_NoConstants_Poly10_Part5() {
265      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
266      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
267
268      //  Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
269      //  Y' = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9
270      // simplify problem by changing target
271      var ds = ((Dataset)regProblem.Dataset).ToModifiable();
272      var ys = ds.GetDoubleValues("Y").ToArray();
273      var x1 = ds.GetDoubleValues("X1").ToArray();
274      var x2 = ds.GetDoubleValues("X2").ToArray();
275      var x3 = ds.GetDoubleValues("X3").ToArray();
276      var x4 = ds.GetDoubleValues("X4").ToArray();
277      var x5 = ds.GetDoubleValues("X5").ToArray();
278      var x6 = ds.GetDoubleValues("X6").ToArray();
279      var x7 = ds.GetDoubleValues("X7").ToArray();
280      var x8 = ds.GetDoubleValues("X8").ToArray();
281      var x9 = ds.GetDoubleValues("X9").ToArray();
282      var x10 = ds.GetDoubleValues("X10").ToArray();
283      for (int i = 0; i < ys.Length; i++) {
284        ys[i] -= x3[i] * x6[i] * x10[i];
285      }
286      ds.ReplaceVariable("Y", ys.ToList());
287      var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
288
289
290      TestGrammarEnumeration(modifiedProblemData);
291    }
292
293    [TestMethod]
294    [TestCategory("Algorithms.DataAnalysis")]
295    [TestProperty("Time", "short")]
296    public void MctsSymbReg_NoConstants_Poly10_Part6() {
297      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
298      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
299
300      //  Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10
301      //  Y' = X1*X2 + X3*X4 + X5*X6 + X3*X6*X10
302      // simplify problem by changing target
303      var ds = ((Dataset)regProblem.Dataset).ToModifiable();
304      var ys = ds.GetDoubleValues("Y").ToArray();
305      var x1 = ds.GetDoubleValues("X1").ToArray();
306      var x2 = ds.GetDoubleValues("X2").ToArray();
307      var x3 = ds.GetDoubleValues("X3").ToArray();
308      var x4 = ds.GetDoubleValues("X4").ToArray();
309      var x5 = ds.GetDoubleValues("X5").ToArray();
310      var x6 = ds.GetDoubleValues("X6").ToArray();
311      var x7 = ds.GetDoubleValues("X7").ToArray();
312      var x8 = ds.GetDoubleValues("X8").ToArray();
313      var x9 = ds.GetDoubleValues("X9").ToArray();
314      var x10 = ds.GetDoubleValues("X10").ToArray();
315      for (int i = 0; i < ys.Length; i++) {
316        ys[i] -= x1[i] * x7[i] * x9[i];
317      }
318      ds.ReplaceVariable("Y", ys.ToList());
319      var modifiedProblemData = new RegressionProblemData(ds, regProblem.AllowedInputVariables, regProblem.TargetVariable);
320
321      TestGrammarEnumeration(modifiedProblemData);
322    }
323
324
325    [TestMethod]
326    [TestCategory("Algorithms.DataAnalysis")]
327    [TestProperty("Time", "long")]
328    public void MctsSymbReg_NoConstants_Poly10_250rows() {
329      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(Seed);
330      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10")));
331      regProblem.TrainingPartition.Start = 0;
332      regProblem.TrainingPartition.End = regProblem.Dataset.Rows;
333      regProblem.TestPartition.Start = 0;
334      regProblem.TestPartition.End = 2;
335      TestGrammarEnumeration(regProblem);
336    }
337
338    [TestMethod]
339    [TestCategory("Algorithms.DataAnalysis")]
340    [TestProperty("Time", "long")]
341    public void MctsSymbReg_NoConstants_Poly10_10000rows() {
342      // as poly-10 but more rows
343      var x1 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
344      var x2 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
345      var x3 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
346      var x4 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
347      var x5 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
348      var x6 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
349      var x7 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
350      var x8 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
351      var x9 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
352      var x10 = Enumerable.Range(0, 10000).Select(_ => rand.NextDouble()).ToList();
353      var ys = new List<double>();
354      for (int i = 0; i < x1.Count; i++) {
355        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]);
356      }
357
358      var ds = new Dataset(new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "y" },
359        new[] { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, ys });
360
361
362      var problemData = new RegressionProblemData(ds, new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }, "y");
363
364      problemData.TrainingPartition.Start = 0;
365      problemData.TrainingPartition.End = problemData.Dataset.Rows;
366      problemData.TestPartition.Start = 0;
367      problemData.TestPartition.End = 2; // must not be empty
368
369
370      TestGrammarEnumeration(problemData);
371    }
372
373    [TestMethod]
374    [TestCategory("Algorithms.DataAnalysis")]
375    [TestProperty("Time", "short")]
376    public void MctsSymbReg_NoConstants_TwoVars() {
377
378      // y = x1 + x2 + x1*x2 + x1*x2*x2 + x1*x1*x2
379      var x1 = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
380      var x2 = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
381      var ys = x1.Zip(x2, (x1i, x2i) => x1i + x2i + x1i * x2i + x1i * x2i * x2i + x1i * x1i * x2i).ToList();
382
383      var ds = new Dataset(new string[] { "a", "b", "y" }, new[] { x1, x2, ys });
384      var problemData = new RegressionProblemData(ds, new string[] { "a", "b" }, "y");
385
386      TestGrammarEnumeration(problemData);
387    }
388
389    [TestMethod]
390    [TestCategory("Algorithms.DataAnalysis")]
391    [TestProperty("Time", "short")]
392    public void MctsSymbReg_NoConstants_Misleading() {
393
394      // y = a + baaaaa (the effect of the second term should be very small)
395      // the alg will quickly find that a has big effect and will search below a
396      // since we prevent a + a... the algorithm must find the correct expression via a + b...
397      // however b has a small effect so the branch might not be identified as relevant
398      var @as = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
399      var bs = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
400      var cs = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() * 1.0e-3).ToList();
401      var ds = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
402      var es = Enumerable.Range(0, 100).Select(_ => rand.NextDouble()).ToList();
403      var ys = new double[@as.Count];
404      for (int i = 0; i < ys.Length; i++)
405        ys[i] = @as[i] + bs[i] + @as[i] * bs[i] * cs[i];
406
407      var dataset = new Dataset(new string[] { "a", "b", "c", "d", "e", "y" }, new[] { @as, bs, cs, ds, es, ys.ToList() });
408
409      var problemData = new RegressionProblemData(dataset, new string[] { "a", "b", "c", "d", "e" }, "y");
410
411      TestGrammarEnumeration(problemData);
412    }
413
414    #region restricted structure but including numeric constants
415
416    [TestMethod]
417    [TestCategory("Algorithms.DataAnalysis")]
418    [TestProperty("Time", "short")]
419    public void MctsSymbRegKeijzer7() {
420      // ln(x)
421      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
422      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 7 f(")));
423      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
424      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
425      TestGrammarEnumeration(regProblem);
426    }
427
428   
429    [TestMethod]
430    [TestCategory("Algorithms.DataAnalysis")]
431    [TestProperty("Time", "short")]
432    public void MctsSymbRegBenchmarkNguyen5() {
433      // sin(x²)cos(x) - 1
434      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
435      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F5 ")));
436      TestGrammarEnumeration(regProblem);
437    }
438
439    [TestMethod]
440    [TestCategory("Algorithms.DataAnalysis")]
441    [TestProperty("Time", "short")]
442    public void MctsSymbRegBenchmarkNguyen6() {
443      // sin(x) + sin(x + x²)
444      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
445      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 ")));
446      TestGrammarEnumeration(regProblem);
447    }
448   
449    [TestMethod]
450    [TestCategory("Algorithms.DataAnalysis")]
451    [TestProperty("Time", "short")]
452    public void MctsSymbRegBenchmarkNguyen7() {
453      //  log(x + 1) + log(x² + 1)
454      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
455      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));
456      TestGrammarEnumeration(regProblem);
457    }
458    [TestMethod]
459    [TestCategory("Algorithms.DataAnalysis")]
460    [TestProperty("Time", "short")]
461    public void MctsSymbRegBenchmarkNguyen8() {
462      // Sqrt(x)
463      // = x ^ 0.5
464      // = exp(0.5 * log(x))
465      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
466      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F8 ")));
467      TestGrammarEnumeration(regProblem);
468    }
469   
470    // [TestMethod]
471    [TestCategory("Algorithms.DataAnalysis")]
472    [TestProperty("Time", "short")]
473    public void MctsSymbRegBenchmarkNguyen9() {
474      //  sin(x) + sin(y²)
475      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
476      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
477      TestGrammarEnumeration(regProblem);
478    }
479
480    // [TestMethod]
481    [TestCategory("Algorithms.DataAnalysis")]
482    [TestProperty("Time", "short")]
483    public void MctsSymbRegBenchmarkNguyen10() {
484      // 2sin(x)cos(y)
485      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
486      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F10 ")));
487      TestGrammarEnumeration(regProblem);
488    }
489   
490    [TestMethod]
491    [TestCategory("Algorithms.DataAnalysis")]
492    [TestProperty("Time", "short")]
493    public void MctsSymbRegBenchmarkNguyen11() {
494      // x ^ y  , x > 0, y > 0   
495      // = exp(y * log(x))
496      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
497      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F11 ")));
498      TestGrammarEnumeration(regProblem);
499    }
500    [TestMethod]
501    [TestCategory("Algorithms.DataAnalysis")]
502    [TestProperty("Time", "short")]
503    public void MctsSymbRegBenchmarkNguyen12() {
504      // x^4 - x³ + y²/2 - y
505      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
506      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F12 ")));
507      TestGrammarEnumeration(regProblem);
508    }
509
510    #endregion
511
512    #region keijzer
513    [TestMethod]
514    [TestCategory("Algorithms.DataAnalysis")]
515    [TestProperty("Time", "long")]
516    public void MctsSymbRegBenchmarkKeijzer5() {
517      // (30 * x * z) / ((x - 10)  * y²)
518      // = 30 x z / (xy² - y²)
519      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
520      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 5 f(")));
521      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
522      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
523      TestGrammarEnumeration(regProblem);
524    }
525
526    [TestMethod]
527    [TestCategory("Algorithms.DataAnalysis")]
528    [TestProperty("Time", "short")]
529    public void MctsSymbRegBenchmarkKeijzer6() {
530      // Keijzer 6 f(x) = Sum(1 / i) From 1 to X  , x \in [0..120]
531      // we can only approximate this
532      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
533      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 6 f(")));
534      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
535      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
536      TestGrammarEnumeration(regProblem);
537    }
538
539    [TestMethod]
540    [TestCategory("Algorithms.DataAnalysis")]
541    [TestProperty("Time", "short")]
542    public void MctsSymbRegBenchmarkKeijzer8() {
543      // sqrt(x)
544      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
545      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 8 f(")));
546      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
547      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
548      TestGrammarEnumeration(regProblem);
549    }
550
551    [TestMethod]
552    [TestCategory("Algorithms.DataAnalysis")]
553    [TestProperty("Time", "short")]
554    public void MctsSymbRegBenchmarkKeijzer9() {
555      // arcsinh(x)  i.e. ln(x + sqrt(x² + 1))
556      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
557      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 9 f(")));
558      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
559      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
560      TestGrammarEnumeration(regProblem);
561    }
562
563    [TestMethod]
564    [TestCategory("Algorithms.DataAnalysis")]
565    [TestProperty("Time", "short")]
566    public void MctsSymbRegBenchmarkKeijzer11() {
567      // xy + sin( (x-1) (y-1) )
568      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
569      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 11 f(")));
570      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
571      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
572      TestGrammarEnumeration(regProblem);
573    }
574
575    [TestMethod]
576    [TestCategory("Algorithms.DataAnalysis")]
577    [TestProperty("Time", "short")]
578    public void MctsSymbRegBenchmarkKeijzer12() {
579      // x^4 - x³ + y² / 2 - y,  same as Nguyen 12             
580      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
581      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 12 f(")));
582      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
583      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
584      TestGrammarEnumeration(regProblem);
585    }
586
587    [TestMethod]
588    [TestCategory("Algorithms.DataAnalysis")]
589    [TestProperty("Time", "short")]
590    public void MctsSymbRegBenchmarkKeijzer14() {
591      // 8 / (2 + x² + y²)
592      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
593      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 14 f(")));
594      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
595      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
596      TestGrammarEnumeration(regProblem);
597    }
598
599    [TestMethod]
600    [TestCategory("Algorithms.DataAnalysis")]
601    [TestProperty("Time", "short")]
602    public void MctsSymbRegBenchmarkKeijzer15() {
603      // x³ / 5 + y³ / 2 - y - x
604      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(Seed);
605      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 15 f(")));
606      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
607      if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000;
608      TestGrammarEnumeration(regProblem);
609    }
610    #endregion
611
612#endif
613    #endregion
614  }
615}
Note: See TracBrowser for help on using the repository browser.