Changeset 15404 for branches/MCTS-SymbReg-2796/Tests
- Timestamp:
- 10/05/17 10:03:32 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MCTS-SymbReg-2796/Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs
r15403 r15404 2 2 using System.Linq; 3 3 using System.Threading; 4 using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression;5 4 using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression.Policies; 6 5 using HeuristicLab.Data; … … 10 9 using Microsoft.VisualStudio.TestTools.UnitTesting; 11 10 12 namespace HeuristicLab.Algorithms.DataAnalysis {11 namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression { 13 12 [TestClass()] 14 13 public class MctsSymbolicRegressionTest { 14 #region expression hashing 15 [TestMethod] 16 [TestCategory("Algorithms.DataAnalysis")] 17 [TestProperty("Time", "short")] 18 public void ExprHashTest() { 19 int nParams; 20 byte[] code; 21 22 { 23 // addition of variables 24 var codeGen = new CodeGenerator(); 25 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 26 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 27 codeGen.Emit1(OpCodes.Add); 28 codeGen.Emit1(OpCodes.Exit); 29 codeGen.GetCode(out code, out nParams); 30 var h1 = ExprHash.GetHash(code, nParams); 31 32 codeGen = new CodeGenerator(); 33 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 34 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 35 codeGen.Emit1(OpCodes.Add); 36 codeGen.Emit1(OpCodes.Exit); 37 codeGen.GetCode(out code, out nParams); 38 var h2 = ExprHash.GetHash(code, nParams); 39 40 Assert.AreEqual(h1, h2); 41 } 42 43 { 44 // multiplication of variables 45 var codeGen = new CodeGenerator(); 46 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 47 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 48 codeGen.Emit1(OpCodes.Mul); 49 codeGen.Emit1(OpCodes.Exit); 50 codeGen.GetCode(out code, out nParams); 51 var h1 = ExprHash.GetHash(code, nParams); 52 53 codeGen = new CodeGenerator(); 54 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 55 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 56 codeGen.Emit1(OpCodes.Mul); 57 codeGen.Emit1(OpCodes.Exit); 58 codeGen.GetCode(out code, out nParams); 59 var h2 = ExprHash.GetHash(code, nParams); 60 61 Assert.AreEqual(h1, h2); 62 } 63 64 { 65 // distributivity 66 var codeGen = new CodeGenerator(); 67 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 68 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 69 codeGen.Emit1(OpCodes.Add); 70 codeGen.Emit2(OpCodes.LoadVar, 3); 71 codeGen.Emit1(OpCodes.Mul); 72 codeGen.Emit1(OpCodes.Exit); 73 codeGen.GetCode(out code, out nParams); 74 var h1 = ExprHash.GetHash(code, nParams); 75 76 codeGen = new CodeGenerator(); 77 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 78 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 3); 79 codeGen.Emit1(OpCodes.Mul); 80 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 81 codeGen.Emit2(OpCodes.LoadVar, 3); 82 codeGen.Emit1(OpCodes.Mul); 83 codeGen.Emit1(OpCodes.Add); 84 codeGen.Emit1(OpCodes.Exit); 85 codeGen.GetCode(out code, out nParams); 86 var h2 = ExprHash.GetHash(code, nParams); 87 88 Assert.AreEqual(h1, h2); 89 } 90 91 92 { 93 // div 94 var codeGen = new CodeGenerator(); 95 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 96 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 97 codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul); 98 codeGen.Emit1(OpCodes.Inv); 99 codeGen.Emit1(OpCodes.Exit); 100 codeGen.GetCode(out code, out nParams); 101 var h1 = ExprHash.GetHash(code, nParams); 102 103 codeGen = new CodeGenerator(); 104 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 105 codeGen.Emit1(OpCodes.Inv); 106 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 107 codeGen.Emit1(OpCodes.Inv); 108 codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul); 109 codeGen.Emit1(OpCodes.Exit); 110 codeGen.GetCode(out code, out nParams); 111 var h2 = ExprHash.GetHash(code, nParams); 112 113 Assert.AreEqual(h1, h2); 114 } 115 { 116 // exp 117 var codeGen = new CodeGenerator(); 118 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 119 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 120 codeGen.Emit1(MctsSymbolicRegression.OpCodes.Add); 121 codeGen.Emit1(OpCodes.Exp); 122 codeGen.Emit1(OpCodes.Exit); 123 codeGen.GetCode(out code, out nParams); 124 var h1 = ExprHash.GetHash(code, nParams); 125 126 codeGen = new CodeGenerator(); 127 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 128 codeGen.Emit1(OpCodes.Exp); 129 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 130 codeGen.Emit1(OpCodes.Exp); 131 codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul); 132 codeGen.GetCode(out code, out nParams); 133 codeGen.Emit1(OpCodes.Exit); 134 var h2 = ExprHash.GetHash(code, nParams); 135 136 Assert.AreEqual(h1, h2); 137 } 138 { 139 // log 140 var codeGen = new CodeGenerator(); 141 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 142 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 143 codeGen.Emit1(MctsSymbolicRegression.OpCodes.Mul); 144 codeGen.Emit1(OpCodes.Log); 145 codeGen.Emit1(OpCodes.Exit); 146 codeGen.GetCode(out code, out nParams); 147 var h1 = ExprHash.GetHash(code, nParams); 148 149 codeGen = new CodeGenerator(); 150 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 1); 151 codeGen.Emit1(OpCodes.Log); 152 codeGen.Emit2(MctsSymbolicRegression.OpCodes.LoadVar, 2); 153 codeGen.Emit1(OpCodes.Log); 154 codeGen.Emit1(MctsSymbolicRegression.OpCodes.Add); 155 codeGen.Emit1(OpCodes.Exit); 156 codeGen.GetCode(out code, out nParams); 157 var h2 = ExprHash.GetHash(code, nParams); 158 159 Assert.AreEqual(h1, h2); 160 } 161 } 162 #endregion 163 15 164 #region number of solutions 16 165 // the algorithm should visits each solution only once
Note: See TracChangeset
for help on using the changeset viewer.