Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/16 18:54:14 (8 years ago)
Author:
gkronber
Message:

created a feature branch for #2650 (support for categorical variables in symb reg) with a first set of changes

work in progress...

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  
    8383    public const byte Erf = 43;
    8484    public const byte Bessel = 44;
     85    public const byte FactorVariable = 46;
    8586
    8687    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
     
    130131      { typeof(Norm), OpCodes.Norm},
    131132      { typeof(Erf), OpCodes.Erf},
    132       { typeof(Bessel), OpCodes.Bessel}   
     133      { typeof(Bessel), OpCodes.Bessel},
     134      { typeof(FactorVariable), OpCodes.FactorVariable }
    133135    };
    134136
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r14185 r14232  
    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)});
    6869    #endregion
    6970
     
    627628            return;
    628629          }
     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          }
    629664        case OpCodes.LagVariable: {
    630665            var nanResult = il.DefineLabel();
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r14185 r14232  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    143144          var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    144145          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);
    145149        } else if (instr.opCode == OpCodes.LagVariable) {
    146150          var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
     
    455459            return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight;
    456460          }
     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          }
    457466        case OpCodes.LagVariable: {
    458467            var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r14185 r14232  
    147147            var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    148148            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;
    149155          }
    150156        } else if (instr.opCode == OpCodes.LagVariable) {
     
    392398            }
    393399            break;
     400          case OpCodes.FactorVariable: {
     401              var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode;
     402              instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName);
     403            }
     404            break;
    394405          case OpCodes.LagVariable: {
    395406              var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
Note: See TracChangeset for help on using the changeset viewer.