Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/09/16 15:34:33 (8 years ago)
Author:
gkronber
Message:

#2650 added new symbol FactorVariable (renamed previous symbol to BinaryFactorVariable)
Work in progress.

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  
    8484    public const byte Bessel = 44;
    8585    public const byte FactorVariable = 46;
     86    public const byte BinaryFactorVariable = 47;
     87
    8688
    8789    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
     
    132134      { typeof(Erf), OpCodes.Erf},
    133135      { typeof(Bessel), OpCodes.Bessel},
    134       { typeof(BinaryFactorVariable), OpCodes.FactorVariable }
     136      { typeof(FactorVariable), OpCodes.FactorVariable },
     137      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable }
    135138    };
    136139
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r14243 r14249  
    6666    private static MethodInfo erf = thisType.GetMethod("Erf", new Type[] { typeof(double) });
    6767    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) });
    6969    #endregion
    7070
     
    628628            return;
    629629          }
    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();
    665633          }
    666634        case OpCodes.LagVariable: {
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r14243 r14249  
    146146        } else if (instr.opCode == OpCodes.FactorVariable) {
    147147          var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;
    148           instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 
     148          instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName);
    149149        } else if (instr.opCode == OpCodes.LagVariable) {
    150150          var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
     
    459459            return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight;
    460460          }
    461         case OpCodes.FactorVariable: {
     461        case OpCodes.BinaryFactorVariable: {
    462462            if (row < 0 || row >= dataset.Rows) return double.NaN;
    463463            var factorVarTreeNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode;
    464464            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]);
    465470          }
    466471        case OpCodes.LagVariable: {
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r14243 r14249  
    148148            instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight;
    149149          }
     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          }
    150156        } else if (instr.opCode == OpCodes.FactorVariable) {
    151157          if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
    152158          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]);
    155161          }
    156162        } else if (instr.opCode == OpCodes.LagVariable) {
     
    398404            }
    399405            break;
     406          case OpCodes.BinaryFactorVariable: {
     407              var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;
     408              instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName);
     409            }
     410            break;
    400411          case OpCodes.FactorVariable: {
    401               var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;
     412              var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode;
    402413              instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName);
    403414            }
Note: See TracChangeset for help on using the changeset viewer.