Changeset 14232 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 08/03/16 18:54:14 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r14185 r14232 83 83 public const byte Erf = 43; 84 84 public const byte Bessel = 44; 85 public const byte FactorVariable = 46; 85 86 86 87 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { … … 130 131 { typeof(Norm), OpCodes.Norm}, 131 132 { typeof(Erf), OpCodes.Erf}, 132 { typeof(Bessel), OpCodes.Bessel} 133 { typeof(Bessel), OpCodes.Bessel}, 134 { typeof(FactorVariable), OpCodes.FactorVariable } 133 135 }; 134 136 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r14185 r14232 66 66 private static MethodInfo erf = thisType.GetMethod("Erf", new Type[] { typeof(double) }); 67 67 private static MethodInfo bessel = thisType.GetMethod("Bessel", new Type[] { typeof(double) }); 68 private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] {typeof(string)}); 68 69 #endregion 69 70 … … 627 628 return; 628 629 } 630 case OpCodes.FactorVariable: { 631 FactorVariableTreeNode varNode = currentInstr.dynamicNode as FactorVariableTreeNode; 632 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array 633 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.data); 634 // load correct column of the current variable 635 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 636 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 637 if (!state.InLaggedContext) { 638 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 639 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 640 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 641 // TODO: convert bool to 1 / 0? 642 } else { 643 var nanResult = il.DefineLabel(); 644 var normalResult = il.DefineLabel(); 645 il.Emit(System.Reflection.Emit.OpCodes.Dup); 646 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); 647 il.Emit(System.Reflection.Emit.OpCodes.Blt, nanResult); 648 il.Emit(System.Reflection.Emit.OpCodes.Dup); 649 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows); 650 il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult); 651 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 652 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 653 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 654 // TODO: convert bool to 1 / 0? 655 il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult); 656 il.MarkLabel(nanResult); 657 il.Emit(System.Reflection.Emit.OpCodes.Pop); // rowIndex 658 il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference 659 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN); 660 il.MarkLabel(normalResult); 661 } 662 return; 663 } 629 664 case OpCodes.LagVariable: { 630 665 var nanResult = il.DefineLabel(); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r14185 r14232 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 143 144 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 144 145 instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 146 } else if (instr.opCode == OpCodes.FactorVariable) { 147 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 148 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 145 149 } else if (instr.opCode == OpCodes.LagVariable) { 146 150 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 455 459 return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight; 456 460 } 461 case OpCodes.FactorVariable: { 462 if (row < 0 || row >= dataset.Rows) return double.NaN; 463 var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode; 464 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? 1 : 0; 465 } 457 466 case OpCodes.LagVariable: { 458 467 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r14185 r14232 147 147 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 148 148 instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight; 149 } 150 } else if (instr.opCode == OpCodes.FactorVariable) { 151 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 152 else { 153 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? 1 : 0; 149 155 } 150 156 } else if (instr.opCode == OpCodes.LagVariable) { … … 392 398 } 393 399 break; 400 case OpCodes.FactorVariable: { 401 var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode; 402 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 403 } 404 break; 394 405 case OpCodes.LagVariable: { 395 406 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
Note: See TracChangeset
for help on using the changeset viewer.