- Timestamp:
- 06/16/21 21:15:16 (4 years ago)
- Location:
- branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/NativeInterpreter.cs
r17853 r17989 31 31 using HeuristicLab.Data; 32 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 33 using HeuristicLab.NativeInterpreter; 33 34 using HeuristicLab.Parameters; 34 35 using HeuristicLab.Problems.DataAnalysis; … … 173 174 174 175 var summary = new OptimizationSummary(); // also not used 175 NativeWrapper.GetValues(code, rows, result, null, options, refsummary);176 NativeWrapper.GetValues(code, rows, options, result, target: null, out summary); 176 177 177 178 // when evaluation took place without any error, we can increment the counter -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/ParameterOptimizer.cs
r17853 r17989 7 7 using HeuristicLab.Data; 8 8 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 9 using HeuristicLab.NativeInterpreter; 9 10 using HeuristicLab.Parameters; 10 11 … … 84 85 set { UseNonmonotonicStepsParameter.Value.Value = value; } 85 86 } 86 private intMinimizer {87 get { return Array.IndexOf(MinimizerType, MinimizerTypeParameter.Value.Value); }88 } 89 private intLinearSolver {90 get { return Array.IndexOf(LinerSolverType, LinearSolverTypeParameter.Value.Value); }91 } 92 private intTrustRegionStrategy {93 get { return Array.IndexOf(TrustRegionStrategyType, TrustRegionStrategyTypeParameter.Value.Value); }94 } 95 private intDogleg {96 get { return Array.IndexOf(DoglegType, DogLegTypeParameter.Value.Value); }97 } 98 private intLineSearchDirection {99 get { return Array.IndexOf(LinearSearchDirectionType, LineSearchDirectionTypeParameter.Value.Value); }87 private CeresTypes.MinimizerType Minimizer { 88 get { return (CeresTypes.MinimizerType)Enum.Parse(typeof(CeresTypes.MinimizerType), MinimizerTypeParameter.Value.Value); } 89 } 90 private CeresTypes.LinearSolverType LinearSolver { 91 get { return (CeresTypes.LinearSolverType)Enum.Parse(typeof(CeresTypes.LinearSolverType), LinearSolverTypeParameter.Value.Value); } 92 } 93 private CeresTypes.TrustRegionStrategyType TrustRegionStrategy { 94 get { return (CeresTypes.TrustRegionStrategyType)Enum.Parse(typeof(CeresTypes.TrustRegionStrategyType), TrustRegionStrategyTypeParameter.Value.Value); } 95 } 96 private CeresTypes.DoglegType Dogleg { 97 get { return (CeresTypes.DoglegType)Enum.Parse(typeof(CeresTypes.DoglegType), DogLegTypeParameter.Value.Value); } 98 } 99 private CeresTypes.LineSearchDirectionType LineSearchDirection { 100 get { return (CeresTypes.LineSearchDirectionType)Enum.Parse(typeof(CeresTypes.LineSearchDirectionType), LineSearchDirectionTypeParameter.Value.Value); } 100 101 } 101 102 #endregion … … 147 148 var result = new double[rowsArray.Length]; 148 149 149 NativeWrapper.GetValues(code, rowsArray, result, target, options, refsummary);150 NativeWrapper.GetValues(code, rowsArray, options, result, target, out summary); 150 151 } 151 152 return Enumerable.Range(0, code.Length).Where(i => nodes[i] is SymbolicExpressionTreeTerminalNode).ToDictionary(i => nodes[i], i => code[i].Value); … … 201 202 var codeArray = totalCode.ToArray(); 202 203 203 NativeWrapper.GetValuesVarPro(codeArray, termIndices, rowsArray, coeff, result, target, options, refsummary);204 NativeWrapper.GetValuesVarPro(codeArray, termIndices,rowsArray, coeff, options, result, target, out summary); 204 205 return Enumerable.Range(0, totalCodeSize).Where(i => codeArray[i].Optimize).ToDictionary(i => totalNodes[i], i => codeArray[i].Value); 205 206 } -
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.