- Timestamp:
- 05/06/19 14:20:06 (6 years ago)
- Location:
- branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16737,16740,16758,16762,16764,16768,16802,16822,16839,16858,16868
- Property svn:mergeinfo changed
-
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/ModelClustersFrequencyAnalyzer.cs
r16734 r16899 43 43 44 44 #region parameter properties 45 [Storable] 45 46 public ILookupParameter<DataTable> ModelClustersFrequencyParameter { 46 47 get { return (ILookupParameter<DataTable>)Parameters[ModelClustersFrequencyParameterName]; } 47 48 } 49 [Storable] 48 50 public IValueLookupParameter<BoolValue> AggregateModelClustersParameter { 49 51 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateModelClustersParameterName]; } … … 54 56 get { return AggregateModelClustersParameter.ActualValue; } 55 57 set { AggregateModelClustersParameter.Value = value; } 58 } 59 public DataTable ModelClustersFrequency { 60 get { return ModelClustersFrequencyParameter.ActualValue; } 61 set { ModelClustersFrequencyParameter.ActualValue = value; } 56 62 } 57 63 #endregion -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/ModelsFrequencyAnalyzer.cs
r16734 r16899 43 43 44 44 #region parameter properties 45 [Storable] 45 46 public ILookupParameter<DataTable> ModelFrequencyParameter { 46 47 get { return (ILookupParameter<DataTable>)Parameters[ModelsFrequencyParameterName]; } 47 48 } 49 [Storable] 48 50 public IValueLookupParameter<BoolValue> AggregateModelParameter { 49 51 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateModelParameterName]; } … … 54 56 get { return AggregateModelParameter.ActualValue; } 55 57 set { AggregateModelParameter.Value = value; } 58 } 59 public DataTable ModelFrequency { 60 get { return ModelFrequencyParameter.ActualValue; } 61 set { ModelFrequencyParameter.ActualValue = value; } 56 62 } 57 63 #endregion -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/TerminalNodesFrequencyAnalyzer.cs
r16760 r16899 43 43 44 44 #region parameter properties 45 [Storable] 45 46 public ILookupParameter<DataTable> TerminalNodesFrequencyParameter { 46 47 get { return (ILookupParameter<DataTable>)Parameters[TerminalNodesFrequencyParameterName]; } 47 48 } 49 [Storable] 48 50 public IValueLookupParameter<BoolValue> AggregateTerminalNodesParameter { 49 51 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateTerminalNodesParameterName]; } … … 55 57 set { AggregateTerminalNodesParameter.Value = value; } 56 58 } 59 public DataTable TerminalNodesFrequency { 60 get { return TerminalNodesFrequencyParameter.ActualValue; } 61 set { TerminalNodesFrequencyParameter.ActualValue = value; } 62 } 63 57 64 #endregion 58 65 [StorableConstructor] -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs
r16565 r16899 83 83 if (branch.SubtreeCount >= 2) { 84 84 var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone(); 85 var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(1).Clone();86 85 var fprime = Derive(f, variableName); 87 var gprime = Derive(g, variableName); 88 var fgPrime = Sum(Product(f, gprime), Product(fprime, g)); 89 for (int i = 2; i < branch.SubtreeCount; i++) { 86 for (int i = 1; i < branch.SubtreeCount; i++) { 87 var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(i).Clone(); 90 88 var fg = Product((ISymbolicExpressionTreeNode)f.Clone(), (ISymbolicExpressionTreeNode)g.Clone()); 91 var h = (ISymbolicExpressionTreeNode)branch.GetSubtree(i).Clone(); 92 var hPrime = Derive(h, variableName); 93 fgPrime = Sum(Product(fgPrime, h), Product(fg, hPrime)); 89 var gPrime = Derive(g, variableName); 90 var fgPrime = Sum(Product(fprime, g), Product(gPrime, f)); 91 // prepare for next iteration 92 f = fg; 93 fprime = fgPrime; 94 94 } 95 return f gPrime;95 return fprime; 96 96 } else 97 97 // multiplication with only one argument has no effect -> derive the argument -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs
r16565 r16899 38 38 double @const = 0) { 39 39 40 if (factorCoefficients.Length == 0 && coefficients.Length == 0) throw new ArgumentException(); 40 if (factorCoefficients.Length == 0 && coefficients.Length == 0 && @const==0) throw new ArgumentException(); 41 42 // Combine both trees 43 ISymbolicExpressionTreeNode add = (new Addition()).CreateTreeNode(); 41 44 42 45 // Create tree for double variables 43 ISymbolicExpressionTree tree = null;44 46 if (coefficients.Length > 0) { 45 tree = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const); 46 if (factorCoefficients.Length == 0) return tree; 47 var varTree = CreateTree(variableNames, new int[variableNames.Length], coefficients); 48 foreach (var varNode in varTree.IterateNodesPrefix().OfType<VariableTreeNode>()) 49 add.AddSubtree(varNode); 47 50 } 48 51 49 52 // Create tree for string variables 50 ISymbolicExpressionTree factorTree = null;51 53 if (factorCoefficients.Length > 0) { 52 factorTree = CreateTree(factors, factorCoefficients, @const); 53 if (tree == null) return factorTree; 54 var factorTree = CreateTree(factors, factorCoefficients); 55 foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>()) 56 add.AddSubtree(binFactorNode); 54 57 } 55 58 56 // Combine both trees 57 ISymbolicExpressionTreeNode add = tree.Root.GetSubtree(0).GetSubtree(0); 58 foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>()) 59 add.InsertSubtree(add.SubtreeCount - 1, binFactorNode); 59 if (@const!=0.0) { 60 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode(); 61 cNode.Value = @const; 62 add.AddSubtree(cNode); 63 } 64 65 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 66 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 67 tree.Root.AddSubtree(startNode); 68 startNode.AddSubtree(add); 60 69 return tree; 61 62 throw new ArgumentException();63 70 } 64 71 -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs
r16722 r16899 137 137 } else if (node.Symbol is SquareRoot) { 138 138 FormatFunction(node, "Math.Sqrt", strBuilder); 139 } else if (node.Symbol is Cube) { 140 FormatPower(node, strBuilder, "3"); 141 } else if (node.Symbol is CubeRoot) { 142 FormatPower(node, strBuilder, "1.0/3"); 139 143 } else if (node.Symbol is Power) { 140 144 FormatFunction(node, "Math.Pow", strBuilder); 141 145 } else if (node.Symbol is Root) { 142 146 FormatRoot(node, strBuilder); 147 } else if (node.Symbol is Absolute) { 148 FormatFunction(node, "Math.Abs", strBuilder); 149 } else if (node.Symbol is AnalyticQuotient) { 150 strBuilder.Append("("); 151 FormatRecursively(node.GetSubtree(0), strBuilder); 152 strBuilder.Append(" / Math.Sqrt(1 + Math.Pow("); 153 FormatRecursively(node.GetSubtree(1), strBuilder); 154 strBuilder.Append(" , 2) )"); 143 155 } else { 144 156 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter."); … … 173 185 174 186 private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 187 FormatPower(node, strBuilder, "2"); 188 } 189 private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) { 175 190 strBuilder.Append("Math.Pow("); 176 191 FormatRecursively(node.GetSubtree(0), strBuilder); 177 strBuilder.Append( ", 2)");192 strBuilder.Append($", {exponent})"); 178 193 } 179 194 -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r16722 r16899 119 119 } 120 120 stringBuilder.Append(")"); 121 } else if (symbol is Absolute) { 122 stringBuilder.Append($"ABS({FormatRecursively(node.GetSubtree(0))})"); 123 } else if (symbol is AnalyticQuotient) { 124 stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) / SQRT(1 + POWER({FormatRecursively(node.GetSubtree(1))}, 2))"); 121 125 } else if (symbol is Average) { 122 stringBuilder.Append("(1/ ");126 stringBuilder.Append("(1/("); 123 127 stringBuilder.Append(node.SubtreeCount); 124 128 stringBuilder.Append(")*("); … … 129 133 stringBuilder.Append(")"); 130 134 } 131 stringBuilder.Append(") ");135 stringBuilder.Append("))"); 132 136 } else if (symbol is Constant) { 133 137 ConstantTreeNode constantTreeNode = node as ConstantTreeNode; … … 137 141 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 138 142 stringBuilder.Append(")"); 143 } else if (symbol is Cube) { 144 stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 3)"); 145 } else if (symbol is CubeRoot) { 146 stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 1/3)"); 139 147 } else if (symbol is Division) { 140 148 if (node.SubtreeCount == 1) { 141 stringBuilder.Append("1/"); 142 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 149 stringBuilder.Append("1/("); 150 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 151 stringBuilder.Append(")"); 143 152 } else { 144 153 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r16722 r16899 117 117 strBuilder.Append(@" \cfrac{ "); 118 118 } 119 } else if (node.Symbol is Absolute) { 120 strBuilder.Append(@"\operatorname{abs} \left( "); 121 } else if (node.Symbol is AnalyticQuotient) { 122 strBuilder.Append(@" \frac { "); 119 123 } else if (node.Symbol is Average) { 120 124 // skip output of (1/1) if only one subtree … … 131 135 } else if (node.Symbol is SquareRoot) { 132 136 strBuilder.Append(@"\sqrt{"); 137 } else if (node.Symbol is Cube) { 138 strBuilder.Append(@"\left("); 139 } else if (node.Symbol is CubeRoot) { 140 strBuilder.Append(@"\left("); 133 141 } else if (node.Symbol is Sine) { 134 142 strBuilder.Append(@"\sin \left( "); … … 289 297 else 290 298 strBuilder.Append(@" }{ \cfrac{ "); 299 } else if (node.Symbol is Absolute) { 300 throw new InvalidOperationException(); 301 } else if (node.Symbol is AnalyticQuotient) { 302 strBuilder.Append(@"}{\sqrt{1 + \left( "); 291 303 } else if (node.Symbol is Average) { 292 304 strBuilder.Append(@" + "); … … 298 310 throw new InvalidOperationException(); 299 311 } else if (node.Symbol is SquareRoot) { 312 throw new InvalidOperationException(); 313 } else if (node.Symbol is Cube) { 314 throw new InvalidOperationException(); 315 } else if (node.Symbol is CubeRoot) { 300 316 throw new InvalidOperationException(); 301 317 } else if (node.Symbol is Sine) { … … 387 403 for (int i = 2; i < node.SubtreeCount; i++) 388 404 strBuilder.Append(" } "); 405 } else if (node.Symbol is Absolute) { 406 strBuilder.Append(@" \right)"); 407 } else if (node.Symbol is AnalyticQuotient) { 408 strBuilder.Append(@" \right)^2}}"); 389 409 } else if (node.Symbol is Average) { 390 410 strBuilder.Append(@" \right) "); … … 397 417 } else if (node.Symbol is SquareRoot) { 398 418 strBuilder.Append(@"}"); 419 } else if (node.Symbol is Cube) { 420 strBuilder.Append(@"\right)^3"); 421 } else if (node.Symbol is CubeRoot) { 422 strBuilder.Append(@"\right)^\frac{1}{3}"); 399 423 } else if (node.Symbol is Sine) { 400 424 strBuilder.Append(@" \right) "); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
r16722 r16899 126 126 } 127 127 stringBuilder.Append(")"); 128 } else if (symbol is Absolute) { 129 stringBuilder.Append($"abs({FormatRecursively(node.GetSubtree(0))})"); 130 } else if (symbol is AnalyticQuotient) { 131 stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) / sqrt(1 + ({FormatRecursively(node.GetSubtree(1))}).^2)"); 128 132 } else if (symbol is And) { 129 133 stringBuilder.Append("(("); … … 179 183 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 180 184 stringBuilder.Append(")"); 185 } else if (symbol is Cube) { 186 stringBuilder.Append("("); 187 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 188 stringBuilder.Append(").^3"); 189 } else if (symbol is CubeRoot) { 190 stringBuilder.Append("("); 191 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 192 stringBuilder.Append(").^(1/3)"); 181 193 } else if (symbol is GreaterThan) { 182 194 stringBuilder.Append("(("); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs
r16722 r16899 56 56 if (node.Symbol is Addition) { 57 57 FormatFunction(node, "Plus", strBuilder); 58 } else if (node.Symbol is Absolute) { 59 FormatFunction(node, "Abs", strBuilder); 60 } else if (node.Symbol is AnalyticQuotient) { 61 strBuilder.Append("["); 62 FormatRecursively(node.GetSubtree(0), strBuilder); 63 strBuilder.Append("]/Sqrt[ 1 + Power["); 64 FormatRecursively(node.GetSubtree(1), strBuilder); 65 strBuilder.Append(", 2]]"); 58 66 } else if (node.Symbol is Average) { 59 67 FormatAverage(node, strBuilder); … … 104 112 } else if (node.Symbol is SquareRoot) { 105 113 FormatFunction(node, "Sqrt", strBuilder); 114 } else if (node.Symbol is Cube) { 115 FormatPower(node, strBuilder, "3"); 116 } else if (node.Symbol is CubeRoot) { 117 FormatPower(node, strBuilder, "1/3"); 106 118 } else if (node.Symbol is Power) { 107 119 FormatFunction(node, "Power", strBuilder); … … 205 217 206 218 private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 219 FormatPower(node, strBuilder, "2"); 220 } 221 222 private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) { 207 223 strBuilder.Append("Power["); 208 224 FormatRecursively(node.GetSubtree(0), strBuilder); 209 strBuilder.Append( ", 2]");225 strBuilder.Append($", {exponent}]"); 210 226 } 211 227 -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs
r16722 r16899 20 20 #endregion 21 21 22 using System; 22 23 using System.Globalization; 23 24 using System.Text; … … 69 70 } 70 71 stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]"); 72 } else if (symbol is Absolute) { 73 stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) abs"); 74 } else if (symbol is AnalyticQuotient) { 75 stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) / (1 + ({FormatPower(node.GetSubtree(1), "2")})) sqrt"); 71 76 } else if (symbol is Average) { 72 77 stringBuilder.Append("(1/"); … … 84 89 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 85 90 stringBuilder.Append(" cos"); 91 } else if (symbol is Cube) { 92 stringBuilder.Append(FormatPower(node.GetSubtree(0), "3")); 93 } else if (symbol is CubeRoot) { 94 stringBuilder.Append(FormatPower(node.GetSubtree(0), "(1/3)")); 86 95 } else if (symbol is Division) { 87 96 if (node.SubtreeCount == 1) { … … 146 155 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 147 156 stringBuilder.Append(" sin"); 157 } else if (symbol is Square) { 158 stringBuilder.Append(FormatPower(node.GetSubtree(0), "2")); 159 } else if (symbol is SquareRoot) { 160 stringBuilder.Append(FormatPower(node.GetSubtree(0), "(1/2)")); 148 161 } else if (symbol is Subtraction) { 149 162 if (node.SubtreeCount == 1) { … … 184 197 } 185 198 199 private string FormatPower(ISymbolicExpressionTreeNode node, string exponent) { 200 return $"(({FormatRecursively(node)}) log * {exponent}) exp "; 201 } 202 186 203 public override IDeepCloneable Clone(Cloner cloner) { 187 204 return new SymbolicDataAnalysisExpressionSmalltalkFormatter(this, cloner); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r16722 r16899 69 69 #endregion 70 70 71 public Interval GetSymbolicEx ressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {71 public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) { 72 72 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 73 return GetSymbolicEx ressionTreeInterval(tree, variableRanges);74 } 75 76 public Interval GetSymbolicEx ressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset,77 out Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) {73 return GetSymbolicExpressionTreeInterval(tree, variableRanges); 74 } 75 76 public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, 77 out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) { 78 78 var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows); 79 return GetSymbolicEx ressionTreeIntervals(tree, variableRanges, out nodeIntervals);80 } 81 82 public Interval GetSymbolicEx ressionTreeInterval(ISymbolicExpressionTree tree,Dictionary<string, Interval> variableRanges) {79 return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals); 80 } 81 82 public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) { 83 83 lock (syncRoot) { 84 84 EvaluatedSolutions++; … … 96 96 97 97 98 public Interval GetSymbolicEx ressionTreeIntervals(ISymbolicExpressionTree tree,99 Dictionary<string, Interval> variableRanges, outDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {98 public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, 99 IDictionary<string, Interval> variableRanges, out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) { 100 100 lock (syncRoot) { 101 101 EvaluatedSolutions++; … … 108 108 // fix incorrect intervals if necessary (could occur because of numerical errors) 109 109 nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 110 foreach (var kvp in intervals) {110 foreach (var kvp in intervals) { 111 111 var interval = kvp.Value; 112 112 if (interval.IsInfiniteOrUndefined || interval.LowerBound <= interval.UpperBound) … … 124 124 125 125 126 private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> variableRanges) {126 private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) { 127 127 if (variableRanges == null) 128 128 throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges)); … … 133 133 } 134 134 135 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode s.MapSymbolToOpCode);136 foreach (Instruction instr in code.Where(i => i.opCode == OpCode s.Variable)) {135 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode.MapSymbolToOpCode); 136 foreach (Instruction instr in code.Where(i => i.opCode == OpCode.Variable)) { 137 137 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 138 138 instr.data = variableRanges[variableTreeNode.VariableName]; … … 141 141 } 142 142 143 private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) {143 private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) { 144 144 Instruction currentInstr = instructions[instructionCounter]; 145 145 //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side … … 150 150 switch (currentInstr.opCode) { 151 151 //Variables, Constants, ... 152 case OpCode s.Variable: {152 case OpCode.Variable: { 153 153 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 154 154 var weightInterval = new Interval(variableTreeNode.Weight, variableTreeNode.Weight); … … 158 158 break; 159 159 } 160 case OpCode s.Constant: {160 case OpCode.Constant: { 161 161 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 162 162 result = new Interval(constTreeNode.Value, constTreeNode.Value); … … 164 164 } 165 165 //Elementary arithmetic rules 166 case OpCode s.Add: {166 case OpCode.Add: { 167 167 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 168 168 for (int i = 1; i < currentInstr.nArguments; i++) { … … 172 172 break; 173 173 } 174 case OpCode s.Sub: {174 case OpCode.Sub: { 175 175 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 176 176 if (currentInstr.nArguments == 1) … … 183 183 break; 184 184 } 185 case OpCode s.Mul: {185 case OpCode.Mul: { 186 186 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 187 187 for (int i = 1; i < currentInstr.nArguments; i++) { … … 191 191 break; 192 192 } 193 case OpCode s.Div: {193 case OpCode.Div: { 194 194 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 195 195 if (currentInstr.nArguments == 1) … … 203 203 } 204 204 //Trigonometric functions 205 case OpCode s.Sin: {205 case OpCode.Sin: { 206 206 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 207 207 result = Interval.Sine(argumentInterval); 208 208 break; 209 209 } 210 case OpCode s.Cos: {210 case OpCode.Cos: { 211 211 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 212 212 result = Interval.Cosine(argumentInterval); 213 213 break; 214 214 } 215 case OpCode s.Tan: {215 case OpCode.Tan: { 216 216 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 217 217 result = Interval.Tangens(argumentInterval); 218 218 break; 219 219 } 220 case OpCode.Tanh: { 221 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 222 result = Interval.HyperbolicTangent(argumentInterval); 223 break; 224 } 220 225 //Exponential functions 221 case OpCode s.Log: {226 case OpCode.Log: { 222 227 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 223 228 result = Interval.Logarithm(argumentInterval); 224 229 break; 225 230 } 226 case OpCode s.Exp: {231 case OpCode.Exp: { 227 232 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 228 233 result = Interval.Exponential(argumentInterval); 229 234 break; 230 235 } 231 case OpCode s.Power: {236 case OpCode.Power: { 232 237 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 233 238 for (int i = 1; i < currentInstr.nArguments; i++) { … … 237 242 break; 238 243 } 239 case OpCode s.Square: {244 case OpCode.Square: { 240 245 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 241 246 result = Interval.Square(argumentInterval); 242 247 break; 243 248 } 244 case OpCode s.Root: {249 case OpCode.Root: { 245 250 result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 246 251 for (int i = 1; i < currentInstr.nArguments; i++) { … … 250 255 break; 251 256 } 252 case OpCode s.SquareRoot: {257 case OpCode.SquareRoot: { 253 258 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 254 259 result = Interval.SquareRoot(argumentInterval); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r16722 r16899 20 20 #endregion 21 21 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 22 23 using System; 23 24 using System.Collections.Generic; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public static class OpCode s{27 public static class OpCode { 28 28 public const byte Add = 1; 29 29 public const byte Sub = 2; … … 95 95 96 96 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { 97 { typeof(Addition), OpCode s.Add },98 { typeof(Subtraction), OpCode s.Sub },99 { typeof(Multiplication), OpCode s.Mul },100 { typeof(Division), OpCode s.Div },101 { typeof(Sine), OpCode s.Sin },102 { typeof(Cosine), OpCode s.Cos },103 { typeof(Tangent), OpCode s.Tan },104 { typeof (HyperbolicTangent), OpCode s.Tanh},105 { typeof(Logarithm), OpCode s.Log },106 { typeof(Exponential), OpCode s.Exp },107 { typeof(IfThenElse), OpCode s.IfThenElse },108 { typeof(GreaterThan), OpCode s.GT },109 { typeof(LessThan), OpCode s.LT },110 { typeof(And), OpCode s.AND },111 { typeof(Or), OpCode s.OR },112 { typeof(Not), OpCode s.NOT},113 { typeof(Xor),OpCode s.XOR},114 { typeof(Average), OpCode s.Average},115 { typeof(InvokeFunction), OpCode s.Call },116 { typeof(Variable), OpCode s.Variable },117 { typeof(LaggedVariable), OpCode s.LagVariable },118 { typeof(AutoregressiveTargetVariable),OpCode s.LagVariable},119 { typeof(Constant), OpCode s.Constant },120 { typeof(TreeModel), OpCode s.TreeModel },121 { typeof(Argument), OpCode s.Arg },122 { typeof(Power),OpCode s.Power},123 { typeof(Root),OpCode s.Root},124 { typeof(TimeLag), OpCode s.TimeLag},125 { typeof(Integral), OpCode s.Integral},126 { typeof(Derivative), OpCode s.Derivative},127 { typeof(VariableCondition),OpCode s.VariableCondition},128 { typeof(Square),OpCode s.Square},129 { typeof(SquareRoot),OpCode s.SquareRoot},130 { typeof(Gamma), OpCode s.Gamma },131 { typeof(Psi), OpCode s.Psi },132 { typeof(Dawson), OpCode s.Dawson},133 { typeof(ExponentialIntegralEi), OpCode s.ExponentialIntegralEi },134 { typeof(CosineIntegral), OpCode s.CosineIntegral },135 { typeof(SineIntegral), OpCode s.SineIntegral },136 { typeof(HyperbolicCosineIntegral), OpCode s.HyperbolicCosineIntegral },137 { typeof(HyperbolicSineIntegral), OpCode s.HyperbolicSineIntegral },138 { typeof(FresnelCosineIntegral), OpCode s.FresnelCosineIntegral },139 { typeof(FresnelSineIntegral), OpCode s.FresnelSineIntegral },140 { typeof(AiryA), OpCode s.AiryA },141 { typeof(AiryB), OpCode s.AiryB },142 { typeof(Norm), OpCode s.Norm},143 { typeof(Erf), OpCode s.Erf},144 { typeof(Bessel), OpCode s.Bessel},145 { typeof(FactorVariable), OpCode s.FactorVariable },146 { typeof(BinaryFactorVariable), OpCode s.BinaryFactorVariable },147 { typeof(Absolute), OpCode s.Absolute },148 { typeof(AnalyticQuotient), OpCode s.AnalyticQuotient },149 { typeof(Cube), OpCode s.Cube },150 { typeof(CubeRoot), OpCode s.CubeRoot }97 { typeof(Addition), OpCode.Add }, 98 { typeof(Subtraction), OpCode.Sub }, 99 { typeof(Multiplication), OpCode.Mul }, 100 { typeof(Division), OpCode.Div }, 101 { typeof(Sine), OpCode.Sin }, 102 { typeof(Cosine), OpCode.Cos }, 103 { typeof(Tangent), OpCode.Tan }, 104 { typeof (HyperbolicTangent), OpCode.Tanh}, 105 { typeof(Logarithm), OpCode.Log }, 106 { typeof(Exponential), OpCode.Exp }, 107 { typeof(IfThenElse), OpCode.IfThenElse }, 108 { typeof(GreaterThan), OpCode.GT }, 109 { typeof(LessThan), OpCode.LT }, 110 { typeof(And), OpCode.AND }, 111 { typeof(Or), OpCode.OR }, 112 { typeof(Not), OpCode.NOT}, 113 { typeof(Xor),OpCode.XOR}, 114 { typeof(Average), OpCode.Average}, 115 { typeof(InvokeFunction), OpCode.Call }, 116 { typeof(Variable), OpCode.Variable }, 117 { typeof(LaggedVariable), OpCode.LagVariable }, 118 { typeof(AutoregressiveTargetVariable),OpCode.LagVariable}, 119 { typeof(Constant), OpCode.Constant }, 120 { typeof(TreeModel), OpCode.TreeModel }, 121 { typeof(Argument), OpCode.Arg }, 122 { typeof(Power),OpCode.Power}, 123 { typeof(Root),OpCode.Root}, 124 { typeof(TimeLag), OpCode.TimeLag}, 125 { typeof(Integral), OpCode.Integral}, 126 { typeof(Derivative), OpCode.Derivative}, 127 { typeof(VariableCondition),OpCode.VariableCondition}, 128 { typeof(Square),OpCode.Square}, 129 { typeof(SquareRoot),OpCode.SquareRoot}, 130 { typeof(Gamma), OpCode.Gamma }, 131 { typeof(Psi), OpCode.Psi }, 132 { typeof(Dawson), OpCode.Dawson}, 133 { typeof(ExponentialIntegralEi), OpCode.ExponentialIntegralEi }, 134 { typeof(CosineIntegral), OpCode.CosineIntegral }, 135 { typeof(SineIntegral), OpCode.SineIntegral }, 136 { typeof(HyperbolicCosineIntegral), OpCode.HyperbolicCosineIntegral }, 137 { typeof(HyperbolicSineIntegral), OpCode.HyperbolicSineIntegral }, 138 { typeof(FresnelCosineIntegral), OpCode.FresnelCosineIntegral }, 139 { typeof(FresnelSineIntegral), OpCode.FresnelSineIntegral }, 140 { typeof(AiryA), OpCode.AiryA }, 141 { typeof(AiryB), OpCode.AiryB }, 142 { typeof(Norm), OpCode.Norm}, 143 { typeof(Erf), OpCode.Erf}, 144 { typeof(Bessel), OpCode.Bessel}, 145 { typeof(FactorVariable), OpCode.FactorVariable }, 146 { typeof(BinaryFactorVariable), OpCode.BinaryFactorVariable }, 147 { typeof(Absolute), OpCode.Absolute }, 148 { typeof(AnalyticQuotient), OpCode.AnalyticQuotient }, 149 { typeof(Cube), OpCode.Cube }, 150 { typeof(CubeRoot), OpCode.CubeRoot } 151 151 }; 152 152 -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r16722 r16899 154 154 private static readonly PropertyInfo Indexer = typeof(IList<double>).GetProperty("Item"); 155 155 private static Expression MakeExpr(ISymbolicExpressionTreeNode node, Dictionary<string, int> variableIndices, Expression row, Expression columns) { 156 var opcode = OpCode s.MapSymbolToOpCode(node);156 var opcode = OpCode.MapSymbolToOpCode(node); 157 157 #region switch opcode 158 158 switch (opcode) { 159 case OpCode s.Constant: {159 case OpCode.Constant: { 160 160 var constantTreeNode = (ConstantTreeNode)node; 161 161 return Expression.Constant(constantTreeNode.Value); 162 162 } 163 case OpCode s.Variable: {163 case OpCode.Variable: { 164 164 var variableTreeNode = (VariableTreeNode)node; 165 165 var variableWeight = Expression.Constant(variableTreeNode.Weight); … … 169 169 return Expression.Multiply(variableWeight, Expression.Property(valuesExpr, Indexer, row)); 170 170 } 171 case OpCode s.Add: {171 case OpCode.Add: { 172 172 Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 173 173 for (int i = 1; i < node.SubtreeCount; ++i) { … … 176 176 return result; 177 177 } 178 case OpCode s.Sub: {178 case OpCode.Sub: { 179 179 Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 180 180 if (node.SubtreeCount == 1) … … 185 185 return result; 186 186 } 187 case OpCode s.Mul: {187 case OpCode.Mul: { 188 188 Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 189 189 for (int i = 1; i < node.SubtreeCount; ++i) { … … 192 192 return result; 193 193 } 194 case OpCode s.Div: {194 case OpCode.Div: { 195 195 Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 196 196 if (node.SubtreeCount == 1) … … 201 201 return result; 202 202 } 203 case OpCode s.Average: {203 case OpCode.Average: { 204 204 Expression result = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 205 205 for (int i = 1; i < node.SubtreeCount; ++i) { … … 208 208 return Expression.Divide(result, Expression.Constant((double)node.SubtreeCount)); 209 209 } 210 case OpCode s.Absolute: {210 case OpCode.Absolute: { 211 211 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 212 212 return Expression.Call(Abs, arg); 213 213 } 214 case OpCode s.Cos: {214 case OpCode.Cos: { 215 215 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 216 216 return Expression.Call(Cos, arg); 217 217 } 218 case OpCode s.Sin: {218 case OpCode.Sin: { 219 219 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 220 220 return Expression.Call(Sin, arg); 221 221 } 222 case OpCode s.Tan: {222 case OpCode.Tan: { 223 223 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 224 224 return Expression.Call(Tan, arg); 225 225 } 226 case OpCode s.Tanh: {226 case OpCode.Tanh: { 227 227 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 228 228 return Expression.Call(Tanh, arg); 229 229 } 230 case OpCode s.Square: {230 case OpCode.Square: { 231 231 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 232 232 return Expression.Power(arg, Expression.Constant(2.0)); 233 233 } 234 case OpCode s.Cube: {234 case OpCode.Cube: { 235 235 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 236 236 return Expression.Power(arg, Expression.Constant(3.0)); 237 237 } 238 case OpCode s.Power: {238 case OpCode.Power: { 239 239 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 240 240 var power = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); 241 241 return Expression.Power(arg, Expression.Call(Round, power)); 242 242 } 243 case OpCode s.SquareRoot: {243 case OpCode.SquareRoot: { 244 244 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 245 245 return Expression.Call(Sqrt, arg); 246 246 } 247 case OpCode s.CubeRoot: {247 case OpCode.CubeRoot: { 248 248 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 249 249 return Expression.Power(arg, Expression.Constant(1.0 / 3.0)); 250 250 } 251 case OpCode s.Root: {251 case OpCode.Root: { 252 252 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 253 253 var power = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); 254 254 return Expression.Power(arg, Expression.Divide(Expression.Constant(1.0), Expression.Call(Round, power))); 255 255 } 256 case OpCode s.Exp: {256 case OpCode.Exp: { 257 257 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 258 258 return Expression.Call(Exp, arg); 259 259 } 260 case OpCode s.Log: {260 case OpCode.Log: { 261 261 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 262 262 return Expression.Call(Log, arg); 263 263 } 264 case OpCode s.Gamma: {264 case OpCode.Gamma: { 265 265 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 266 266 var isNaN = Expression.Call(IsNaN, arg); … … 278 278 return expr; 279 279 } 280 case OpCode s.Psi: {280 case OpCode.Psi: { 281 281 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 282 282 var isNaN = Expression.Call(IsNaN, arg); … … 300 300 return expr; 301 301 } 302 case OpCode s.Dawson: {302 case OpCode.Dawson: { 303 303 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 304 304 var isNaN = Expression.Call(IsNaN, arg); … … 314 314 return expr; 315 315 } 316 case OpCode s.ExponentialIntegralEi: {316 case OpCode.ExponentialIntegralEi: { 317 317 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 318 318 var isNaN = Expression.Call(IsNaN, arg); … … 328 328 return expr; 329 329 } 330 case OpCode s.SineIntegral: {330 case OpCode.SineIntegral: { 331 331 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 332 332 var isNaN = Expression.Call(IsNaN, arg); … … 348 348 return expr; 349 349 } 350 case OpCode s.CosineIntegral: {350 case OpCode.CosineIntegral: { 351 351 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 352 352 var isNaN = Expression.Call(IsNaN, arg); … … 368 368 return expr; 369 369 } 370 case OpCode s.HyperbolicSineIntegral: {370 case OpCode.HyperbolicSineIntegral: { 371 371 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 372 372 var isNaN = Expression.Call(IsNaN, arg); … … 388 388 return expr; 389 389 } 390 case OpCode s.HyperbolicCosineIntegral: {390 case OpCode.HyperbolicCosineIntegral: { 391 391 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 392 392 var isNaN = Expression.Call(IsNaN, arg); … … 408 408 return expr; 409 409 } 410 case OpCode s.FresnelSineIntegral: {410 case OpCode.FresnelSineIntegral: { 411 411 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 412 412 var isNaN = Expression.Call(IsNaN, arg); … … 424 424 return expr; 425 425 } 426 case OpCode s.FresnelCosineIntegral: {426 case OpCode.FresnelCosineIntegral: { 427 427 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 428 428 var isNaN = Expression.Call(IsNaN, arg); … … 440 440 return expr; 441 441 } 442 case OpCode s.AiryA: {442 case OpCode.AiryA: { 443 443 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 444 444 var isNaN = Expression.Call(IsNaN, arg); … … 458 458 return expr; 459 459 } 460 case OpCode s.AiryB: {460 case OpCode.AiryB: { 461 461 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 462 462 var isNaN = Expression.Call(IsNaN, arg); … … 476 476 return expr; 477 477 } 478 case OpCode s.Norm: {478 case OpCode.Norm: { 479 479 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 480 480 var result = Expression.Variable(typeof(double)); … … 487 487 result); 488 488 } 489 case OpCode s.Erf: {489 case OpCode.Erf: { 490 490 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 491 491 var isNaN = Expression.Call(IsNaN, arg); … … 499 499 result); 500 500 } 501 case OpCode s.Bessel: {501 case OpCode.Bessel: { 502 502 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 503 503 var isNaN = Expression.Call(IsNaN, arg); … … 511 511 result); 512 512 } 513 case OpCode s.AnalyticQuotient: {513 case OpCode.AnalyticQuotient: { 514 514 var x1 = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 515 515 var x2 = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); … … 520 520 Expression.Multiply(x2, x2)))); 521 521 } 522 case OpCode s.IfThenElse: {522 case OpCode.IfThenElse: { 523 523 var test = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 524 524 var result = Expression.Variable(typeof(double)); … … 528 528 return Expression.Block(new[] { result }, condition, result); 529 529 } 530 case OpCode s.AND: {530 case OpCode.AND: { 531 531 var result = Expression.Variable(typeof(double)); 532 532 var expr = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); … … 553 553 ); 554 554 } 555 case OpCode s.OR: {555 case OpCode.OR: { 556 556 var result = Expression.Variable(typeof(double)); 557 557 var expr = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); … … 578 578 ); 579 579 } 580 case OpCode s.NOT: {580 case OpCode.NOT: { 581 581 var value = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 582 582 var result = Expression.Variable(typeof(double)); … … 586 586 return Expression.Block(new[] { result }, condition, result); 587 587 } 588 case OpCode s.XOR: {588 case OpCode.XOR: { 589 589 var ps = Expression.Variable(typeof(int)); 590 590 var block = Expression.Block( … … 617 617 return xorExpr; 618 618 } 619 case OpCode s.GT: {619 case OpCode.GT: { 620 620 var left = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 621 621 var right = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); … … 629 629 result); 630 630 } 631 case OpCode s.LT: {631 case OpCode.LT: { 632 632 var left = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 633 633 var right = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); … … 638 638 return Expression.Block(new[] { result }, condition, result); 639 639 } 640 case OpCode s.VariableCondition: {640 case OpCode.VariableCondition: { 641 641 var variableConditionTreeNode = (VariableConditionTreeNode)node; 642 642 if (variableConditionTreeNode.Symbol.IgnoreSlope) throw new NotSupportedException("Strict variable conditionals are not supported"); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r16722 r16899 64 64 65 65 switch (instr.opcode) { 66 case OpCode s.Variable: {66 case OpCode.Variable: { 67 67 LoadData(instr, rows, rowIndex, batchSize); 68 68 break; 69 69 } 70 case OpCode s.TreeModel: {70 case OpCode.TreeModel: { 71 71 SubTreeEvoluate(instr, rows, rowIndex, batchSize); 72 72 break; 73 73 } 74 74 75 case OpCode s.Add: {75 case OpCode.Add: { 76 76 Load(instr.buf, code[c].buf); 77 77 for (int j = 1; j < n; ++j) { … … 81 81 } 82 82 83 case OpCode s.Sub: {83 case OpCode.Sub: { 84 84 if (n == 1) { 85 85 Neg(instr.buf, code[c].buf); … … 93 93 } 94 94 95 case OpCode s.Mul: {95 case OpCode.Mul: { 96 96 Load(instr.buf, code[c].buf); 97 97 for (int j = 1; j < n; ++j) { … … 101 101 } 102 102 103 case OpCode s.Div: {103 case OpCode.Div: { 104 104 if (n == 1) { 105 105 Inv(instr.buf, code[c].buf); … … 113 113 } 114 114 115 case OpCode s.Square: {115 case OpCode.Square: { 116 116 Square(instr.buf, code[c].buf); 117 117 break; 118 118 } 119 119 120 case OpCode s.Root: {120 case OpCode.Root: { 121 121 Load(instr.buf, code[c].buf); 122 122 Root(instr.buf, code[c + 1].buf); … … 124 124 } 125 125 126 case OpCode s.SquareRoot: {126 case OpCode.SquareRoot: { 127 127 Sqrt(instr.buf, code[c].buf); 128 128 break; 129 129 } 130 130 131 case OpCode s.Cube: {131 case OpCode.Cube: { 132 132 Cube(instr.buf, code[c].buf); 133 133 break; 134 134 } 135 case OpCode s.CubeRoot: {135 case OpCode.CubeRoot: { 136 136 CubeRoot(instr.buf, code[c].buf); 137 137 break; 138 138 } 139 139 140 case OpCode s.Power: {140 case OpCode.Power: { 141 141 Load(instr.buf, code[c].buf); 142 142 Pow(instr.buf, code[c + 1].buf); … … 144 144 } 145 145 146 case OpCode s.Exp: {146 case OpCode.Exp: { 147 147 Exp(instr.buf, code[c].buf); 148 148 break; 149 149 } 150 150 151 case OpCode s.Log: {151 case OpCode.Log: { 152 152 Log(instr.buf, code[c].buf); 153 153 break; 154 154 } 155 155 156 case OpCode s.Sin: {156 case OpCode.Sin: { 157 157 Sin(instr.buf, code[c].buf); 158 158 break; 159 159 } 160 160 161 case OpCode s.Cos: {161 case OpCode.Cos: { 162 162 Cos(instr.buf, code[c].buf); 163 163 break; 164 164 } 165 165 166 case OpCode s.Tan: {166 case OpCode.Tan: { 167 167 Tan(instr.buf, code[c].buf); 168 168 break; 169 169 } 170 case OpCode s.Tanh: {170 case OpCode.Tanh: { 171 171 Tanh(instr.buf, code[c].buf); 172 172 break; 173 173 } 174 case OpCode s.Absolute: {174 case OpCode.Absolute: { 175 175 Absolute(instr.buf, code[c].buf); 176 176 break; 177 177 } 178 178 179 case OpCode s.AnalyticQuotient: {179 case OpCode.AnalyticQuotient: { 180 180 Load(instr.buf, code[c].buf); 181 181 AnalyticQuotient(instr.buf, code[c + 1].buf); … … 213 213 } 214 214 215 var code = Compile(tree, dataset, OpCode s.MapSymbolToOpCode, rows);215 var code = Compile(tree, dataset, OpCode.MapSymbolToOpCode, rows); 216 216 var remainingRows = rows.Length % BATCHSIZE; 217 217 var roundedTotal = rows.Length - remainingRows; -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r16722 r16899 180 180 181 181 private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) { 182 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode s.MapSymbolToOpCode);182 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode.MapSymbolToOpCode); 183 183 Dictionary<string, int> doubleVariableNames = dataset.DoubleVariables.Select((x, i) => new { x, i }).ToDictionary(e => e.x, e => e.i); 184 184 int necessaryArgStackSize = 0; 185 185 foreach (Instruction instr in code) { 186 if (instr.opCode == OpCode s.Variable) {186 if (instr.opCode == OpCode.Variable) { 187 187 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 188 188 instr.data = doubleVariableNames[variableTreeNode.VariableName]; 189 } else if (instr.opCode == OpCode s.LagVariable) {189 } else if (instr.opCode == OpCode.LagVariable) { 190 190 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 191 191 instr.data = doubleVariableNames[laggedVariableTreeNode.VariableName]; 192 } else if (instr.opCode == OpCode s.VariableCondition) {192 } else if (instr.opCode == OpCode.VariableCondition) { 193 193 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 194 194 instr.data = doubleVariableNames[variableConditionTreeNode.VariableName]; 195 } else if (instr.opCode == OpCode s.Call) {195 } else if (instr.opCode == OpCode.Call) { 196 196 necessaryArgStackSize += instr.nArguments + 1; 197 197 } … … 205 205 206 206 switch (currentInstr.opCode) { 207 case OpCode s.Add: {207 case OpCode.Add: { 208 208 if (nArgs > 0) { 209 209 CompileInstructions(il, state, ds); … … 215 215 return; 216 216 } 217 case OpCode s.Sub: {217 case OpCode.Sub: { 218 218 if (nArgs == 1) { 219 219 CompileInstructions(il, state, ds); … … 230 230 return; 231 231 } 232 case OpCode s.Mul: {232 case OpCode.Mul: { 233 233 if (nArgs > 0) { 234 234 CompileInstructions(il, state, ds); … … 240 240 return; 241 241 } 242 case OpCode s.Div: {242 case OpCode.Div: { 243 243 if (nArgs == 1) { 244 244 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); … … 256 256 return; 257 257 } 258 case OpCode s.Average: {258 case OpCode.Average: { 259 259 CompileInstructions(il, state, ds); 260 260 for (int i = 1; i < nArgs; i++) { … … 266 266 return; 267 267 } 268 case OpCode s.Absolute: {268 case OpCode.Absolute: { 269 269 CompileInstructions(il, state, ds); 270 270 il.Emit(System.Reflection.Emit.OpCodes.Call, abs); 271 271 return; 272 272 } 273 case OpCode s.Cos: {273 case OpCode.Cos: { 274 274 CompileInstructions(il, state, ds); 275 275 il.Emit(System.Reflection.Emit.OpCodes.Call, cos); 276 276 return; 277 277 } 278 case OpCode s.Sin: {278 case OpCode.Sin: { 279 279 CompileInstructions(il, state, ds); 280 280 il.Emit(System.Reflection.Emit.OpCodes.Call, sin); 281 281 return; 282 282 } 283 case OpCode s.Tan: {283 case OpCode.Tan: { 284 284 CompileInstructions(il, state, ds); 285 285 il.Emit(System.Reflection.Emit.OpCodes.Call, tan); 286 286 return; 287 287 } 288 case OpCode s.Tanh: {288 case OpCode.Tanh: { 289 289 CompileInstructions(il, state, ds); 290 290 il.Emit(System.Reflection.Emit.OpCodes.Call, tanh); 291 291 return; 292 292 } 293 case OpCode s.Power: {293 case OpCode.Power: { 294 294 CompileInstructions(il, state, ds); 295 295 CompileInstructions(il, state, ds); … … 298 298 return; 299 299 } 300 case OpCode s.Root: {300 case OpCode.Root: { 301 301 CompileInstructions(il, state, ds); 302 302 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); // 1 / round(...) … … 307 307 return; 308 308 } 309 case OpCode s.Exp: {309 case OpCode.Exp: { 310 310 CompileInstructions(il, state, ds); 311 311 il.Emit(System.Reflection.Emit.OpCodes.Call, exp); 312 312 return; 313 313 } 314 case OpCode s.Log: {314 case OpCode.Log: { 315 315 CompileInstructions(il, state, ds); 316 316 il.Emit(System.Reflection.Emit.OpCodes.Call, log); 317 317 return; 318 318 } 319 case OpCode s.Square: {319 case OpCode.Square: { 320 320 CompileInstructions(il, state, ds); 321 321 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); … … 323 323 return; 324 324 } 325 case OpCode s.Cube: {325 case OpCode.Cube: { 326 326 CompileInstructions(il, state, ds); 327 327 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 3.0); … … 329 329 return; 330 330 } 331 case OpCode s.SquareRoot: {331 case OpCode.SquareRoot: { 332 332 CompileInstructions(il, state, ds); 333 333 il.Emit(System.Reflection.Emit.OpCodes.Call, sqrt); 334 334 return; 335 335 } 336 case OpCode s.CubeRoot: {336 case OpCode.CubeRoot: { 337 337 CompileInstructions(il, state, ds); 338 338 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0 / 3.0); … … 340 340 return; 341 341 } 342 case OpCode s.AiryA: {342 case OpCode.AiryA: { 343 343 CompileInstructions(il, state, ds); 344 344 il.Emit(System.Reflection.Emit.OpCodes.Call, airyA); 345 345 return; 346 346 } 347 case OpCode s.AiryB: {347 case OpCode.AiryB: { 348 348 CompileInstructions(il, state, ds); 349 349 il.Emit(System.Reflection.Emit.OpCodes.Call, airyB); 350 350 return; 351 351 } 352 case OpCode s.Bessel: {352 case OpCode.Bessel: { 353 353 CompileInstructions(il, state, ds); 354 354 il.Emit(System.Reflection.Emit.OpCodes.Call, bessel); 355 355 return; 356 356 } 357 case OpCode s.CosineIntegral: {357 case OpCode.CosineIntegral: { 358 358 CompileInstructions(il, state, ds); 359 359 il.Emit(System.Reflection.Emit.OpCodes.Call, cosIntegral); 360 360 return; 361 361 } 362 case OpCode s.Dawson: {362 case OpCode.Dawson: { 363 363 CompileInstructions(il, state, ds); 364 364 il.Emit(System.Reflection.Emit.OpCodes.Call, dawson); 365 365 return; 366 366 } 367 case OpCode s.Erf: {367 case OpCode.Erf: { 368 368 CompileInstructions(il, state, ds); 369 369 il.Emit(System.Reflection.Emit.OpCodes.Call, erf); 370 370 return; 371 371 } 372 case OpCode s.ExponentialIntegralEi: {372 case OpCode.ExponentialIntegralEi: { 373 373 CompileInstructions(il, state, ds); 374 374 il.Emit(System.Reflection.Emit.OpCodes.Call, expIntegralEi); 375 375 return; 376 376 } 377 case OpCode s.FresnelCosineIntegral: {377 case OpCode.FresnelCosineIntegral: { 378 378 CompileInstructions(il, state, ds); 379 379 il.Emit(System.Reflection.Emit.OpCodes.Call, fresnelCosIntegral); 380 380 return; 381 381 } 382 case OpCode s.FresnelSineIntegral: {382 case OpCode.FresnelSineIntegral: { 383 383 CompileInstructions(il, state, ds); 384 384 il.Emit(System.Reflection.Emit.OpCodes.Call, fresnelSinIntegral); 385 385 return; 386 386 } 387 case OpCode s.Gamma: {387 case OpCode.Gamma: { 388 388 CompileInstructions(il, state, ds); 389 389 il.Emit(System.Reflection.Emit.OpCodes.Call, gamma); 390 390 return; 391 391 } 392 case OpCode s.HyperbolicCosineIntegral: {392 case OpCode.HyperbolicCosineIntegral: { 393 393 CompileInstructions(il, state, ds); 394 394 il.Emit(System.Reflection.Emit.OpCodes.Call, hypCosIntegral); 395 395 return; 396 396 } 397 case OpCode s.HyperbolicSineIntegral: {397 case OpCode.HyperbolicSineIntegral: { 398 398 CompileInstructions(il, state, ds); 399 399 il.Emit(System.Reflection.Emit.OpCodes.Call, hypSinIntegral); 400 400 return; 401 401 } 402 case OpCode s.Norm: {402 case OpCode.Norm: { 403 403 CompileInstructions(il, state, ds); 404 404 il.Emit(System.Reflection.Emit.OpCodes.Call, norm); 405 405 return; 406 406 } 407 case OpCode s.Psi: {407 case OpCode.Psi: { 408 408 CompileInstructions(il, state, ds); 409 409 il.Emit(System.Reflection.Emit.OpCodes.Call, psi); 410 410 return; 411 411 } 412 case OpCode s.SineIntegral: {412 case OpCode.SineIntegral: { 413 413 CompileInstructions(il, state, ds); 414 414 il.Emit(System.Reflection.Emit.OpCodes.Call, sinIntegral); 415 415 return; 416 416 } 417 case OpCode s.AnalyticQuotient: {417 case OpCode.AnalyticQuotient: { 418 418 CompileInstructions(il, state, ds); // x1 419 419 CompileInstructions(il, state, ds); // x2 … … 427 427 return; 428 428 } 429 case OpCode s.IfThenElse: {429 case OpCode.IfThenElse: { 430 430 Label end = il.DefineLabel(); 431 431 Label c1 = il.DefineLabel(); … … 441 441 return; 442 442 } 443 case OpCode s.AND: {443 case OpCode.AND: { 444 444 Label falseBranch = il.DefineLabel(); 445 445 Label end = il.DefineLabel(); … … 462 462 return; 463 463 } 464 case OpCode s.OR: {464 case OpCode.OR: { 465 465 Label trueBranch = il.DefineLabel(); 466 466 Label end = il.DefineLabel(); … … 490 490 return; 491 491 } 492 case OpCode s.NOT: {492 case OpCode.NOT: { 493 493 CompileInstructions(il, state, ds); 494 494 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); // > 0 … … 502 502 return; 503 503 } 504 case OpCode s.XOR: {504 case OpCode.XOR: { 505 505 CompileInstructions(il, state, ds); 506 506 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 0.0); … … 521 521 return; 522 522 } 523 case OpCode s.GT: {523 case OpCode.GT: { 524 524 CompileInstructions(il, state, ds); 525 525 CompileInstructions(il, state, ds); … … 533 533 return; 534 534 } 535 case OpCode s.LT: {535 case OpCode.LT: { 536 536 CompileInstructions(il, state, ds); 537 537 CompileInstructions(il, state, ds); … … 544 544 return; 545 545 } 546 case OpCode s.TimeLag: {546 case OpCode.TimeLag: { 547 547 LaggedTreeNode laggedTreeNode = (LaggedTreeNode)currentInstr.dynamicNode; 548 548 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // row -= lag … … 560 560 return; 561 561 } 562 case OpCode s.Integral: {562 case OpCode.Integral: { 563 563 int savedPc = state.ProgramCounter; 564 564 LaggedTreeNode laggedTreeNode = (LaggedTreeNode)currentInstr.dynamicNode; … … 587 587 //one sided smooth differentiatior, N = 4 588 588 // y' = 1/8h (f_i + 2f_i-1, -2 f_i-3 - f_i-4) 589 case OpCode s.Derivative: {589 case OpCode.Derivative: { 590 590 int savedPc = state.ProgramCounter; 591 591 CompileInstructions(il, state, ds); … … 629 629 return; 630 630 } 631 case OpCode s.Call: {631 case OpCode.Call: { 632 632 throw new NotSupportedException( 633 633 "Automatically defined functions are not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter. Either turn of ADFs or change the interpeter."); 634 634 } 635 case OpCode s.Arg: {635 case OpCode.Arg: { 636 636 throw new NotSupportedException( 637 637 "Automatically defined functions are not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter. Either turn of ADFs or change the interpeter."); 638 638 } 639 case OpCode s.Variable: {639 case OpCode.Variable: { 640 640 VariableTreeNode varNode = (VariableTreeNode)currentInstr.dynamicNode; 641 641 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array … … 669 669 return; 670 670 } 671 case OpCode s.LagVariable: {671 case OpCode.LagVariable: { 672 672 var nanResult = il.DefineLabel(); 673 673 var normalResult = il.DefineLabel(); … … 697 697 return; 698 698 } 699 case OpCode s.Constant: {699 case OpCode.Constant: { 700 700 ConstantTreeNode constNode = (ConstantTreeNode)currentInstr.dynamicNode; 701 701 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value); … … 705 705 //mkommend: this symbol uses the logistic function f(x) = 1 / (1 + e^(-alpha * x) ) 706 706 //to determine the relative amounts of the true and false branch see http://en.wikipedia.org/wiki/Logistic_function 707 case OpCode s.VariableCondition: {707 case OpCode.VariableCondition: { 708 708 throw new NotSupportedException("Interpretation of symbol " + currentInstr.dynamicNode.Symbol.Name + 709 709 " is not supported by the SymbolicDataAnalysisTreeILEmittingInterpreter"); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r16722 r16899 137 137 138 138 private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) { 139 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode s.MapSymbolToOpCode);139 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCode.MapSymbolToOpCode); 140 140 int necessaryArgStackSize = 0; 141 141 foreach (Instruction instr in code) { 142 if (instr.opCode == OpCode s.Variable) {142 if (instr.opCode == OpCode.Variable) { 143 143 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 144 144 instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 145 } else if (instr.opCode == OpCode s.FactorVariable) {145 } else if (instr.opCode == OpCode.FactorVariable) { 146 146 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 147 147 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 148 } else if (instr.opCode == OpCode s.BinaryFactorVariable) {148 } else if (instr.opCode == OpCode.BinaryFactorVariable) { 149 149 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 150 150 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 151 } else if (instr.opCode == OpCode s.LagVariable) {151 } else if (instr.opCode == OpCode.LagVariable) { 152 152 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 153 153 instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName); 154 } else if (instr.opCode == OpCode s.VariableCondition) {154 } else if (instr.opCode == OpCode.VariableCondition) { 155 155 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 156 156 instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName); 157 } else if (instr.opCode == OpCode s.Call) {157 } else if (instr.opCode == OpCode.Call) { 158 158 necessaryArgStackSize += instr.nArguments + 1; 159 159 } … … 165 165 Instruction currentInstr = state.NextInstruction(); 166 166 switch (currentInstr.opCode) { 167 case OpCode s.Add: {167 case OpCode.Add: { 168 168 double s = Evaluate(dataset, ref row, state); 169 169 for (int i = 1; i < currentInstr.nArguments; i++) { … … 172 172 return s; 173 173 } 174 case OpCode s.Sub: {174 case OpCode.Sub: { 175 175 double s = Evaluate(dataset, ref row, state); 176 176 for (int i = 1; i < currentInstr.nArguments; i++) { … … 180 180 return s; 181 181 } 182 case OpCode s.Mul: {182 case OpCode.Mul: { 183 183 double p = Evaluate(dataset, ref row, state); 184 184 for (int i = 1; i < currentInstr.nArguments; i++) { … … 187 187 return p; 188 188 } 189 case OpCode s.Div: {189 case OpCode.Div: { 190 190 double p = Evaluate(dataset, ref row, state); 191 191 for (int i = 1; i < currentInstr.nArguments; i++) { … … 195 195 return p; 196 196 } 197 case OpCode s.Average: {197 case OpCode.Average: { 198 198 double sum = Evaluate(dataset, ref row, state); 199 199 for (int i = 1; i < currentInstr.nArguments; i++) { … … 202 202 return sum / currentInstr.nArguments; 203 203 } 204 case OpCode s.Absolute: {204 case OpCode.Absolute: { 205 205 return Math.Abs(Evaluate(dataset, ref row, state)); 206 206 } 207 case OpCode s.Tanh: {207 case OpCode.Tanh: { 208 208 return Math.Tanh(Evaluate(dataset, ref row, state)); 209 209 } 210 case OpCode s.Cos: {210 case OpCode.Cos: { 211 211 return Math.Cos(Evaluate(dataset, ref row, state)); 212 212 } 213 case OpCode s.Sin: {213 case OpCode.Sin: { 214 214 return Math.Sin(Evaluate(dataset, ref row, state)); 215 215 } 216 case OpCode s.Tan: {216 case OpCode.Tan: { 217 217 return Math.Tan(Evaluate(dataset, ref row, state)); 218 218 } 219 case OpCode s.Square: {219 case OpCode.Square: { 220 220 return Math.Pow(Evaluate(dataset, ref row, state), 2); 221 221 } 222 case OpCode s.Cube: {222 case OpCode.Cube: { 223 223 return Math.Pow(Evaluate(dataset, ref row, state), 3); 224 224 } 225 case OpCode s.Power: {225 case OpCode.Power: { 226 226 double x = Evaluate(dataset, ref row, state); 227 227 double y = Math.Round(Evaluate(dataset, ref row, state)); 228 228 return Math.Pow(x, y); 229 229 } 230 case OpCode s.SquareRoot: {230 case OpCode.SquareRoot: { 231 231 return Math.Sqrt(Evaluate(dataset, ref row, state)); 232 232 } 233 case OpCode s.CubeRoot: {233 case OpCode.CubeRoot: { 234 234 return Math.Pow(Evaluate(dataset, ref row, state), 1.0 / 3.0); 235 235 } 236 case OpCode s.Root: {236 case OpCode.Root: { 237 237 double x = Evaluate(dataset, ref row, state); 238 238 double y = Math.Round(Evaluate(dataset, ref row, state)); 239 239 return Math.Pow(x, 1 / y); 240 240 } 241 case OpCode s.Exp: {241 case OpCode.Exp: { 242 242 return Math.Exp(Evaluate(dataset, ref row, state)); 243 243 } 244 case OpCode s.Log: {244 case OpCode.Log: { 245 245 return Math.Log(Evaluate(dataset, ref row, state)); 246 246 } 247 case OpCode s.Gamma: {247 case OpCode.Gamma: { 248 248 var x = Evaluate(dataset, ref row, state); 249 249 if (double.IsNaN(x)) { return double.NaN; } else { return alglib.gammafunction(x); } 250 250 } 251 case OpCode s.Psi: {251 case OpCode.Psi: { 252 252 var x = Evaluate(dataset, ref row, state); 253 253 if (double.IsNaN(x)) return double.NaN; … … 255 255 return alglib.psi(x); 256 256 } 257 case OpCode s.Dawson: {257 case OpCode.Dawson: { 258 258 var x = Evaluate(dataset, ref row, state); 259 259 if (double.IsNaN(x)) { return double.NaN; } 260 260 return alglib.dawsonintegral(x); 261 261 } 262 case OpCode s.ExponentialIntegralEi: {262 case OpCode.ExponentialIntegralEi: { 263 263 var x = Evaluate(dataset, ref row, state); 264 264 if (double.IsNaN(x)) { return double.NaN; } 265 265 return alglib.exponentialintegralei(x); 266 266 } 267 case OpCode s.SineIntegral: {267 case OpCode.SineIntegral: { 268 268 double si, ci; 269 269 var x = Evaluate(dataset, ref row, state); … … 274 274 } 275 275 } 276 case OpCode s.CosineIntegral: {276 case OpCode.CosineIntegral: { 277 277 double si, ci; 278 278 var x = Evaluate(dataset, ref row, state); … … 283 283 } 284 284 } 285 case OpCode s.HyperbolicSineIntegral: {285 case OpCode.HyperbolicSineIntegral: { 286 286 double shi, chi; 287 287 var x = Evaluate(dataset, ref row, state); … … 292 292 } 293 293 } 294 case OpCode s.HyperbolicCosineIntegral: {294 case OpCode.HyperbolicCosineIntegral: { 295 295 double shi, chi; 296 296 var x = Evaluate(dataset, ref row, state); … … 301 301 } 302 302 } 303 case OpCode s.FresnelCosineIntegral: {303 case OpCode.FresnelCosineIntegral: { 304 304 double c = 0, s = 0; 305 305 var x = Evaluate(dataset, ref row, state); … … 310 310 } 311 311 } 312 case OpCode s.FresnelSineIntegral: {312 case OpCode.FresnelSineIntegral: { 313 313 double c = 0, s = 0; 314 314 var x = Evaluate(dataset, ref row, state); … … 319 319 } 320 320 } 321 case OpCode s.AiryA: {321 case OpCode.AiryA: { 322 322 double ai, aip, bi, bip; 323 323 var x = Evaluate(dataset, ref row, state); … … 328 328 } 329 329 } 330 case OpCode s.AiryB: {330 case OpCode.AiryB: { 331 331 double ai, aip, bi, bip; 332 332 var x = Evaluate(dataset, ref row, state); … … 337 337 } 338 338 } 339 case OpCode s.Norm: {339 case OpCode.Norm: { 340 340 var x = Evaluate(dataset, ref row, state); 341 341 if (double.IsNaN(x)) return double.NaN; 342 342 else return alglib.normaldistribution(x); 343 343 } 344 case OpCode s.Erf: {344 case OpCode.Erf: { 345 345 var x = Evaluate(dataset, ref row, state); 346 346 if (double.IsNaN(x)) return double.NaN; 347 347 else return alglib.errorfunction(x); 348 348 } 349 case OpCode s.Bessel: {349 case OpCode.Bessel: { 350 350 var x = Evaluate(dataset, ref row, state); 351 351 if (double.IsNaN(x)) return double.NaN; … … 353 353 } 354 354 355 case OpCode s.AnalyticQuotient: {355 case OpCode.AnalyticQuotient: { 356 356 var x1 = Evaluate(dataset, ref row, state); 357 357 var x2 = Evaluate(dataset, ref row, state); 358 358 return x1 / Math.Pow(1 + x2 * x2, 0.5); 359 359 } 360 case OpCode s.IfThenElse: {360 case OpCode.IfThenElse: { 361 361 double condition = Evaluate(dataset, ref row, state); 362 362 double result; … … 368 368 return result; 369 369 } 370 case OpCode s.AND: {370 case OpCode.AND: { 371 371 double result = Evaluate(dataset, ref row, state); 372 372 for (int i = 1; i < currentInstr.nArguments; i++) { … … 378 378 return result > 0.0 ? 1.0 : -1.0; 379 379 } 380 case OpCode s.OR: {380 case OpCode.OR: { 381 381 double result = Evaluate(dataset, ref row, state); 382 382 for (int i = 1; i < currentInstr.nArguments; i++) { … … 388 388 return result > 0.0 ? 1.0 : -1.0; 389 389 } 390 case OpCode s.NOT: {390 case OpCode.NOT: { 391 391 return Evaluate(dataset, ref row, state) > 0.0 ? -1.0 : 1.0; 392 392 } 393 case OpCode s.XOR: {393 case OpCode.XOR: { 394 394 //mkommend: XOR on multiple inputs is defined as true if the number of positive signals is odd 395 395 // this is equal to a consecutive execution of binary XOR operations. … … 400 400 return positiveSignals % 2 != 0 ? 1.0 : -1.0; 401 401 } 402 case OpCode s.GT: {402 case OpCode.GT: { 403 403 double x = Evaluate(dataset, ref row, state); 404 404 double y = Evaluate(dataset, ref row, state); 405 405 if (x > y) { return 1.0; } else { return -1.0; } 406 406 } 407 case OpCode s.LT: {407 case OpCode.LT: { 408 408 double x = Evaluate(dataset, ref row, state); 409 409 double y = Evaluate(dataset, ref row, state); 410 410 if (x < y) { return 1.0; } else { return -1.0; } 411 411 } 412 case OpCode s.TimeLag: {412 case OpCode.TimeLag: { 413 413 var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode; 414 414 row += timeLagTreeNode.Lag; … … 417 417 return result; 418 418 } 419 case OpCode s.Integral: {419 case OpCode.Integral: { 420 420 int savedPc = state.ProgramCounter; 421 421 var timeLagTreeNode = (LaggedTreeNode)currentInstr.dynamicNode; … … 435 435 //one sided smooth differentiatior, N = 4 436 436 // y' = 1/8h (f_i + 2f_i-1, -2 f_i-3 - f_i-4) 437 case OpCode s.Derivative: {437 case OpCode.Derivative: { 438 438 int savedPc = state.ProgramCounter; 439 439 double f_0 = Evaluate(dataset, ref row, state); row--; … … 448 448 return (f_0 + 2 * f_1 - 2 * f_3 - f_4) / 8; // h = 1 449 449 } 450 case OpCode s.Call: {450 case OpCode.Call: { 451 451 // evaluate sub-trees 452 452 double[] argValues = new double[currentInstr.nArguments]; … … 471 471 return v; 472 472 } 473 case OpCode s.Arg: {473 case OpCode.Arg: { 474 474 return state.GetStackFrameValue((ushort)currentInstr.data); 475 475 } 476 case OpCode s.Variable: {476 case OpCode.Variable: { 477 477 if (row < 0 || row >= dataset.Rows) return double.NaN; 478 478 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 479 479 return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight; 480 480 } 481 case OpCode s.BinaryFactorVariable: {481 case OpCode.BinaryFactorVariable: { 482 482 if (row < 0 || row >= dataset.Rows) return double.NaN; 483 483 var factorVarTreeNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode; 484 484 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? factorVarTreeNode.Weight : 0; 485 485 } 486 case OpCode s.FactorVariable: {486 case OpCode.FactorVariable: { 487 487 if (row < 0 || row >= dataset.Rows) return double.NaN; 488 488 var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode; 489 489 return factorVarTreeNode.GetValue(((IList<string>)currentInstr.data)[row]); 490 490 } 491 case OpCode s.LagVariable: {491 case OpCode.LagVariable: { 492 492 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; 493 493 int actualRow = row + laggedVariableTreeNode.Lag; … … 495 495 return ((IList<double>)currentInstr.data)[actualRow] * laggedVariableTreeNode.Weight; 496 496 } 497 case OpCode s.Constant: {497 case OpCode.Constant: { 498 498 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 499 499 return constTreeNode.Value; … … 502 502 //mkommend: this symbol uses the logistic function f(x) = 1 / (1 + e^(-alpha * x) ) 503 503 //to determine the relative amounts of the true and false branch see http://en.wikipedia.org/wiki/Logistic_function 504 case OpCode s.VariableCondition: {504 case OpCode.VariableCondition: { 505 505 if (row < 0 || row >= dataset.Rows) return double.NaN; 506 506 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode; -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r16722 r16899 133 133 } 134 134 135 var code = SymbolicExpressionTreeLinearCompiler.Compile(tree, OpCode s.MapSymbolToOpCode);135 var code = SymbolicExpressionTreeLinearCompiler.Compile(tree, OpCode.MapSymbolToOpCode); 136 136 PrepareInstructions(code, dataset); 137 137 return rows.Select(row => Evaluate(dataset, row, code)); … … 143 143 #region opcode if 144 144 var instr = code[i]; 145 if (instr.opCode == OpCode s.Variable) {145 if (instr.opCode == OpCode.Variable) { 146 146 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 147 147 else { … … 149 149 instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight; 150 150 } 151 } else if (instr.opCode == OpCode s.BinaryFactorVariable) {151 } else if (instr.opCode == OpCode.BinaryFactorVariable) { 152 152 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 153 153 else { … … 155 155 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0; 156 156 } 157 } else if (instr.opCode == OpCode s.FactorVariable) {157 } else if (instr.opCode == OpCode.FactorVariable) { 158 158 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 159 159 else { … … 161 161 instr.value = factorTreeNode.GetValue(((IList<string>)instr.data)[row]); 162 162 } 163 } else if (instr.opCode == OpCode s.LagVariable) {163 } else if (instr.opCode == OpCode.LagVariable) { 164 164 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 165 165 int actualRow = row + laggedVariableTreeNode.Lag; … … 168 168 else 169 169 instr.value = ((IList<double>)instr.data)[actualRow] * laggedVariableTreeNode.Weight; 170 } else if (instr.opCode == OpCode s.VariableCondition) {170 } else if (instr.opCode == OpCode.VariableCondition) { 171 171 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 172 172 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; … … 188 188 } 189 189 } 190 } else if (instr.opCode == OpCode s.Add) {190 } else if (instr.opCode == OpCode.Add) { 191 191 double s = code[instr.childIndex].value; 192 192 for (int j = 1; j != instr.nArguments; ++j) { … … 194 194 } 195 195 instr.value = s; 196 } else if (instr.opCode == OpCode s.Sub) {196 } else if (instr.opCode == OpCode.Sub) { 197 197 double s = code[instr.childIndex].value; 198 198 for (int j = 1; j != instr.nArguments; ++j) { … … 201 201 if (instr.nArguments == 1) s = -s; 202 202 instr.value = s; 203 } else if (instr.opCode == OpCode s.Mul) {203 } else if (instr.opCode == OpCode.Mul) { 204 204 double p = code[instr.childIndex].value; 205 205 for (int j = 1; j != instr.nArguments; ++j) { … … 207 207 } 208 208 instr.value = p; 209 } else if (instr.opCode == OpCode s.Div) {209 } else if (instr.opCode == OpCode.Div) { 210 210 double p = code[instr.childIndex].value; 211 211 for (int j = 1; j != instr.nArguments; ++j) { … … 214 214 if (instr.nArguments == 1) p = 1.0 / p; 215 215 instr.value = p; 216 } else if (instr.opCode == OpCode s.AnalyticQuotient) {216 } else if (instr.opCode == OpCode.AnalyticQuotient) { 217 217 var x1 = code[instr.childIndex].value; 218 218 var x2 = code[instr.childIndex + 1].value; 219 219 instr.value = x1 / Math.Sqrt(1 + x2 * x2); 220 } else if (instr.opCode == OpCode s.Average) {220 } else if (instr.opCode == OpCode.Average) { 221 221 double s = code[instr.childIndex].value; 222 222 for (int j = 1; j != instr.nArguments; ++j) { … … 224 224 } 225 225 instr.value = s / instr.nArguments; 226 } else if (instr.opCode == OpCode s.Absolute) {226 } else if (instr.opCode == OpCode.Absolute) { 227 227 instr.value = Math.Abs(code[instr.childIndex].value); 228 } else if (instr.opCode == OpCode s.Tanh) {228 } else if (instr.opCode == OpCode.Tanh) { 229 229 instr.value = Math.Tanh(code[instr.childIndex].value); 230 } else if (instr.opCode == OpCode s.Cos) {230 } else if (instr.opCode == OpCode.Cos) { 231 231 instr.value = Math.Cos(code[instr.childIndex].value); 232 } else if (instr.opCode == OpCode s.Sin) {232 } else if (instr.opCode == OpCode.Sin) { 233 233 instr.value = Math.Sin(code[instr.childIndex].value); 234 } else if (instr.opCode == OpCode s.Tan) {234 } else if (instr.opCode == OpCode.Tan) { 235 235 instr.value = Math.Tan(code[instr.childIndex].value); 236 } else if (instr.opCode == OpCode s.Square) {236 } else if (instr.opCode == OpCode.Square) { 237 237 instr.value = Math.Pow(code[instr.childIndex].value, 2); 238 } else if (instr.opCode == OpCode s.Cube) {238 } else if (instr.opCode == OpCode.Cube) { 239 239 instr.value = Math.Pow(code[instr.childIndex].value, 3); 240 } else if (instr.opCode == OpCode s.Power) {240 } else if (instr.opCode == OpCode.Power) { 241 241 double x = code[instr.childIndex].value; 242 242 double y = Math.Round(code[instr.childIndex + 1].value); 243 243 instr.value = Math.Pow(x, y); 244 } else if (instr.opCode == OpCode s.SquareRoot) {244 } else if (instr.opCode == OpCode.SquareRoot) { 245 245 instr.value = Math.Sqrt(code[instr.childIndex].value); 246 } else if (instr.opCode == OpCode s.CubeRoot) {246 } else if (instr.opCode == OpCode.CubeRoot) { 247 247 instr.value = Math.Pow(code[instr.childIndex].value, 1.0 / 3.0); 248 } else if (instr.opCode == OpCode s.Root) {248 } else if (instr.opCode == OpCode.Root) { 249 249 double x = code[instr.childIndex].value; 250 250 double y = Math.Round(code[instr.childIndex + 1].value); 251 251 instr.value = Math.Pow(x, 1 / y); 252 } else if (instr.opCode == OpCode s.Exp) {252 } else if (instr.opCode == OpCode.Exp) { 253 253 instr.value = Math.Exp(code[instr.childIndex].value); 254 } else if (instr.opCode == OpCode s.Log) {254 } else if (instr.opCode == OpCode.Log) { 255 255 instr.value = Math.Log(code[instr.childIndex].value); 256 } else if (instr.opCode == OpCode s.Gamma) {256 } else if (instr.opCode == OpCode.Gamma) { 257 257 var x = code[instr.childIndex].value; 258 258 instr.value = double.IsNaN(x) ? double.NaN : alglib.gammafunction(x); 259 } else if (instr.opCode == OpCode s.Psi) {259 } else if (instr.opCode == OpCode.Psi) { 260 260 var x = code[instr.childIndex].value; 261 261 if (double.IsNaN(x)) instr.value = double.NaN; 262 262 else if (x <= 0 && (Math.Floor(x) - x).IsAlmost(0)) instr.value = double.NaN; 263 263 else instr.value = alglib.psi(x); 264 } else if (instr.opCode == OpCode s.Dawson) {264 } else if (instr.opCode == OpCode.Dawson) { 265 265 var x = code[instr.childIndex].value; 266 266 instr.value = double.IsNaN(x) ? double.NaN : alglib.dawsonintegral(x); 267 } else if (instr.opCode == OpCode s.ExponentialIntegralEi) {267 } else if (instr.opCode == OpCode.ExponentialIntegralEi) { 268 268 var x = code[instr.childIndex].value; 269 269 instr.value = double.IsNaN(x) ? double.NaN : alglib.exponentialintegralei(x); 270 } else if (instr.opCode == OpCode s.SineIntegral) {270 } else if (instr.opCode == OpCode.SineIntegral) { 271 271 double si, ci; 272 272 var x = code[instr.childIndex].value; … … 276 276 instr.value = si; 277 277 } 278 } else if (instr.opCode == OpCode s.CosineIntegral) {278 } else if (instr.opCode == OpCode.CosineIntegral) { 279 279 double si, ci; 280 280 var x = code[instr.childIndex].value; … … 284 284 instr.value = ci; 285 285 } 286 } else if (instr.opCode == OpCode s.HyperbolicSineIntegral) {286 } else if (instr.opCode == OpCode.HyperbolicSineIntegral) { 287 287 double shi, chi; 288 288 var x = code[instr.childIndex].value; … … 292 292 instr.value = shi; 293 293 } 294 } else if (instr.opCode == OpCode s.HyperbolicCosineIntegral) {294 } else if (instr.opCode == OpCode.HyperbolicCosineIntegral) { 295 295 double shi, chi; 296 296 var x = code[instr.childIndex].value; … … 300 300 instr.value = chi; 301 301 } 302 } else if (instr.opCode == OpCode s.FresnelCosineIntegral) {302 } else if (instr.opCode == OpCode.FresnelCosineIntegral) { 303 303 double c = 0, s = 0; 304 304 var x = code[instr.childIndex].value; … … 308 308 instr.value = c; 309 309 } 310 } else if (instr.opCode == OpCode s.FresnelSineIntegral) {310 } else if (instr.opCode == OpCode.FresnelSineIntegral) { 311 311 double c = 0, s = 0; 312 312 var x = code[instr.childIndex].value; … … 316 316 instr.value = s; 317 317 } 318 } else if (instr.opCode == OpCode s.AiryA) {318 } else if (instr.opCode == OpCode.AiryA) { 319 319 double ai, aip, bi, bip; 320 320 var x = code[instr.childIndex].value; … … 324 324 instr.value = ai; 325 325 } 326 } else if (instr.opCode == OpCode s.AiryB) {326 } else if (instr.opCode == OpCode.AiryB) { 327 327 double ai, aip, bi, bip; 328 328 var x = code[instr.childIndex].value; … … 332 332 instr.value = bi; 333 333 } 334 } else if (instr.opCode == OpCode s.Norm) {334 } else if (instr.opCode == OpCode.Norm) { 335 335 var x = code[instr.childIndex].value; 336 336 if (double.IsNaN(x)) instr.value = double.NaN; 337 337 else instr.value = alglib.normaldistribution(x); 338 } else if (instr.opCode == OpCode s.Erf) {338 } else if (instr.opCode == OpCode.Erf) { 339 339 var x = code[instr.childIndex].value; 340 340 if (double.IsNaN(x)) instr.value = double.NaN; 341 341 else instr.value = alglib.errorfunction(x); 342 } else if (instr.opCode == OpCode s.Bessel) {342 } else if (instr.opCode == OpCode.Bessel) { 343 343 var x = code[instr.childIndex].value; 344 344 if (double.IsNaN(x)) instr.value = double.NaN; 345 345 else instr.value = alglib.besseli0(x); 346 } else if (instr.opCode == OpCode s.IfThenElse) {346 } else if (instr.opCode == OpCode.IfThenElse) { 347 347 double condition = code[instr.childIndex].value; 348 348 double result; … … 353 353 } 354 354 instr.value = result; 355 } else if (instr.opCode == OpCode s.AND) {355 } else if (instr.opCode == OpCode.AND) { 356 356 double result = code[instr.childIndex].value; 357 357 for (int j = 1; j < instr.nArguments; j++) { … … 360 360 } 361 361 instr.value = result > 0.0 ? 1.0 : -1.0; 362 } else if (instr.opCode == OpCode s.OR) {362 } else if (instr.opCode == OpCode.OR) { 363 363 double result = code[instr.childIndex].value; 364 364 for (int j = 1; j < instr.nArguments; j++) { … … 367 367 } 368 368 instr.value = result > 0.0 ? 1.0 : -1.0; 369 } else if (instr.opCode == OpCode s.NOT) {369 } else if (instr.opCode == OpCode.NOT) { 370 370 instr.value = code[instr.childIndex].value > 0.0 ? -1.0 : 1.0; 371 } else if (instr.opCode == OpCode s.XOR) {371 } else if (instr.opCode == OpCode.XOR) { 372 372 int positiveSignals = 0; 373 373 for (int j = 0; j < instr.nArguments; j++) { … … 375 375 } 376 376 instr.value = positiveSignals % 2 != 0 ? 1.0 : -1.0; 377 } else if (instr.opCode == OpCode s.GT) {377 } else if (instr.opCode == OpCode.GT) { 378 378 double x = code[instr.childIndex].value; 379 379 double y = code[instr.childIndex + 1].value; 380 380 instr.value = x > y ? 1.0 : -1.0; 381 } else if (instr.opCode == OpCode s.LT) {381 } else if (instr.opCode == OpCode.LT) { 382 382 double x = code[instr.childIndex].value; 383 383 double y = code[instr.childIndex + 1].value; 384 384 instr.value = x < y ? 1.0 : -1.0; 385 } else if (instr.opCode == OpCode s.TimeLag || instr.opCode == OpCodes.Derivative || instr.opCode == OpCodes.Integral) {385 } else if (instr.opCode == OpCode.TimeLag || instr.opCode == OpCode.Derivative || instr.opCode == OpCode.Integral) { 386 386 var state = (InterpreterState)instr.data; 387 387 state.Reset(); … … 415 415 #region opcode switch 416 416 switch (instr.opCode) { 417 case OpCode s.Constant: {417 case OpCode.Constant: { 418 418 var constTreeNode = (ConstantTreeNode)instr.dynamicNode; 419 419 instr.value = constTreeNode.Value; … … 421 421 } 422 422 break; 423 case OpCode s.Variable: {423 case OpCode.Variable: { 424 424 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 425 425 instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 426 426 } 427 427 break; 428 case OpCode s.BinaryFactorVariable: {428 case OpCode.BinaryFactorVariable: { 429 429 var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 430 430 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 431 431 } 432 432 break; 433 case OpCode s.FactorVariable: {433 case OpCode.FactorVariable: { 434 434 var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode; 435 435 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 436 436 } 437 437 break; 438 case OpCode s.LagVariable: {438 case OpCode.LagVariable: { 439 439 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 440 440 instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName); 441 441 } 442 442 break; 443 case OpCode s.VariableCondition: {443 case OpCode.VariableCondition: { 444 444 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 445 445 instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName); 446 446 } 447 447 break; 448 case OpCode s.TimeLag:449 case OpCode s.Integral:450 case OpCode s.Derivative: {448 case OpCode.TimeLag: 449 case OpCode.Integral: 450 case OpCode.Derivative: { 451 451 var seq = GetPrefixSequence(code, i); 452 452 var interpreterState = new InterpreterState(seq, 0); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r16565 r16899 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Runtime.InteropServices; 22 using HEAL.Attic; 26 23 using HeuristicLab.Common; 27 24 using HeuristicLab.Core; … … 29 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 27 using HeuristicLab.Parameters; 31 using HEAL.Attic; 28 using System; 29 using System.Collections.Generic; 30 using System.Linq; 31 using System.Runtime.InteropServices; 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 101 101 private IDataset dataset; 102 102 103 private static readonly HashSet<byte> supportedOpCodes = new HashSet<byte>() { 104 (byte)OpCode.Constant, 105 (byte)OpCode.Variable, 106 (byte)OpCode.Add, 107 (byte)OpCode.Sub, 108 (byte)OpCode.Mul, 109 (byte)OpCode.Div, 110 (byte)OpCode.Exp, 111 (byte)OpCode.Log, 112 (byte)OpCode.Sin, 113 (byte)OpCode.Cos, 114 (byte)OpCode.Tan, 115 (byte)OpCode.Tanh, 116 (byte)OpCode.Power, 117 (byte)OpCode.Root, 118 (byte)OpCode.SquareRoot, 119 (byte)OpCode.Square, 120 (byte)OpCode.CubeRoot, 121 (byte)OpCode.Cube, 122 (byte)OpCode.Absolute, 123 (byte)OpCode.AnalyticQuotient 124 }; 125 103 126 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 104 127 if (!rows.Any()) return Enumerable.Empty<double>(); … … 108 131 } 109 132 110 var code = Compile(tree, OpCodes.MapSymbolToOpCode); 133 byte mapSupportedSymbols(ISymbolicExpressionTreeNode node) { 134 var opCode = OpCode.MapSymbolToOpCode(node); 135 if (supportedOpCodes.Contains(opCode)) return opCode; 136 else throw new NotSupportedException($"The native interpreter does not support {node.Symbol.Name}"); 137 }; 138 var code = Compile(tree, mapSupportedSymbols); 111 139 112 140 var rowsArray = rows.ToArray(); -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Selectors/DiversitySelector.cs
r16722 r16899 100 100 #region Events 101 101 private void RegisterParameterEventHandlers() { 102 SelectorParameter.ValueChanged += new EventHandler(SelectorParameter_ValueChanged); 103 CopySelected.ValueChanged += new EventHandler(CopySelected_ValueChanged); 102 SelectorParameter.ValueChanged += SelectorParameter_ValueChanged; 103 CopySelectedParameter.ValueChanged += CopySelectedParameter_ValueChanged; 104 CopySelected.ValueChanged += CopySelected_ValueChanged; 105 } 106 107 private void CopySelectedParameter_ValueChanged(object sender, EventArgs e) { 108 if (CopySelected.Value != true) { 109 CopySelected.Value = true; 110 } 111 CopySelected.ValueChanged += CopySelected_ValueChanged; 104 112 } 105 113 -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs
r16565 r16899 35 35 if (node.Symbol is StartSymbol) node = node.GetSubtree(0); 36 36 37 switch (OpCode s.MapSymbolToOpCode(node)) {38 case OpCode s.Constant: {37 switch (OpCode.MapSymbolToOpCode(node)) { 38 case OpCode.Constant: { 39 39 return 1; 40 40 } 41 case OpCode s.Variable:42 case OpCode s.BinaryFactorVariable:43 case OpCode s.FactorVariable: {41 case OpCode.Variable: 42 case OpCode.BinaryFactorVariable: 43 case OpCode.FactorVariable: { 44 44 return 2; 45 45 } 46 case OpCode s.Add:47 case OpCode s.Sub: {46 case OpCode.Add: 47 case OpCode.Sub: { 48 48 double complexity = 0; 49 49 for (int i = 0; i < node.SubtreeCount; i++) { … … 52 52 return complexity; 53 53 } 54 case OpCode s.Mul:55 case OpCode s.Div: {54 case OpCode.Mul: 55 case OpCode.Div: { 56 56 double complexity = 1; 57 57 for (int i = 0; i < node.SubtreeCount; i++) { … … 61 61 return complexity; 62 62 } 63 case OpCode s.Sin:64 case OpCode s.Cos:65 case OpCode s.Tan:66 case OpCode s.Exp:67 case OpCode s.Log: {63 case OpCode.Sin: 64 case OpCode.Cos: 65 case OpCode.Tan: 66 case OpCode.Exp: 67 case OpCode.Log: { 68 68 double complexity = CalculateComplexity(node.GetSubtree(0)); 69 69 return Math.Pow(2.0, complexity); 70 70 } 71 case OpCode s.Square: {71 case OpCode.Square: { 72 72 double complexity = CalculateComplexity(node.GetSubtree(0)); 73 73 return complexity * complexity; 74 74 } 75 case OpCode s.SquareRoot: {75 case OpCode.SquareRoot: { 76 76 double complexity = CalculateComplexity(node.GetSubtree(0)); 77 77 return complexity * complexity * complexity; 78 78 } 79 case OpCode s.Power:80 case OpCode s.Root: {79 case OpCode.Power: 80 case OpCode.Root: { 81 81 double complexity = CalculateComplexity(node.GetSubtree(0)); 82 82 var exponent = node.GetSubtree(1) as ConstantTreeNode; -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ModelTreeNode.cs
r16734 r16899 57 57 private TreeModelTreeNode(TreeModelTreeNode original, Cloner cloner) 58 58 : base(original, cloner) { 59 tree = original.tree;59 tree = (ISymbolicExpressionTree)original.tree.Clone(cloner); 60 60 ClusterNumer = original.ClusterNumer; 61 61 TreeNumber = original.TreeNumber;
Note: See TracChangeset
for help on using the changeset viewer.