Changeset 17367 for branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 11/22/19 16:31:11 (5 years ago)
- Location:
- branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r17180 r17367 79 79 CubeRoot = 51, 80 80 Tanh = 52, 81 VectorVariable = 53, 82 VectorAdd = 54, 83 VectorSub = 55, 84 VectorMul = 56, 85 VectorDiv = 57, 86 VectorSum = 58, 87 VectorAvg = 59 81 88 }; 82 89 public static class OpCodes { 83 90 // constants for API compatibility only 84 91 public const byte Add = (byte)OpCode.Add; 85 public const byte Sub = (byte)OpCode.Sub;86 public const byte Mul = (byte)OpCode.Mul;87 public const byte Div = (byte)OpCode.Div;88 public const byte Sin = (byte)OpCode.Sin;89 public const byte Cos = (byte)OpCode.Cos;90 public const byte Tan = (byte)OpCode.Tan;91 public const byte Log = (byte)OpCode.Log;92 public const byte Sub = (byte)OpCode.Sub; 93 public const byte Mul = (byte)OpCode.Mul; 94 public const byte Div = (byte)OpCode.Div; 95 public const byte Sin = (byte)OpCode.Sin; 96 public const byte Cos = (byte)OpCode.Cos; 97 public const byte Tan = (byte)OpCode.Tan; 98 public const byte Log = (byte)OpCode.Log; 92 99 public const byte Exp = (byte)OpCode.Exp; 93 100 public const byte IfThenElse = (byte)OpCode.IfThenElse; … … 134 141 public const byte CubeRoot = (byte)OpCode.CubeRoot; 135 142 public const byte Tanh = (byte)OpCode.Tanh; 143 public const byte VectorVariable = (byte)OpCode.VectorVariable; 144 public const byte VectorAdd = (byte)OpCode.VectorAdd; 145 public const byte VectorSub = (byte)OpCode.VectorSub; 146 public const byte VectorMul = (byte)OpCode.VectorMul; 147 public const byte VectorDiv = (byte)OpCode.VectorDiv; 148 public const byte VectorSum = (byte)OpCode.VectorSum; 149 public const byte VectorAvg = (byte)OpCode.VectorAvg; 136 150 137 151 138 152 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { 139 153 { typeof(Addition), OpCodes.Add }, 140 154 { typeof(Subtraction), OpCodes.Sub }, 141 155 { typeof(Multiplication), OpCodes.Mul }, … … 189 203 { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient }, 190 204 { typeof(Cube), OpCodes.Cube }, 191 { typeof(CubeRoot), OpCodes.CubeRoot } 205 { typeof(CubeRoot), OpCodes.CubeRoot }, 206 { typeof(VectorVariable), OpCodes.VectorVariable }, 207 { typeof(VectorAddition), OpCodes.VectorAdd }, 208 { typeof(VectorSubtraction), OpCodes.VectorSub }, 209 { typeof(VectorMultiplication), OpCodes.VectorMul }, 210 { typeof(VectorDivision), OpCodes.VectorDiv }, 211 { typeof(VectorSum), OpCodes.VectorSum }, 212 { typeof(VectorAverage), OpCodes.VectorAvg } 192 213 }; 193 214 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r17180 r17367 149 149 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 150 150 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 151 } else if (instr.opCode == OpCodes.VectorVariable) { 152 var vectorVariableTreeNode = (VectorVariableTreeNode)instr.dynamicNode; 153 instr.data = dataset.GetReadOnlyDoubleVectorValues(vectorVariableTreeNode.VariableName); 151 154 } else if (instr.opCode == OpCodes.LagVariable) { 152 155 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 528 531 } 529 532 } 533 534 case OpCodes.VectorSum: { 535 DoubleVector v = VectorEvaluate(dataset, ref row, state); 536 return v.Sum(); 537 } 538 case OpCodes.VectorAvg: { 539 DoubleVector v = VectorEvaluate(dataset, ref row, state); 540 return v.Average(); 541 } 542 530 543 default: 531 544 throw new NotSupportedException(); 532 545 } 533 546 } 547 548 public virtual DoubleVector VectorEvaluate(IDataset dataset, ref int row, InterpreterState state) { 549 Instruction currentInstr = state.NextInstruction(); 550 switch (currentInstr.opCode) { 551 case OpCodes.VectorAdd: { 552 DoubleVector s = VectorEvaluate(dataset, ref row, state); 553 for (int i = 1; i < currentInstr.nArguments; i++) { 554 s += Evaluate(dataset, ref row, state); 555 } 556 return s; 557 } 558 case OpCodes.VectorSub: { 559 DoubleVector s = VectorEvaluate(dataset, ref row, state); 560 for (int i = 1; i < currentInstr.nArguments; i++) { 561 s -= Evaluate(dataset, ref row, state); 562 } 563 return s; 564 } 565 case OpCodes.VectorMul: { 566 DoubleVector s = VectorEvaluate(dataset, ref row, state); 567 for (int i = 1; i < currentInstr.nArguments; i++) { 568 s *= Evaluate(dataset, ref row, state); 569 } 570 return s; 571 } 572 case OpCodes.VectorDiv: { 573 DoubleVector s = VectorEvaluate(dataset, ref row, state); 574 for (int i = 1; i < currentInstr.nArguments; i++) { 575 s /= Evaluate(dataset, ref row, state); 576 } 577 return s; 578 } 579 580 case OpCodes.VectorVariable: { 581 if (row < 0 || row >= dataset.Rows) return new DoubleVector(new[] { double.NaN }); 582 var vectorVarTreeNode = currentInstr.dynamicNode as VectorVariableTreeNode; 583 return ((IList<DoubleVector>)currentInstr.data)[row] * vectorVarTreeNode.Weight; 584 } 585 default: 586 throw new NotSupportedException(); 587 } 588 } 534 589 } 535 590 }
Note: See TracChangeset
for help on using the changeset viewer.