Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9826


Ignore:
Timestamp:
07/31/13 12:51:01 (11 years ago)
Author:
mkommend
Message:

#2021: Minor code changes in the linear interpreter branch.

Location:
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/Instruction.cs

    r9738 r9826  
    3131    public byte nArguments;
    3232    // an optional object value (addresses for calls, argument index for arguments)
    33     public object iArg0;
     33    public object data;
    3434  }
    3535}
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs

    r9732 r9826  
    5252        if (instr.dynamicNode.Symbol is InvokeFunction) {
    5353          var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode;
    54           instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName];
     54          instr.data = entryPoint[invokeNode.Symbol.FunctionName];
    5555        }
    5656      }
     
    6868        if (node.Symbol is Argument) {
    6969          var argNode = (ArgumentTreeNode)node;
    70           instr.iArg0 = (ushort)argNode.Symbol.ArgumentIndex;
     70          instr.data = (ushort)argNode.Symbol.ArgumentIndex;
    7171        }
    7272        instr.dynamicNode = node;
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeLinearCompiler.cs

    r9815 r9826  
    3030      int c = 1, i = 0;
    3131      foreach (var node in root.IterateNodesBreadth()) {
    32         for (int j = 0; j != node.SubtreeCount; ++j) {
     32        for (int j = 0; j < node.SubtreeCount; ++j) {
    3333          var s = node.GetSubtree(j);
    3434          code[c + j] = new LinearInstruction { dynamicNode = s, nArguments = (byte)s.SubtreeCount, opCode = opCodeMapper(s) };
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r9733 r9826  
    168168        if (instr.opCode == OpCodes.Variable) {
    169169          var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    170           instr.iArg0 = doubleVariableNames[variableTreeNode.VariableName];
     170          instr.data = doubleVariableNames[variableTreeNode.VariableName];
    171171        } else if (instr.opCode == OpCodes.LagVariable) {
    172172          var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
    173           instr.iArg0 = doubleVariableNames[laggedVariableTreeNode.VariableName];
     173          instr.data = doubleVariableNames[laggedVariableTreeNode.VariableName];
    174174        } else if (instr.opCode == OpCodes.VariableCondition) {
    175175          var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;
    176           instr.iArg0 = doubleVariableNames[variableConditionTreeNode.VariableName];
     176          instr.data = doubleVariableNames[variableConditionTreeNode.VariableName];
    177177        } else if (instr.opCode == OpCodes.Call) {
    178178          necessaryArgStackSize += instr.nArguments + 1;
     
    566566            VariableTreeNode varNode = (VariableTreeNode)currentInstr.dynamicNode;
    567567            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
    568             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);
     568            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.data);
    569569            // load correct column of the current variable
    570570            il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
     
    600600            LaggedVariableTreeNode varNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
    601601            il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array
    602             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);
     602            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.data);
    603603            // load correct column of the current variable
    604604            il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r9776 r9826  
    117117        if (instr.opCode == OpCodes.Variable) {
    118118          var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    119           instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);
     119          instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);
    120120        } else if (instr.opCode == OpCodes.LagVariable) {
    121121          var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
    122           instr.iArg0 = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);
     122          instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);
    123123        } else if (instr.opCode == OpCodes.VariableCondition) {
    124124          var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;
    125           instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);
     125          instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);
    126126        } else if (instr.opCode == OpCodes.Call) {
    127127          necessaryArgStackSize += instr.nArguments + 1;
     
    406406            int savedPc = state.ProgramCounter;
    407407            // set pc to start of function 
    408             state.ProgramCounter = (ushort)currentInstr.iArg0;
     408            state.ProgramCounter = (ushort)currentInstr.data;
    409409            // evaluate the function
    410410            double v = Evaluate(dataset, ref row, state);
     
    418418          }
    419419        case OpCodes.Arg: {
    420             return state.GetStackFrameValue((ushort)currentInstr.iArg0);
     420            return state.GetStackFrameValue((ushort)currentInstr.data);
    421421          }
    422422        case OpCodes.Variable: {
    423423            if (row < 0 || row >= dataset.Rows) return double.NaN;
    424424            var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
    425             return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight;
     425            return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight;
    426426          }
    427427        case OpCodes.LagVariable: {
     
    429429            int actualRow = row + laggedVariableTreeNode.Lag;
    430430            if (actualRow < 0 || actualRow >= dataset.Rows) return double.NaN;
    431             return ((IList<double>)currentInstr.iArg0)[actualRow] * laggedVariableTreeNode.Weight;
     431            return ((IList<double>)currentInstr.data)[actualRow] * laggedVariableTreeNode.Weight;
    432432          }
    433433        case OpCodes.Constant: {
     
    441441            if (row < 0 || row >= dataset.Rows) return double.NaN;
    442442            var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode;
    443             double variableValue = ((IList<double>)currentInstr.iArg0)[row];
     443            double variableValue = ((IList<double>)currentInstr.data)[row];
    444444            double x = variableValue - variableConditionTreeNode.Threshold;
    445445            double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
  • branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r9818 r9826  
    137137              if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
    138138              var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    139               instr.value = ((IList<double>)instr.iArg0)[row] * variableTreeNode.Weight;
     139              instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight;
    140140            }
    141141            break;
     
    146146                instr.value = double.NaN;
    147147              else
    148                 instr.value = ((IList<double>)instr.iArg0)[actualRow] * laggedVariableTreeNode.Weight;
     148                instr.value = ((IList<double>)instr.data)[actualRow] * laggedVariableTreeNode.Weight;
    149149            }
    150150            break;
     
    152152              if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
    153153              var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;
    154               double variableValue = ((IList<double>)instr.iArg0)[row];
     154              double variableValue = ((IList<double>)instr.data)[row];
    155155              double x = variableValue - variableConditionTreeNode.Threshold;
    156156              double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
     
    412412          case OpCodes.Integral:
    413413          case OpCodes.Derivative: {
    414               var state = (InterpreterState)instr.iArg0;
     414              var state = (InterpreterState)instr.data;
    415415              state.Reset();
    416416              instr.value = interpreter.Evaluate(dataset, ref row, state);
     
    418418            break;
    419419          default:
    420             var errorText = string.Format("The {0} symbol is not supported by the linear interpreter. To support this symbol, please use another interpreter.", instr.dynamicNode.Symbol.Name);
     420            var errorText = string.Format("The {0} symbol is not supported by the linear interpreter. To support this symbol, please use the SymbolicDataAnalysisExpressionTreeInterpreter.", instr.dynamicNode.Symbol.Name);
    421421            throw new NotSupportedException(errorText);
    422422        }
     
    450450          case OpCodes.Variable: {
    451451              var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    452               instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);
     452              instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);
    453453            }
    454454            break;
    455455          case OpCodes.LagVariable: {
    456456              var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
    457               instr.iArg0 = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);
     457              instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);
    458458            }
    459459            break;
    460460          case OpCodes.VariableCondition: {
    461461              var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;
    462               instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);
     462              instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);
    463463            }
    464464            break;
     
    468468              var seq = GetPrefixSequence(code, i);
    469469              var interpreterState = new InterpreterState(seq, 0);
    470               instr.iArg0 = interpreterState;
     470              instr.data = interpreterState;
    471471              for (int j = 1; j != seq.Length; ++j)
    472472                seq[j].skip = true;
Note: See TracChangeset for help on using the changeset viewer.