- Timestamp:
- 02/06/18 13:18:31 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs
r15714 r15723 1 1 using System; 2 using System.Collections.Generic;3 2 using System.Linq; 4 3 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration; … … 10 9 11 10 namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression { 12 //[TestClass()]11 [TestClass()] 13 12 public class MctsSymbolicRegressionTest { 14 13 private const int Seed = 1234; 15 14 private IRandom rand; 16 15 17 private const double SuccessThreshold = 0.99999; 16 private const double SuccessThreshold = 0.9999999; 17 18 private GrammarEnumerationAlgorithm alg; 19 private RegressionProblem problem; 18 20 19 21 [TestInitialize] … … 21 23 Console.Write("init called... "); 22 24 rand = new FastRandom(Seed); 23 } 25 26 alg = new GrammarEnumerationAlgorithm(); 27 problem = new RegressionProblem(); 28 alg.Problem = problem; 29 alg.GuiUpdateInterval = int.MaxValue; 30 } 31 32 33 private void TestGrammarEnumeration(IRegressionProblemData problemData) { 34 alg.Problem.ProblemData = problemData; 35 36 // Run 37 alg.Start(); 38 39 // Evaluate results 40 var eps = 1.0 - SuccessThreshold; 41 42 // Check if algorithm terminated correctly 43 Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (training)"), "No training solution returned!"); 44 Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (test)"), "No test solution returned!"); 45 46 // Check resultss 47 Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (training)"].Value).Value, eps, "Training quality too low!"); 48 Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (test)"].Value).Value, eps, "Test quality too low!"); 49 50 // Check overfitting 51 Assert.AreEqual(alg.Results["Best solution string (training)"].Value.ToString(), 52 alg.Results["Best solution string (test)"].Value.ToString()); 53 } 54 24 55 25 56 #region test structure search (no constants) 26 57 [TestMethod] 27 [TestCategory("Algorithms.DataAnalysis")] 28 [TestProperty("Time", "short")] 58 [TestProperty("Goal", "structure search")] 29 59 public void MctsSymbReg_NoConstants_Nguyen1() { 30 60 // x³ + x² + x 61 alg.MaxTreeSize = 15; 31 62 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed); 32 63 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 "))); 33 64 TestGrammarEnumeration(regProblem); 34 } 35 [TestMethod] 36 [TestCategory("Algorithms.DataAnalysis")] 37 [TestProperty("Time", "short")] 65 66 Console.WriteLine("Nguyen1: " + alg.Results["Best solution string (training)"].Value); 67 } 68 69 [TestMethod] 70 [TestProperty("Goal", "structure search")] 38 71 public void MctsSymbReg_NoConstants_Nguyen2() { 39 72 // x^4 + x³ + x² + x 73 alg.MaxTreeSize = 20; 40 74 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed); 41 75 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 "))); 42 76 TestGrammarEnumeration(regProblem); 43 } 44 [TestMethod] 45 [TestCategory("Algorithms.DataAnalysis")] 46 [TestProperty("Time", "short")] 77 78 Console.WriteLine("Nguyen2: " + alg.Results["Best solution string (training)"].Value); 79 } 80 81 /* NEXT UP 82 [TestMethod] 83 [TestProperty("Goal", "structure search")] 47 84 public void MctsSymbReg_NoConstants_Nguyen3() { 48 85 // x^5 + x^4 + x³ + x² + x 86 alg.MaxTreeSize = 25; 49 87 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed); 50 88 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 "))); … … 52 90 } 53 91 [TestMethod] 54 [TestCategory("Algorithms.DataAnalysis")] 55 [TestProperty("Time", "short")] 92 [TestProperty("Goal", "structure search")] 56 93 public void MctsSymbReg_NoConstants_Nguyen4() { 94 57 95 // x^6 + x^5 + x^4 + x³ + x² + x 96 alg.MaxTreeSize = 30; 58 97 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed); 59 98 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 "))); 60 99 TestGrammarEnumeration(regProblem); 61 } 62 100 } */ 101 102 103 #endregion 104 105 #region TODO 106 107 #if false 63 108 [TestMethod] 64 109 [TestCategory("Algorithms.DataAnalysis")] … … 357 402 TestGrammarEnumeration(problemData); 358 403 } 359 #endregion360 404 361 405 #region restricted structure but including numeric constants … … 557 601 #endregion 558 602 559 private void TestGrammarEnumeration(IRegressionProblemData problemData) 560 { 561 // Configure algorithm and problem 562 var alg = new GrammarEnumerationAlgorithm(); 563 var problem = new RegressionProblem(); 564 alg.Problem = problem; 565 problem.ProblemData = problemData; 566 567 // Run 568 alg.Start(); 569 570 // Evaluate results 571 var eps = 1.0 - SuccessThreshold; 572 573 // Check if algorithm terminated correctly 574 Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (training)"), "No training solution returned!"); 575 Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (test)"), "No test solution returned!"); 576 577 // Check resultss 578 Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (training)"].Value).Value, eps, "Training quality too low!"); 579 Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (test)"].Value).Value, eps, "Test quality too low!"); 580 } 603 #endif 604 #endregion 581 605 } 582 606 }
Note: See TracChangeset
for help on using the changeset viewer.