Changeset 15784 for branches/2886_SymRegGrammarEnumeration/Test
- Timestamp:
- 02/16/18 18:36:17 (7 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/Test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs
r15776 r15784 1 1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 2 4 using System.Linq; 3 5 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration; 4 6 using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration.GrammarEnumeration; 7 using HeuristicLab.Common; 5 8 using HeuristicLab.Core; 6 9 using HeuristicLab.Problems.DataAnalysis; … … 52 55 [TestMethod] 53 56 [TestProperty("Goal", "structure search")] 54 public void MctsSymbReg_NoConstants_Nguyen1() {57 public void NoConstants_Nguyen1() { 55 58 // x³ + x² + x 56 alg.MaxTreeSize = 1 5;57 alg.Problem.ProblemData = new NguyenFunctionOne(Seed).GenerateRegressionData(); 59 alg.MaxTreeSize = 12; 60 alg.Problem.ProblemData = new NguyenFunctionOne(Seed).GenerateRegressionData(); 58 61 59 62 alg.Start(); … … 83 86 //[TestMethod] 84 87 [TestProperty("Goal", "structure search")] 85 public void MctsSymbReg_NoConstants_Nguyen2() {88 public void NoConstants_Nguyen2() { 86 89 // x^4 + x³ + x² + x 87 90 alg.MaxTreeSize = 20; … … 95 98 //[TestMethod] 96 99 [TestProperty("Goal", "structure search")] 97 public void MctsSymbReg_NoConstants_Nguyen3() {100 public void NoConstants_Nguyen3() { 98 101 // x^5 + x^4 + x^3 + x^2 + x 99 102 alg.MaxTreeSize = 32; … … 105 108 } 106 109 107 [TestMethod] 108 [TestProperty("Goal", "structure search")] 109 public void MctsSymbReg_NoConstants_Nguyen6() {110 [TestMethod] 111 [TestProperty("Goal", "structure search")] 112 public void NoConstants_Nguyen6() { 110 113 // sin(x) + sin(x + x²) 111 alg.MaxTreeSize = 1 5;114 alg.MaxTreeSize = 13; 112 115 alg.Problem.ProblemData = new NguyenFunctionSix(Seed).GenerateRegressionData(); 113 116 114 117 alg.Start(); 115 EvaluateGrammarEnumeration(); 116 } 117 118 [TestMethod] 119 [TestProperty("Goal", "structure search")] 120 public void MctsSymbReg_NoConstants_Nguyen9() { 118 119 TerminalSymbol varSymbol = alg.Grammar.Var.VariableTerminalSymbols.First(); 120 TerminalSymbol mulSymbol = alg.Grammar.Multiplication; 121 TerminalSymbol addSymbol = alg.Grammar.Addition; 122 TerminalSymbol sinSymbol = alg.Grammar.Sin; 123 124 SymbolString targetSolution = new SymbolString(new[] { 125 varSymbol, sinSymbol, 126 varSymbol, varSymbol, mulSymbol, varSymbol, addSymbol, sinSymbol, addSymbol 127 }); 128 129 int targetSolutionHash = alg.Grammar.CalcHashCode(targetSolution); 130 int actualSolutionHash = alg.Grammar.CalcHashCode(alg.BestTrainingSentence); 131 132 Assert.IsTrue(alg.DistinctSentences.ContainsKey(actualSolutionHash), "Actual solution was not generated!"); 133 134 Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one."); 135 136 EvaluateGrammarEnumeration(); 137 } 138 139 [TestMethod] 140 [TestProperty("Goal", "structure search")] 141 public void NoConstants_Nguyen9() { 121 142 // sin(x) + sin(y²) 122 143 alg.MaxTreeSize = 10; … … 133 154 alg.MaxTreeSize = 10; 134 155 alg.Problem.ProblemData = new PolyTen(Seed).GenerateRegressionData(); 156 157 alg.Start(); 158 EvaluateGrammarEnumeration(); 159 } 160 161 [TestMethod] 162 [TestProperty("Goal", "structure search")] 163 public void NoConstants_Inverse() { 164 // 1 / (log(x)*x + x) 165 alg.MaxTreeSize = 12; 166 167 var x = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() + 1.1).ToList(); 168 var y = x.Select(xi => 1 / (Math.Log(xi) * xi + xi)).ToList(); 169 alg.Problem.ProblemData = new RegressionProblemData(new Dataset(new List<string>() { "x", "y" }, new List<IList>() { x, y }), "x".ToEnumerable(), "y"); 135 170 136 171 alg.Start(); … … 210 245 var ys = ds.GetDoubleValues("Y").ToArray(); 211 246 var x1 = ds.GetDoubleValues("X1").ToArray(); 212 var x2 = ds.GetDoubleValues("X2").ToArray(); 247 var x2 = ds.GetDoubleValues("X2").ToArray(); 213 248 var x3 = ds.GetDoubleValues("X3").ToArray(); 214 249 var x4 = ds.GetDoubleValues("X4").ToArray(); -
branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs
r15746 r15784 106 106 } 107 107 108 [TestMethod] 109 [TestCategory("TreeHashing")] 110 public void InverseFactorCancelationSimple() { 111 SymbolString s1 = new SymbolString(new Symbol[] { varA, grammar.Inv, varB, grammar.Multiplication, varA, grammar.Multiplication, varA, grammar.Multiplication }); 112 SymbolString s2 = new SymbolString(new Symbol[] { varA, varB, grammar.Multiplication }); 113 114 int hash1 = grammar.CalcHashCode(s1); 115 int hash2 = grammar.CalcHashCode(s2); 116 117 Assert.AreEqual(hash1, hash2); 118 } 119 120 [TestMethod] 121 [TestCategory("TreeHashing")] 122 public void InverseFactorCancelationComplex() { 123 SymbolString s1 = new SymbolString(new Symbol[] { varA, grammar.Sin, varA, varA, grammar.Multiplication, varA, grammar.Addition, grammar.Sin, grammar.Addition }); 124 SymbolString s2 = new SymbolString(new Symbol[] { varA, varA, varA, grammar.Multiplication, grammar.Addition, grammar.Sin, varA, grammar.Inv, varA, grammar.Sin, varA, grammar.Multiplication, grammar.Multiplication, grammar.Addition }); 125 126 int hash1 = grammar.CalcHashCode(s1); 127 int hash2 = grammar.CalcHashCode(s2); 128 129 Assert.AreEqual(hash1, hash2); 130 } 108 131 109 132 #region parser
Note: See TracChangeset
for help on using the changeset viewer.