Changeset 14249 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 08/09/16 15:34:33 (8 years ago)
- Location:
- branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r14243 r14249 84 84 public const byte Bessel = 44; 85 85 public const byte FactorVariable = 46; 86 public const byte BinaryFactorVariable = 47; 87 86 88 87 89 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { … … 132 134 { typeof(Erf), OpCodes.Erf}, 133 135 { typeof(Bessel), OpCodes.Bessel}, 134 { typeof(BinaryFactorVariable), OpCodes.FactorVariable } 136 { typeof(FactorVariable), OpCodes.FactorVariable }, 137 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable } 135 138 }; 136 139 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r14243 r14249 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 private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] { typeof(string) }); 69 69 #endregion 70 70 … … 628 628 return; 629 629 } 630 case OpCodes.FactorVariable: { 631 BinaryFactorVariableTreeNode varNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode; 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 throw new NotSupportedException(); 642 // TODO: convert bool to 1 / 0? 643 } else { 644 var nanResult = il.DefineLabel(); 645 var normalResult = il.DefineLabel(); 646 il.Emit(System.Reflection.Emit.OpCodes.Dup); 647 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); 648 il.Emit(System.Reflection.Emit.OpCodes.Blt, nanResult); 649 il.Emit(System.Reflection.Emit.OpCodes.Dup); 650 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows); 651 il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult); 652 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 653 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 654 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 655 throw new NotSupportedException(); 656 // TODO: convert bool to 1 / 0? 657 il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult); 658 il.MarkLabel(nanResult); 659 il.Emit(System.Reflection.Emit.OpCodes.Pop); // rowIndex 660 il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference 661 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN); 662 il.MarkLabel(normalResult); 663 } 664 return; 630 case OpCodes.FactorVariable: 631 case OpCodes.BinaryFactorVariable: { 632 throw new NotSupportedException(); 665 633 } 666 634 case OpCodes.LagVariable: { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r14243 r14249 146 146 } else if (instr.opCode == OpCodes.FactorVariable) { 147 147 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 148 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 148 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 149 149 } else if (instr.opCode == OpCodes.LagVariable) { 150 150 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 459 459 return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight; 460 460 } 461 case OpCodes. FactorVariable: {461 case OpCodes.BinaryFactorVariable: { 462 462 if (row < 0 || row >= dataset.Rows) return double.NaN; 463 463 var factorVarTreeNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode; 464 464 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? factorVarTreeNode.Weight : 0; 465 } 466 case OpCodes.FactorVariable: { 467 if (row < 0 || row >= dataset.Rows) return double.NaN; 468 var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode; 469 return factorVarTreeNode.GetValue(((IList<string>)currentInstr.data)[row]); 465 470 } 466 471 case OpCodes.LagVariable: { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r14243 r14249 148 148 instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight; 149 149 } 150 } else if (instr.opCode == OpCodes.BinaryFactorVariable) { 151 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 152 else { 153 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0; 155 } 150 156 } else if (instr.opCode == OpCodes.FactorVariable) { 151 157 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 152 158 else { 153 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0;159 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 160 instr.value = factorTreeNode.GetValue(((IList<string>)instr.data)[row]); 155 161 } 156 162 } else if (instr.opCode == OpCodes.LagVariable) { … … 398 404 } 399 405 break; 406 case OpCodes.BinaryFactorVariable: { 407 var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 408 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 409 } 410 break; 400 411 case OpCodes.FactorVariable: { 401 var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;412 var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode; 402 413 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 403 414 }
Note: See TracChangeset
for help on using the changeset viewer.