Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6860


Ignore:
Timestamp:
10/03/11 17:28:53 (13 years ago)
Author:
gkronber
Message:

#1480 reverse merged changes to SymbolicDataAnalysisExpressionTreeInterpreter.cs in r6849 as there were no performance improvements observable for this interpreter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r6849 r6860  
    132132
    133133      public const byte VariableCondition = 27;
    134 
    135       public const byte UncheckedVariable = 28;
    136       public const byte UncheckedVariableCondition = 29;
    137134    }
    138135    #endregion
    139136
    140     private Dictionary<Type, byte> symbolToUncheckedOpcode = new Dictionary<Type, byte>() {
    141       { typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Variable), OpCodes.UncheckedVariable },
    142       { typeof(VariableCondition),OpCodes.UncheckedVariableCondition}
    143     };
    144137    private Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
    145138      { typeof(Addition), OpCodes.Add },
     
    213206      for (int i = 0; i < code.Length; i++) {
    214207        Instruction instr = code[i];
    215         if (instr.opCode == OpCodes.Variable || instr.opCode == OpCodes.UncheckedVariable) {
     208        if (instr.opCode == OpCodes.Variable) {
    216209          var variableTreeNode = instr.dynamicNode as VariableTreeNode;
    217210          instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);
     
    221214          instr.iArg0 = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName);
    222215          code[i] = instr;
    223         } else if (instr.opCode == OpCodes.VariableCondition || instr.opCode == OpCodes.UncheckedVariableCondition) {
     216        } else if (instr.opCode == OpCodes.VariableCondition) {
    224217          var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode;
    225218          instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName);
     
    417410            return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight;
    418411          }
    419         case OpCodes.UncheckedVariable: {
    420             var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
    421             return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight;
    422           }
    423412        case OpCodes.LagVariable: {
    424413            var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
     
    448437            return trueBranch * p + falseBranch * (1 - p);
    449438          }
    450         case OpCodes.UncheckedVariableCondition: {
    451             var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode;
    452             double variableValue = ((IList<double>)currentInstr.iArg0)[row];
    453             double x = variableValue - variableConditionTreeNode.Threshold;
    454             double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
    455 
    456             double trueBranch = Evaluate(dataset, ref row, state);
    457             double falseBranch = Evaluate(dataset, ref row, state);
    458 
    459             return trueBranch * p + falseBranch * (1 - p);
    460           }
    461439        default: throw new NotSupportedException();
    462440      }
     
    464442
    465443    private byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
    466       if ((treeNode.Symbol.GetType() == typeof(Variable) || treeNode.Symbol.GetType() == typeof(VariableCondition)) && !InLaggedContext(treeNode)) {
    467         return symbolToUncheckedOpcode[treeNode.Symbol.GetType()];
    468       } else {
    469         if (symbolToOpcode.ContainsKey(treeNode.Symbol.GetType()))
    470           return symbolToOpcode[treeNode.Symbol.GetType()];
    471         else
    472           throw new NotSupportedException("Symbol: " + treeNode.Symbol);
    473       }
    474     }
    475 
    476     private bool InLaggedContext(ISymbolicExpressionTreeNode treeNode) {
    477       if (treeNode.Parent == null) return false;
    478       if (treeNode.Parent is ILaggedTreeNode) return true;
    479       if (treeNode.Parent.Symbol is Derivative) return true;
    480       return InLaggedContext(treeNode.Parent);
     444      if (symbolToOpcode.ContainsKey(treeNode.Symbol.GetType()))
     445        return symbolToOpcode[treeNode.Symbol.GetType()];
     446      else
     447        throw new NotSupportedException("Symbol: " + treeNode.Symbol);
    481448    }
    482449
Note: See TracChangeset for help on using the changeset viewer.