Changeset 16378
- Timestamp:
- 12/13/18 14:39:56 (6 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r16360 r16378 36 36 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 37 37 } 38 39 38 40 39 [StorableConstructor] … … 175 174 } 176 175 176 private readonly object syncRoot = new object(); 177 177 178 [ThreadStatic] 178 179 private Dictionary<string, double[]> cachedData; 179 180 181 [ThreadStatic] 182 private IDataset dataset; 183 180 184 private void InitCache(IDataset dataset) { 185 this.dataset = dataset; 181 186 cachedData = new Dictionary<string, double[]>(); 182 187 foreach (var v in dataset.DoubleVariables) { … … 187 192 public void InitializeState() { 188 193 cachedData = null; 194 dataset = null; 189 195 EvaluatedSolutions = 0; 190 196 } 191 197 192 198 private double[] GetValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) { 199 if (cachedData == null || this.dataset != dataset) { 200 InitCache(dataset); 201 } 202 193 203 var code = Compile(tree, dataset, OpCodes.MapSymbolToOpCode); 194 204 var remainingRows = rows.Length % BATCHSIZE; 195 205 var roundedTotal = rows.Length - remainingRows; 196 206 197 // TODO: evaluated solutions are not counted198 199 207 var result = new double[rows.Length]; 200 208 … … 209 217 } 210 218 219 // when evaluation took place without any error, we can increment the counter 220 lock (syncRoot) { 221 EvaluatedSolutions++; 222 } 223 211 224 return result; 212 225 } 213 226 214 227 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) { 215 if (cachedData == null) {216 InitCache(dataset);217 }218 228 return GetValues(tree, dataset, rows); 219 229 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r16277 r16378 59 59 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(bool deserializing) : base(deserializing) { } 60 60 61 62 61 protected SymbolicDataAnalysisExpressionTreeNativeInterpreter(SymbolicDataAnalysisExpressionTreeNativeInterpreter original, Cloner cloner) : base(original, cloner) { 63 62 } … … 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; 122 127 cachedData = new Dictionary<string, GCHandle>(); 123 128 foreach (var v in dataset.DoubleVariables) { … … 135 140 cachedData = null; 136 141 } 142 dataset = null; 137 143 EvaluatedSolutions = 0; 138 144 }
Note: See TracChangeset
for help on using the changeset viewer.