- Timestamp:
- 12/08/18 08:11:48 (6 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/2915-AbsoluteSymbol (added) merged: 15943-15944,16236-16240,16304,16306,16332,16344-16352,16355 /branches/2937_SymReg_AnalyticalQuotient (added) merged: 16083
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/BatchOperations.cs
r16293 r16356 89 89 a[i] = Math.Sqrt(b[i]); 90 90 } 91 92 public static void Cube(double[] a, double[] b) { 93 for (int i = 0; i < BATCHSIZE; ++i) 94 a[i] = Math.Pow(b[i], 3d); 95 } 96 97 public static void CubeRoot(double[] a, double[] b) { 98 for (int i = 0; i < BATCHSIZE; ++i) 99 a[i] = Math.Pow(b[i], 1d / 3d); 100 } 101 102 public static void Absolute(double[] a, double[] b) { 103 for (int i = 0; i < BATCHSIZE; ++i) 104 a[i] = Math.Abs(b[i]); 105 } 106 107 public static void AnalyticQuotient(double[] a, double[] b) { 108 for (int i = 0; i < BATCHSIZE; ++i) 109 a[i] = a[i] / Math.Sqrt(1d + b[i] * b[i]); 110 } 91 111 } 92 112 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r15583 r16356 46 46 public const byte OR = 14; 47 47 public const byte NOT = 15; 48 public const byte XOR = 45;49 48 50 49 … … 83 82 public const byte Erf = 43; 84 83 public const byte Bessel = 44; 84 public const byte XOR = 45; 85 85 public const byte FactorVariable = 46; 86 86 public const byte BinaryFactorVariable = 47; 87 public const byte Absolute = 48; 88 public const byte AnalyticalQuotient = 49; 89 public const byte Cube = 50; 90 public const byte CubeRoot = 51; 87 91 88 92 … … 113 117 { typeof(Power),OpCodes.Power}, 114 118 { typeof(Root),OpCodes.Root}, 115 { typeof(TimeLag), OpCodes.TimeLag}, 119 { typeof(TimeLag), OpCodes.TimeLag}, 116 120 { typeof(Integral), OpCodes.Integral}, 117 121 { typeof(Derivative), OpCodes.Derivative}, … … 135 139 { typeof(Bessel), OpCodes.Bessel}, 136 140 { typeof(FactorVariable), OpCodes.FactorVariable }, 137 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable } 141 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable }, 142 { typeof(Absolute), OpCodes.Absolute }, 143 { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient }, 144 { typeof(Cube), OpCodes.Cube }, 145 { typeof(CubeRoot), OpCodes.CubeRoot } 138 146 }; 139 147 -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r15583 r16356 41 41 42 42 #region method info for the commonly called functions 43 private static readonly MethodInfo Abs = typeof(Math).GetMethod("Abs", new[] { typeof(double) }); 43 44 private static readonly MethodInfo Sin = typeof(Math).GetMethod("Sin", new[] { typeof(double) }); 44 45 private static readonly MethodInfo Cos = typeof(Math).GetMethod("Cos", new[] { typeof(double) }); … … 207 208 return Expression.Divide(result, Expression.Constant((double)node.SubtreeCount)); 208 209 } 210 case OpCodes.Absolute: { 211 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 212 return Expression.Call(Abs, arg); 213 } 209 214 case OpCodes.Cos: { 210 215 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); … … 222 227 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 223 228 return Expression.Power(arg, Expression.Constant(2.0)); 229 } 230 case OpCodes.Cube: { 231 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 232 return Expression.Power(arg, Expression.Constant(3.0)); 224 233 } 225 234 case OpCodes.Power: { … … 231 240 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 232 241 return Expression.Call(Sqrt, arg); 242 } 243 case OpCodes.CubeRoot: { 244 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 245 return Expression.Power(arg, Expression.Constant(1.0 / 3.0)); 233 246 } 234 247 case OpCodes.Root: { … … 493 506 Expression.Assign(result, Expression.Call(Bessel, arg))), 494 507 result); 508 } 509 case OpCodes.AnalyticalQuotient: { 510 var x1 = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 511 var x2 = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); 512 return Expression.Divide(x1, 513 Expression.Call(Sqrt, 514 Expression.Add( 515 Expression.Constant(1.0), 516 Expression.Multiply(x2, x2)))); 495 517 } 496 518 case OpCodes.IfThenElse: { -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r16301 r16356 111 111 112 112 case OpCodes.Root: { 113 Root(instr.buf, code[c].buf); 113 Load(instr.buf, code[c].buf); 114 Root(instr.buf, code[c + 1].buf); 114 115 break; 115 116 } … … 120 121 } 121 122 123 case OpCodes.Cube: { 124 Cube(instr.buf, code[c].buf); 125 break; 126 } 127 case OpCodes.CubeRoot: { 128 CubeRoot(instr.buf, code[c].buf); 129 break; 130 } 131 122 132 case OpCodes.Power: { 123 Pow(instr.buf, code[c].buf); 133 Load(instr.buf, code[c].buf); 134 Pow(instr.buf, code[c + 1].buf); 124 135 break; 125 136 } … … 147 158 case OpCodes.Tan: { 148 159 Tan(instr.buf, code[c].buf); 160 break; 161 } 162 163 case OpCodes.Absolute: { 164 Absolute(instr.buf, code[c].buf); 165 break; 166 } 167 168 case OpCodes.AnalyticalQuotient: { 169 Load(instr.buf, code[c].buf); 170 AnalyticQuotient(instr.buf, code[c + 1].buf); 149 171 break; 150 172 } … … 172 194 var remainingRows = rows.Length % BATCHSIZE; 173 195 var roundedTotal = rows.Length - remainingRows; 196 197 // TODO: evaluated solutions are not counted 174 198 175 199 var result = new double[rows.Length]; -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r15583 r16356 50 50 private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) }); 51 51 private static MethodInfo sqrt = typeof(Math).GetMethod("Sqrt", new Type[] { typeof(double) }); 52 private static MethodInfo abs = typeof(Math).GetMethod("Abs", new Type[] { typeof(double) }); 52 53 53 54 private static MethodInfo airyA = thisType.GetMethod("AiryA", new Type[] { typeof(double) }); … … 264 265 return; 265 266 } 267 case OpCodes.Absolute: { 268 CompileInstructions(il, state, ds); 269 il.Emit(System.Reflection.Emit.OpCodes.Call, abs); 270 return; 271 } 266 272 case OpCodes.Cos: { 267 273 CompileInstructions(il, state, ds); … … 311 317 return; 312 318 } 319 case OpCodes.Cube: { 320 CompileInstructions(il, state, ds); 321 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 3.0); 322 il.Emit(System.Reflection.Emit.OpCodes.Call, power); 323 return; 324 } 313 325 case OpCodes.SquareRoot: { 314 326 CompileInstructions(il, state, ds); … … 316 328 return; 317 329 } 330 case OpCodes.CubeRoot: { 331 CompileInstructions(il, state, ds); 332 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0 / 3.0); 333 il.Emit(System.Reflection.Emit.OpCodes.Call, power); 334 return; 335 } 318 336 case OpCodes.AiryA: { 319 337 CompileInstructions(il, state, ds); … … 389 407 CompileInstructions(il, state, ds); 390 408 il.Emit(System.Reflection.Emit.OpCodes.Call, sinIntegral); 409 return; 410 } 411 case OpCodes.AnalyticalQuotient: { 412 CompileInstructions(il, state, ds); // x1 413 CompileInstructions(il, state, ds); // x2 414 415 il.Emit(System.Reflection.Emit.OpCodes.Dup); 416 il.Emit(System.Reflection.Emit.OpCodes.Mul); // x2*x2 417 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); 418 il.Emit(System.Reflection.Emit.OpCodes.Mul); // 1+x2*x2 419 il.Emit(System.Reflection.Emit.OpCodes.Call, sqrt); 420 il.Emit(System.Reflection.Emit.OpCodes.Div); 391 421 return; 392 422 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r15583 r16356 203 203 return sum / currentInstr.nArguments; 204 204 } 205 case OpCodes.Absolute: { 206 return Math.Abs(Evaluate(dataset, ref row, state)); 207 } 205 208 case OpCodes.Cos: { 206 209 return Math.Cos(Evaluate(dataset, ref row, state)); … … 214 217 case OpCodes.Square: { 215 218 return Math.Pow(Evaluate(dataset, ref row, state), 2); 219 } 220 case OpCodes.Cube: { 221 return Math.Pow(Evaluate(dataset, ref row, state), 3); 216 222 } 217 223 case OpCodes.Power: { … … 223 229 return Math.Sqrt(Evaluate(dataset, ref row, state)); 224 230 } 231 case OpCodes.CubeRoot: { 232 return Math.Pow(Evaluate(dataset, ref row, state), 1.0 / 3.0); 233 } 225 234 case OpCodes.Root: { 226 235 double x = Evaluate(dataset, ref row, state); … … 340 349 if (double.IsNaN(x)) return double.NaN; 341 350 else return alglib.besseli0(x); 351 } 352 353 case OpCodes.AnalyticalQuotient: { 354 var x1 = Evaluate(dataset, ref row, state); 355 var x2 = Evaluate(dataset, ref row, state); 356 return x1 / Math.Pow(1 + x2 * x2, 0.5); 342 357 } 343 358 case OpCodes.IfThenElse: { -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r15583 r16356 215 215 if (instr.nArguments == 1) p = 1.0 / p; 216 216 instr.value = p; 217 } else if (instr.opCode == OpCodes.AnalyticalQuotient) { 218 var x1 = code[instr.childIndex].value; 219 var x2 = code[instr.childIndex + 1].value; 220 instr.value = x1 / Math.Sqrt(1 + x2 * x2); 217 221 } else if (instr.opCode == OpCodes.Average) { 218 222 double s = code[instr.childIndex].value; … … 221 225 } 222 226 instr.value = s / instr.nArguments; 227 } else if (instr.opCode == OpCodes.Absolute) { 228 instr.value = Math.Abs(code[instr.childIndex].value); 223 229 } else if (instr.opCode == OpCodes.Cos) { 224 230 instr.value = Math.Cos(code[instr.childIndex].value); … … 229 235 } else if (instr.opCode == OpCodes.Square) { 230 236 instr.value = Math.Pow(code[instr.childIndex].value, 2); 237 } else if (instr.opCode == OpCodes.Cube) { 238 instr.value = Math.Pow(code[instr.childIndex].value, 3); 231 239 } else if (instr.opCode == OpCodes.Power) { 232 240 double x = code[instr.childIndex].value; … … 235 243 } else if (instr.opCode == OpCodes.SquareRoot) { 236 244 instr.value = Math.Sqrt(code[instr.childIndex].value); 245 } else if (instr.opCode == OpCodes.CubeRoot) { 246 instr.value = Math.Pow(code[instr.childIndex].value, 1.0 / 3.0); 237 247 } else if (instr.opCode == OpCodes.Root) { 238 248 double x = code[instr.childIndex].value;
Note: See TracChangeset
for help on using the changeset viewer.