Changeset 17989 for branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
- Timestamp:
- 06/16/21 21:15:16 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r17844 r17989 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.NativeInterpreter; 30 31 using HeuristicLab.Parameters; 31 32 using HEAL.Attic; … … 70 71 var code = new NativeInstruction[root.GetLength()]; 71 72 if (root.SubtreeCount > ushort.MaxValue) throw new ArgumentException("Number of subtrees is too big (>65.535)"); 72 code[0] = new NativeInstruction { narg = (ushort)root.SubtreeCount, opcode = opCodeMapper(root) }; 73 int c = 1, i = 0; 74 foreach (var node in root.IterateNodesBreadth()) { 75 for (int j = 0; j < node.SubtreeCount; ++j) { 76 var s = node.GetSubtree(j); 77 if (s.SubtreeCount > ushort.MaxValue) throw new ArgumentException("Number of subtrees is too big (>65.535)"); 78 code[c + j] = new NativeInstruction { narg = (ushort)s.SubtreeCount, opcode = opCodeMapper(s) }; 73 int i = code.Length - 1; 74 foreach (var n in root.IterateNodesPrefix()) { 75 code[i] = new NativeInstruction { Arity = (ushort)n.SubtreeCount, OpCode = opCodeMapper(n), Length = 1, Optimize = false }; 76 if (n is VariableTreeNode variable) { 77 code[i].Value = variable.Weight; 78 code[i].Data = cachedData[variable.VariableName].AddrOfPinnedObject(); 79 } else if (n is ConstantTreeNode constant) { 80 code[i].Value = constant.Value; 79 81 } 82 --i; 83 } 84 // second pass to calculate lengths 85 for (i = 0; i < code.Length; i++) { 86 var c = i - 1; 87 for (int j = 0; j < code[i].Arity; ++j) { 88 code[i].Length += code[c].Length; 89 c -= code[c].Length; 90 } 91 } 80 92 81 if (node is VariableTreeNode variable) {82 code[i].weight = variable.Weight;83 code[i].data = cachedData[variable.VariableName].AddrOfPinnedObject();84 } else if (node is ConstantTreeNode constant) {85 code[i].value = constant.Value;86 }87 88 code[i].childIndex = c;89 c += node.SubtreeCount;90 ++i;91 }92 93 return code; 93 94 } … … 114 115 (byte)OpCode.Tan, 115 116 (byte)OpCode.Tanh, 116 (byte)OpCode.Power,117 (byte)OpCode.Root,117 // (byte)OpCode.Power, 118 // (byte)OpCode.Root, 118 119 (byte)OpCode.SquareRoot, 119 120 (byte)OpCode.Square, … … 131 132 } 132 133 133 byte mapSupportedSymbols(ISymbolicExpressionTreeNode node) { 134 byte mapSupportedSymbols(ISymbolicExpressionTreeNode node) { 134 135 var opCode = OpCodes.MapSymbolToOpCode(node); 135 136 if (supportedOpCodes.Contains(opCode)) return opCode; … … 140 141 var rowsArray = rows.ToArray(); 141 142 var result = new double[rowsArray.Length]; 142 143 NativeWrapper.GetValuesVectorized(code, code.Length, rowsArray, rowsArray.Length, result); 143 // prevent optimization of parameters 144 var options = new SolverOptions { 145 Iterations = 0 146 }; 147 NativeWrapper.GetValues(code, rowsArray, options, result, target: null, optSummary: out var optSummary); // target is only used when optimizing parameters 144 148 145 149 // when evaluation took place without any error, we can increment the counter
Note: See TracChangeset
for help on using the changeset viewer.