Changeset 16296
- Timestamp:
- 11/14/18 12:08:42 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r16293 r16296 154 154 } 155 155 156 [ThreadStatic] 157 private Dictionary<string, double[]> cachedData; 158 159 private void InitCache(IDataset dataset) { 160 cachedData = new Dictionary<string, double[]>(); 161 foreach (var v in dataset.DoubleVariables) { 162 var values = dataset.GetDoubleValues(v).ToArray(); 163 } 164 } 165 166 public void InitializeState() { 167 cachedData = null; 168 EvaluatedSolutions = 0; 169 } 170 156 171 private double[] GetValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) { 157 172 var code = Compile(tree, dataset, OpCodes.MapSymbolToOpCode); 158 159 173 var remainingRows = rows.Length % BATCHSIZE; 160 174 var roundedTotal = rows.Length - remainingRows; … … 176 190 177 191 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) { 192 if (cachedData == null) { 193 InitCache(dataset); 194 } 178 195 return GetValues(tree, dataset, rows); 179 196 } 180 197 181 198 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 182 return GetValues(tree, dataset, rows.ToArray()); 183 } 184 185 public void InitializeState() { 199 return GetSymbolicExpressionTreeValues(tree, dataset, rows.ToArray()); 186 200 } 187 201 … … 193 207 int c = 1, i = 0; 194 208 foreach (var node in root.IterateNodesBreadth()) { 195 for (int j = 0; j < node.SubtreeCount; ++j) { 196 var s = node.GetSubtree(j); 197 if (s.SubtreeCount > ushort.MaxValue) throw new ArgumentException("Number of subtrees is too big (>65.535)"); 198 code[c + j] = new BatchInstruction { narg = (ushort)s.SubtreeCount, opcode = opCodeMapper(s) }; 199 } 200 201 code[i].buf = new double[BATCHSIZE]; 202 209 if (node.SubtreeCount > ushort.MaxValue) throw new ArgumentException("Number of subtrees is too big (>65.535)"); 210 code[i] = new BatchInstruction { 211 opcode = opCodeMapper(node), 212 narg = (ushort)node.SubtreeCount, 213 buf = new double[BATCHSIZE], 214 childIndex = c 215 }; 203 216 if (node is VariableTreeNode variable) { 204 217 code[i].weight = variable.Weight; 205 code[i].data = dataset.GetReadOnlyDoubleValues(variable.VariableName).ToArray(); 218 if (cachedData.ContainsKey(variable.VariableName)) { 219 code[i].data = cachedData[variable.VariableName]; 220 } else { 221 code[i].data = dataset.GetReadOnlyDoubleValues(variable.VariableName).ToArray(); 222 cachedData[variable.VariableName] = code[i].data; 223 } 206 224 } else if (node is ConstantTreeNode constant) { 207 225 code[i].value = constant.Value; … … 209 227 code[i].buf[j] = code[i].value; 210 228 } 211 212 code[i].childIndex = c;213 229 c += node.SubtreeCount; 214 230 ++i;
Note: See TracChangeset
for help on using the changeset viewer.