Changeset 16654 for branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 03/07/19 12:29:27 (6 years ago)
- Location:
- branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/InterpreterState.cs
r15583 r16654 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/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r16375 r16654 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/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r16360 r16654 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 { … … 98 98 99 99 [StorableConstructor] 100 private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(bool deserializing) 101 : base(deserializing) { 100 private SymbolicDataAnalysisExpressionCompiledTreeInterpreter(StorableConstructorFlag _) : base(_) { 102 101 } 103 102 -
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r16531 r16654 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"; … … 37 37 } 38 38 39 40 39 [StorableConstructor] 41 protected SymbolicDataAnalysisExpressionTreeBatchInterpreter( bool deserializing) : base(deserializing) { }40 protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(StorableConstructorFlag _) : base(_) { } 42 41 protected SymbolicDataAnalysisExpressionTreeBatchInterpreter(SymbolicDataAnalysisExpressionTreeBatchInterpreter original, Cloner cloner) : base(original, cloner) { 43 42 } … … 178 177 } 179 178 179 private readonly object syncRoot = new object(); 180 180 181 [ThreadStatic] 181 182 private Dictionary<string, double[]> cachedData; 182 183 184 [ThreadStatic] 185 private IDataset dataset; 186 183 187 private void InitCache(IDataset dataset) { 188 this.dataset = dataset; 184 189 cachedData = new Dictionary<string, double[]>(); 185 190 foreach (var v in dataset.DoubleVariables) { … … 190 195 public void InitializeState() { 191 196 cachedData = null; 197 dataset = null; 192 198 EvaluatedSolutions = 0; 193 199 } 194 200 195 201 private double[] GetValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) { 202 if (cachedData == null || this.dataset != dataset) { 203 InitCache(dataset); 204 } 205 196 206 var code = Compile(tree, dataset, OpCodes.MapSymbolToOpCode); 197 207 var remainingRows = rows.Length % BATCHSIZE; 198 208 var roundedTotal = rows.Length - remainingRows; 199 209 200 // TODO: evaluated solutions are not counted201 202 210 var result = new double[rows.Length]; 203 211 … … 212 220 } 213 221 222 // when evaluation took place without any error, we can increment the counter 223 lock (syncRoot) { 224 EvaluatedSolutions++; 225 } 226 214 227 return result; 215 228 } 216 229 217 230 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) { 218 if (cachedData == null) {219 InitCache(dataset);220 }221 231 return GetValues(tree, dataset, rows); 222 232 } -
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r16360 r16654 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 { … … 104 104 105 105 [StorableConstructor] 106 private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter( bool deserializing) : base(deserializing) { }106 private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(StorableConstructorFlag _) : base(_) { } 107 107 108 108 private SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter original, Cloner cloner) : base(original, cloner) { } … … 425 425 Label c1 = il.DefineLabel(); 426 426 CompileInstructions(il, state, ds); 427 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0427 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 428 428 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 429 429 il.Emit(System.Reflection.Emit.OpCodes.Brfalse, c1); … … 440 440 CompileInstructions(il, state, ds); 441 441 for (int i = 1; i < nArgs; i++) { 442 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0442 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 443 443 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 444 444 il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch); 445 445 CompileInstructions(il, state, ds); 446 446 } 447 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0447 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 448 448 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 449 449 il.Emit(System.Reflection.Emit.OpCodes.Brfalse, falseBranch); … … 465 465 // complex definition because of special properties of NaN 466 466 il.Emit(System.Reflection.Emit.OpCodes.Dup); 467 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // <= 0467 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // <= 0 468 468 il.Emit(System.Reflection.Emit.OpCodes.Ble, nextArgBranch); 469 469 il.Emit(System.Reflection.Emit.OpCodes.Br, resultBranch); … … 473 473 } 474 474 il.MarkLabel(resultBranch); 475 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0475 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 476 476 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 477 477 il.Emit(System.Reflection.Emit.OpCodes.Brtrue, trueBranch); … … 486 486 case OpCodes.NOT: { 487 487 CompileInstructions(il, state, ds); 488 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0); // > 0488 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 489 489 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 490 490 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64 … … 498 498 case OpCodes.XOR: { 499 499 CompileInstructions(il, state, ds); 500 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0);500 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); 501 501 il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0 502 502 503 503 for (int i = 1; i < nArgs; i++) { 504 504 CompileInstructions(il, state, ds); 505 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4_0);505 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); 506 506 il.Emit(System.Reflection.Emit.OpCodes.Cgt);// > 0 507 507 il.Emit(System.Reflection.Emit.OpCodes.Xor); -
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r16375 r16654 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, -
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r16375 r16654 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 } -
branches/2866_SymRegHyperbolicFunctions/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r16277 r16654 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) { } 60 59 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(StorableConstructorFlag _) : base(_) { } 61 60 62 61 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(SymbolicDataAnalysisExpressionTreeNativeInterpreter original, Cloner cloner) : base(original, cloner) { … … 99 98 private static Dictionary<string, GCHandle> cachedData; 100 99 100 [ThreadStatic] 101 private IDataset dataset; 102 101 103 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 102 104 if (!rows.Any()) return Enumerable.Empty<double>(); 103 105 104 lock (syncRoot) { 105 EvaluatedSolutions++; // increment the evaluated solutions counter 106 } 107 108 if (cachedData == null) { 106 if (cachedData == null || this.dataset != dataset) { 109 107 InitCache(dataset); 110 108 } … … 116 114 117 115 NativeWrapper.GetValuesVectorized(code, code.Length, rowsArray, rowsArray.Length, result); 116 117 // when evaluation took place without any error, we can increment the counter 118 lock (syncRoot) { 119 EvaluatedSolutions++; 120 } 121 118 122 return result; 119 123 } 120 124 121 125 private void InitCache(IDataset dataset) { 126 this.dataset = dataset; 127 128 // free handles to old data 129 if (cachedData != null) { 130 foreach (var gch in cachedData.Values) { 131 gch.Free(); 132 } 133 cachedData = null; 134 } 135 136 // cache new data 122 137 cachedData = new Dictionary<string, GCHandle>(); 123 138 foreach (var v in dataset.DoubleVariables) { … … 135 150 cachedData = null; 136 151 } 152 dataset = null; 137 153 EvaluatedSolutions = 0; 138 154 }
Note: See TracChangeset
for help on using the changeset viewer.