Changeset 15849 for branches/2886_SymRegGrammarEnumeration/Test
- Timestamp:
- 03/20/18 13:49:19 (6 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration/Test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs
r15834 r15849 31 31 alg.Problem = problem; 32 32 alg.GuiUpdateInterval = int.MaxValue; 33 foreach (IGrammarEnumerationAnalyzer grammarEnumerationAnalyzer in alg.Analyzers) { 34 alg.Analyzers.SetItemCheckedState(grammarEnumerationAnalyzer, grammarEnumerationAnalyzer is RSquaredEvaluator); 35 } 33 36 } 34 37 … … 57 60 public void NoConstants_Nguyen1() { 58 61 // x³ + x² + x 59 alg.MaxTreeSize = 12;62 alg.MaxTreeSize = 20; 60 63 alg.Problem.ProblemData = new NguyenFunctionOne(Seed).GenerateRegressionData(); 61 64 62 65 alg.Start(); 63 66 67 TerminalSymbol constSymbol = alg.Grammar.Const; 64 68 TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First(); 65 69 TerminalSymbol mulSymbol = alg.Grammar.Multiplication; … … 67 71 68 72 SymbolString targetSolution = new SymbolString(new[] { 69 varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, 70 varSymbol, varSymbol, mulSymbol, addSymbol, 71 varSymbol, addSymbol 73 constSymbol, varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, mulSymbol, 74 constSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, addSymbol, 75 constSymbol, varSymbol, mulSymbol, addSymbol, 76 constSymbol, addSymbol 72 77 }); 73 78 … … 88 93 public void NoConstants_Nguyen2() { 89 94 // x^4 + x³ + x² + x 90 alg.MaxTreeSize = 20;95 alg.MaxTreeSize = 30; 91 96 alg.Problem.ProblemData = new NguyenFunctionTwo(Seed).GenerateRegressionData(); 92 97 … … 112 117 public void NoConstants_Nguyen6() { 113 118 // sin(x) + sin(x + x²) 114 alg.MaxTreeSize = 10;119 alg.MaxTreeSize = 25; 115 120 alg.Problem.ProblemData = new NguyenFunctionSix(Seed).GenerateRegressionData(); 116 121 117 122 alg.Start(); 118 123 124 TerminalSymbol constSymbol = alg.Grammar.Const; 119 125 TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First(); 120 126 TerminalSymbol mulSymbol = alg.Grammar.Multiplication; … … 122 128 TerminalSymbol sinSymbol = alg.Grammar.Sin; 123 129 130 // c * sin(c x + c) + c * sin(c * x * x + c * x) + c 124 131 SymbolString targetSolution = new SymbolString(new[] { 125 varSymbol, sinSymbol, 126 varSymbol, varSymbol, mulSymbol, varSymbol, addSymbol, sinSymbol, addSymbol 132 varSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, 133 varSymbol, varSymbol, mulSymbol, constSymbol, mulSymbol, varSymbol, constSymbol, mulSymbol, addSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, addSymbol, 134 constSymbol, addSymbol 127 135 }); 128 136 … … 140 148 public void NoConstants_Nguyen9() { 141 149 // sin(x) + sin(y²) 142 alg.MaxTreeSize = 11;150 alg.MaxTreeSize = 22; 143 151 alg.Problem.ProblemData = new NguyenFunctionNine(Seed).GenerateRegressionData(); 144 152 … … 147 155 TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First(v => v.StringRepresentation == "X"); 148 156 TerminalSymbol ySymbol = alg.Grammar.VarTerminals.First(v => v.StringRepresentation == "Y"); 157 TerminalSymbol constSymbol = alg.Grammar.Const; 149 158 TerminalSymbol mulSymbol = alg.Grammar.Multiplication; 150 159 TerminalSymbol addSymbol = alg.Grammar.Addition; 151 160 TerminalSymbol sinSymbol = alg.Grammar.Sin; 152 161 162 // c*sin(c*x + c) + c*sin(c*y*y + c) + c 153 163 SymbolString targetSolution = new SymbolString(new[] { 154 xSymbol, sinSymbol, 155 ySymbol, ySymbol, mulSymbol, sinSymbol, addSymbol 164 xSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, 165 ySymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, addSymbol, 166 constSymbol, addSymbol 156 167 }); 157 168 … … 180 191 public void NoConstants_Inverse() { 181 192 // x / (log(x)*x + x) 182 alg.MaxTreeSize = 12;193 alg.MaxTreeSize = 23; 183 194 184 195 var x = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() + 1.1).ToList(); -
branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs
r15834 r15849 12 12 private TerminalSymbol varB; 13 13 private TerminalSymbol varC; 14 private TerminalSymbol c; 14 15 15 16 [TestInitialize] … … 20 21 varB = grammar.VarTerminals.First(s => s.StringRepresentation == "b"); 21 22 varC = grammar.VarTerminals.First(s => s.StringRepresentation == "c"); 23 c = grammar.Const; 22 24 } 23 25 … … 132 134 } 133 135 136 // Constants 137 [TestMethod] 138 [TestCategory("TreeHashing")] 139 public void SimpleConst() { 140 SymbolString s1 = new SymbolString(new Symbol[] { c, varA, grammar.Multiplication, c, grammar.Addition}); 141 SymbolString s2 = new SymbolString(new Symbol[] { c, varA, grammar.Multiplication, c, varA, grammar.Multiplication, grammar.Addition, c, grammar.Addition }); 142 143 int hash1 = grammar.Hasher.CalcHashCode(s1); 144 int hash2 = grammar.Hasher.CalcHashCode(s2); 145 146 Assert.AreEqual(hash1, hash2); 147 } 148 134 149 /* DEPRECATED; SINCE WE DO NOT ALLOW COMPOUND DIVISIONS 135 150 [TestMethod]
Note: See TracChangeset
for help on using the changeset viewer.