Changeset 16238 for branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 10/18/18 15:29:59 (6 years ago)
- Location:
- branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r16237 r16238 87 87 public const byte Absolute = 48; 88 88 public const byte AnalyticalQuotient = 49; 89 public const byte Cube = 50; 90 public const byte CubeRoot = 51; 89 91 90 92 … … 138 140 { typeof(FactorVariable), OpCodes.FactorVariable }, 139 141 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable }, 140 { typeof(Absolute), OpCodes.Absolute }, 141 { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient } 142 { typeof(Absolute), OpCodes.Absolute }, 143 { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient }, 144 { typeof(Cube), OpCodes.Cube }, 145 { typeof(CubeRoot), OpCodes.CubeRoot } 142 146 }; 143 147 -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r15583 r16238 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: { -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r15583 r16238 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 } -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r15944 r16238 218 218 return Math.Pow(Evaluate(dataset, ref row, state), 2); 219 219 } 220 case OpCodes.Cube: { 221 return Math.Pow(Evaluate(dataset, ref row, state), 3); 222 } 220 223 case OpCodes.Power: { 221 224 double x = Evaluate(dataset, ref row, state); … … 226 229 return Math.Sqrt(Evaluate(dataset, ref row, state)); 227 230 } 231 case OpCodes.CubeRoot: { 232 return Math.Pow(Evaluate(dataset, ref row, state), 1.0 / 3.0); 233 } 228 234 case OpCodes.Root: { 229 235 double x = Evaluate(dataset, ref row, state); … … 343 349 if (double.IsNaN(x)) return double.NaN; 344 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); 345 357 } 346 358 case OpCodes.IfThenElse: { -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r16236 r16238 233 233 } else if (instr.opCode == OpCodes.Tan) { 234 234 instr.value = Math.Tan(code[instr.childIndex].value); 235 } else if 235 } else if(instr.opCode == OpCodes.Square) { 236 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); 237 239 } else if (instr.opCode == OpCodes.Power) { 238 240 double x = code[instr.childIndex].value; 239 241 double y = Math.Round(code[instr.childIndex + 1].value); 240 242 instr.value = Math.Pow(x, y); 241 } else if 243 } else if(instr.opCode == OpCodes.SquareRoot) { 242 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); 243 247 } else if (instr.opCode == OpCodes.Root) { 244 248 double x = code[instr.childIndex].value;
Note: See TracChangeset
for help on using the changeset viewer.