Changeset 16676 for branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 03/13/19 09:30:18 (6 years ago)
- Location:
- branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/BatchOperations.cs
r16356 r16676 69 69 a[i] = Math.Tan(b[i]); 70 70 } 71 public static void Tanh(double[] a, double[] b) { 72 for (int i = 0; i < BATCHSIZE; ++i) 73 a[i] = Math.Tanh(b[i]); 74 } 71 75 72 76 public static void Pow(double[] a, double[] b) { -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/InterpreterState.cs
r15583 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16407 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;29 using HEAL.Attic; 30 30 using HeuristicLab.Parameters; 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 33 [Storable Class]33 [StorableType("DE6C1E1E-D7C1-4070-847E-63B68562B10C")] 34 34 [Item("IntervalInterpreter", "Intperter for calculation of intervals of symbolic models.")] 35 35 public sealed class IntervalInterpreter : ParameterizedNamedItem, IStatefulItem { … … 47 47 48 48 [StorableConstructor] 49 private IntervalInterpreter( bool deserializing) : base(deserializing) { }49 private IntervalInterpreter(StorableConstructorFlag _) : base(_) { } 50 50 private IntervalInterpreter(IntervalInterpreter original, Cloner cloner) 51 51 : base(original, cloner) { } … … 88 88 var outputInterval = Evaluate(instructions, ref instructionCount); 89 89 90 return outputInterval; 90 // because of numerical errors the bounds might be incorrect 91 if (outputInterval.LowerBound <= outputInterval.UpperBound) 92 return outputInterval; 93 else 94 return new Interval(outputInterval.UpperBound, outputInterval.LowerBound); 91 95 } 92 96 … … 102 106 var outputInterval = Evaluate(instructions, ref instructionCount, intervals); 103 107 104 nodeIntervals = intervals; 105 106 return outputInterval; 108 // fix incorrect intervals if necessary (could occur because of numerical errors) 109 nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 110 foreach(var kvp in intervals) { 111 var interval = kvp.Value; 112 if (interval.IsInfiniteOrUndefined || interval.LowerBound <= interval.UpperBound) 113 nodeIntervals.Add(kvp.Key, interval); 114 else 115 nodeIntervals.Add(kvp.Key, new Interval(interval.UpperBound, interval.LowerBound)); 116 } 117 118 // because of numerical errors the bounds might be incorrect 119 if (outputInterval.IsInfiniteOrUndefined || outputInterval.LowerBound <= outputInterval.UpperBound) 120 return outputInterval; 121 else 122 return new Interval(outputInterval.UpperBound, outputInterval.LowerBound); 107 123 } 108 124 -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r16360 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 90 90 public const byte CubeRoot = 51; 91 91 92 public const byte Tanh = 52; 93 92 94 93 95 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { … … 99 101 { typeof(Cosine), OpCodes.Cos }, 100 102 { typeof(Tangent), OpCodes.Tan }, 103 { typeof (HyperbolicTangent), OpCodes.Tanh}, 101 104 { typeof(Logarithm), OpCodes.Log }, 102 105 { typeof(Exponential), OpCodes.Exp }, -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r16360 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 31 using HeuristicLab.Parameters; 32 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;32 using HEAL.Attic; 33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 35 [Storable Class]35 [StorableType("DFA06F28-E224-4D93-9907-69792D24D1F9")] 36 36 [Item("SymbolicDataAnalysisExpressionCompiledTreeInterpreter", "Interpreter that converts the tree into a Linq.Expression then compiles it.")] 37 37 public sealed class SymbolicDataAnalysisExpressionCompiledTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { … … 45 45 private static readonly MethodInfo Cos = typeof(Math).GetMethod("Cos", new[] { typeof(double) }); 46 46 private static readonly MethodInfo Tan = typeof(Math).GetMethod("Tan", new[] { typeof(double) }); 47 private static readonly MethodInfo Tanh = typeof(Math).GetMethod("Tanh", new[] { typeof(double) }); 47 48 private static readonly MethodInfo Sqrt = typeof(Math).GetMethod("Sqrt", new[] { typeof(double) }); 48 49 private static readonly MethodInfo Floor = typeof(Math).GetMethod("Floor", new[] { typeof(double) }); … … 98 99 99 100 [StorableConstructor] 100 private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(bool deserializing) 101 : base(deserializing) { 101 private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(StorableConstructorFlag _) : base(_) { 102 102 } 103 103 … … 223 223 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 224 224 return Expression.Call(Tan, arg); 225 } 226 case OpCodes.Tanh: { 227 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 228 return Expression.Call(Tanh, arg); 225 229 } 226 230 case OpCodes.Square: { -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r16378 r16676 8 8 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 9 9 using HeuristicLab.Parameters; 10 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;10 using HEAL.Attic; 11 11 12 12 using static HeuristicLab.Problems.DataAnalysis.Symbolic.BatchOperations; … … 14 14 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 15 15 [Item("SymbolicDataAnalysisExpressionTreeBatchInterpreter", "An interpreter that uses batching and vectorization techniques to achieve faster performance.")] 16 [Storable Class]16 [StorableType("BEB15146-BB95-4838-83AC-6838543F017B")] 17 17 public class SymbolicDataAnalysisExpressionTreeBatchInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { 18 18 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; … … 38 38 39 39 [StorableConstructor] 40 protected SymbolicDataAnalysisExpressionTreeBatchInterpreter( bool deserializing) : base(deserializing) { }40 protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(StorableConstructorFlag _) : base(_) { } 41 41 protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(SymbolicDataAnalysisExpressionTreeBatchInterpreter original, Cloner cloner) : base(original, cloner) { 42 42 } … … 159 159 break; 160 160 } 161 161 case OpCodes.Tanh: { 162 Tanh(instr.buf, code[c].buf); 163 break; 164 } 162 165 case OpCodes.Absolute: { 163 166 Absolute(instr.buf, code[c].buf); -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r16360 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 31 using HeuristicLab.Parameters; 32 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;32 using HEAL.Attic; 33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 35 [Storable Class]35 [StorableType("426718E3-2A57-4CA4-98A1-65EDD0B0BDBF")] 36 36 [Item("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.")] 37 37 public sealed class SymbolicDataAnalysisExpressionTreeILEmittingInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { … … 45 45 private static MethodInfo sin = typeof(Math).GetMethod("Sin", new Type[] { typeof(double) }); 46 46 private static MethodInfo tan = typeof(Math).GetMethod("Tan", new Type[] { typeof(double) }); 47 private static MethodInfo tanh = typeof(Math).GetMethod("Tanh", new Type[] { typeof(double) }); 47 48 private static MethodInfo exp = typeof(Math).GetMethod("Exp", new Type[] { typeof(double) }); 48 49 private static MethodInfo log = typeof(Math).GetMethod("Log", new Type[] { typeof(double) }); … … 104 105 105 106 [StorableConstructor] 106 private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter( bool deserializing) : base(deserializing) { }107 private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(StorableConstructorFlag _) : base(_) { } 107 108 108 109 private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter original, Cloner cloner) : base(original, cloner) { } … … 285 286 return; 286 287 } 288 case OpCodes.Tanh: { 289 CompileInstructions(il, state, ds); 290 il.Emit(System.Reflection.Emit.OpCodes.Call, tanh); 291 return; 292 } 287 293 case OpCodes.Power: { 288 294 CompileInstructions(il, state, ds); … … 425 431 Label c1 = il.DefineLabel(); 426 432 CompileInstructions(il, state, ds); 427 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0433 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 428 434 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 429 435 il.Emit(System.Reflection.Emit.OpCodes.Brfalse, c1); … … 440 446 CompileInstructions(il, state, ds); 441 447 for (int i = 1; i < nArgs; i++) { 442 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0448 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 443 449 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 444 450 il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch); 445 451 CompileInstructions(il, state, ds); 446 452 } 447 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0453 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 448 454 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 449 455 il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch); … … 465 471 // complex definition because of special properties of NaN 466 472 il.Emit(System.Reflection.Emit.OpCodes.Dup); 467 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // <= 0473 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // <= 0 468 474 il.Emit(System.Reflection.Emit.OpCodes.Ble, nextArgBranch); 469 475 il.Emit(System.Reflection.Emit.OpCodes.Br, resultBranch); … … 473 479 } 474 480 il.MarkLabel(resultBranch); 475 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0481 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 476 482 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 477 483 il.Emit(System.Reflection.Emit.OpCodes.Brtrue, trueBranch); … … 486 492 case OpCodes.NOT: { 487 493 CompileInstructions(il, state, ds); 488 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0494 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 489 495 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 490 496 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64 … … 498 504 case OpCodes.XOR: { 499 505 CompileInstructions(il, state, ds); 500 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0);506 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); 501 507 il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0 502 508 503 509 for (int i = 1; i < nArgs; i++) { 504 510 CompileInstructions(il, state, ds); 505 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0);511 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); 506 512 il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0 507 513 il.Emit(System.Reflection.Emit.OpCodes.Xor); -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r16360 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 28 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 28 using HeuristicLab.Parameters; 30 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;29 using HEAL.Attic; 31 30 32 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 33 [Storable Class]32 [StorableType("FB94F333-B32A-44FB-A561-CBDE76693D20")] 34 33 [Item("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.")] 35 34 public class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, … … 70 69 71 70 [StorableConstructor] 72 protected SymbolicDataAnalysisExpressionTreeInterpreter( bool deserializing) : base(deserializing) { }71 protected SymbolicDataAnalysisExpressionTreeInterpreter(StorableConstructorFlag _) : base(_) { } 73 72 74 73 protected SymbolicDataAnalysisExpressionTreeInterpreter(SymbolicDataAnalysisExpressionTreeInterpreter original, … … 206 205 return Math.Abs(Evaluate(dataset, ref row, state)); 207 206 } 207 case OpCodes.Tanh: { 208 return Math.Tanh(Evaluate(dataset, ref row, state)); 209 } 208 210 case OpCodes.Cos: { 209 211 return Math.Cos(Evaluate(dataset, ref row, state)); -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r16360 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 29 using HeuristicLab.Parameters; 30 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;30 using HEAL.Attic; 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 33 [Storable Class]33 [StorableType("EF325166-E03A-44C4-83CE-7F07B836285E")] 34 34 [Item("SymbolicDataAnalysisExpressionTreeLinearInterpreter", "Fast linear (non-recursive) interpreter for symbolic expression trees. Does not support ADFs.")] 35 35 public sealed class SymbolicDataAnalysisExpressionTreeLinearInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { … … 70 70 71 71 [StorableConstructor] 72 private SymbolicDataAnalysisExpressionTreeLinearInterpreter(bool deserializing) 73 : base(deserializing) { 72 private SymbolicDataAnalysisExpressionTreeLinearInterpreter(StorableConstructorFlag _) : base(_) { 74 73 interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 75 74 } … … 227 226 } else if (instr.opCode == OpCodes.Absolute) { 228 227 instr.value = Math.Abs(code[instr.childIndex].value); 228 } else if (instr.opCode == OpCodes.Tanh) { 229 instr.value = Math.Tanh(code[instr.childIndex].value); 229 230 } else if (instr.opCode == OpCodes.Cos) { 230 231 instr.value = Math.Cos(code[instr.childIndex].value); -
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r16379 r16676 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 30 using HeuristicLab.Parameters; 31 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;31 using HEAL.Attic; 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 34 [Storable Class]34 [StorableType("91723319-8F15-4D33-B277-40AC7C7CF9AE")] 35 35 [Item("SymbolicDataAnalysisExpressionTreeNativeInterpreter", "An interpreter that wraps a native dll")] 36 36 public class SymbolicDataAnalysisExpressionTreeNativeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter { … … 57 57 58 58 [StorableConstructor] 59 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter( bool deserializing) : base(deserializing) { }59 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(StorableConstructorFlag _) : base(_) { } 60 60 61 61 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(SymbolicDataAnalysisExpressionTreeNativeInterpreter original, Cloner cloner) : base(original, cloner) {
Note: See TracChangeset
for help on using the changeset viewer.