Changeset 9826
- Timestamp:
- 07/31/13 12:51:01 (11 years ago)
- 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 31 31 public byte nArguments; 32 32 // an optional object value (addresses for calls, argument index for arguments) 33 public object iArg0;33 public object data; 34 34 } 35 35 } -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs
r9732 r9826 52 52 if (instr.dynamicNode.Symbol is InvokeFunction) { 53 53 var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode; 54 instr. iArg0= entryPoint[invokeNode.Symbol.FunctionName];54 instr.data = entryPoint[invokeNode.Symbol.FunctionName]; 55 55 } 56 56 } … … 68 68 if (node.Symbol is Argument) { 69 69 var argNode = (ArgumentTreeNode)node; 70 instr. iArg0= (ushort)argNode.Symbol.ArgumentIndex;70 instr.data = (ushort)argNode.Symbol.ArgumentIndex; 71 71 } 72 72 instr.dynamicNode = node; -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeLinearCompiler.cs
r9815 r9826 30 30 int c = 1, i = 0; 31 31 foreach (var node in root.IterateNodesBreadth()) { 32 for (int j = 0; j !=node.SubtreeCount; ++j) {32 for (int j = 0; j < node.SubtreeCount; ++j) { 33 33 var s = node.GetSubtree(j); 34 34 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 168 168 if (instr.opCode == OpCodes.Variable) { 169 169 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 170 instr. iArg0= doubleVariableNames[variableTreeNode.VariableName];170 instr.data = doubleVariableNames[variableTreeNode.VariableName]; 171 171 } else if (instr.opCode == OpCodes.LagVariable) { 172 172 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 173 instr. iArg0= doubleVariableNames[laggedVariableTreeNode.VariableName];173 instr.data = doubleVariableNames[laggedVariableTreeNode.VariableName]; 174 174 } else if (instr.opCode == OpCodes.VariableCondition) { 175 175 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 176 instr. iArg0= doubleVariableNames[variableConditionTreeNode.VariableName];176 instr.data = doubleVariableNames[variableConditionTreeNode.VariableName]; 177 177 } else if (instr.opCode == OpCodes.Call) { 178 178 necessaryArgStackSize += instr.nArguments + 1; … … 566 566 VariableTreeNode varNode = (VariableTreeNode)currentInstr.dynamicNode; 567 567 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); 569 569 // load correct column of the current variable 570 570 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); … … 600 600 LaggedVariableTreeNode varNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; 601 601 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); 603 603 // load correct column of the current variable 604 604 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r9776 r9826 117 117 if (instr.opCode == OpCodes.Variable) { 118 118 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 119 instr. iArg0= dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);119 instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 120 120 } else if (instr.opCode == OpCodes.LagVariable) { 121 121 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 122 instr. iArg0= dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);122 instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName); 123 123 } else if (instr.opCode == OpCodes.VariableCondition) { 124 124 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 125 instr. iArg0= dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);125 instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName); 126 126 } else if (instr.opCode == OpCodes.Call) { 127 127 necessaryArgStackSize += instr.nArguments + 1; … … 406 406 int savedPc = state.ProgramCounter; 407 407 // set pc to start of function 408 state.ProgramCounter = (ushort)currentInstr. iArg0;408 state.ProgramCounter = (ushort)currentInstr.data; 409 409 // evaluate the function 410 410 double v = Evaluate(dataset, ref row, state); … … 418 418 } 419 419 case OpCodes.Arg: { 420 return state.GetStackFrameValue((ushort)currentInstr. iArg0);420 return state.GetStackFrameValue((ushort)currentInstr.data); 421 421 } 422 422 case OpCodes.Variable: { 423 423 if (row < 0 || row >= dataset.Rows) return double.NaN; 424 424 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 425 return ((IList<double>)currentInstr. iArg0)[row] * variableTreeNode.Weight;425 return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight; 426 426 } 427 427 case OpCodes.LagVariable: { … … 429 429 int actualRow = row + laggedVariableTreeNode.Lag; 430 430 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; 432 432 } 433 433 case OpCodes.Constant: { … … 441 441 if (row < 0 || row >= dataset.Rows) return double.NaN; 442 442 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode; 443 double variableValue = ((IList<double>)currentInstr. iArg0)[row];443 double variableValue = ((IList<double>)currentInstr.data)[row]; 444 444 double x = variableValue - variableConditionTreeNode.Threshold; 445 445 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 137 137 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 138 138 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; 140 140 } 141 141 break; … … 146 146 instr.value = double.NaN; 147 147 else 148 instr.value = ((IList<double>)instr. iArg0)[actualRow] * laggedVariableTreeNode.Weight;148 instr.value = ((IList<double>)instr.data)[actualRow] * laggedVariableTreeNode.Weight; 149 149 } 150 150 break; … … 152 152 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 153 153 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 154 double variableValue = ((IList<double>)instr. iArg0)[row];154 double variableValue = ((IList<double>)instr.data)[row]; 155 155 double x = variableValue - variableConditionTreeNode.Threshold; 156 156 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); … … 412 412 case OpCodes.Integral: 413 413 case OpCodes.Derivative: { 414 var state = (InterpreterState)instr. iArg0;414 var state = (InterpreterState)instr.data; 415 415 state.Reset(); 416 416 instr.value = interpreter.Evaluate(dataset, ref row, state); … … 418 418 break; 419 419 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); 421 421 throw new NotSupportedException(errorText); 422 422 } … … 450 450 case OpCodes.Variable: { 451 451 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 452 instr. iArg0= dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);452 instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 453 453 } 454 454 break; 455 455 case OpCodes.LagVariable: { 456 456 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; 457 instr. iArg0= dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);457 instr.data = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName); 458 458 } 459 459 break; 460 460 case OpCodes.VariableCondition: { 461 461 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 462 instr. iArg0= dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);462 instr.data = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName); 463 463 } 464 464 break; … … 468 468 var seq = GetPrefixSequence(code, i); 469 469 var interpreterState = new InterpreterState(seq, 0); 470 instr. iArg0= interpreterState;470 instr.data = interpreterState; 471 471 for (int j = 1; j != seq.Length; ++j) 472 472 seq[j].skip = true;
Note: See TracChangeset
for help on using the changeset viewer.