- Timestamp:
- 07/04/19 16:10:58 (5 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 16378-16379,16542
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16378-16379
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r17072 r17073 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 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r17071 r17073 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; 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.