Ignore:
Timestamp:
12/07/10 14:11:12 (11 years ago)
Author:
mkommend
Message:

Implemented VariableCondition symbol (ticket #1325).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r5052 r5060  
    7171      public const byte Integral = 23;
    7272      public const byte Derivative = 24;
     73
     74      public const byte VariableCondition = 25;
    7375    }
    7476
     
    9799      { typeof(TimeLag), OpCodes.TimeLag},
    98100      { typeof(Integral), OpCodes.Integral},
    99       { typeof(Derivative), OpCodes.Derivative}
     101      { typeof(Derivative), OpCodes.Derivative},
     102      { typeof(VariableCondition),OpCodes.VariableCondition}
    100103    };
    101104    private const int ARGUMENT_STACK_SIZE = 1024;
     
    147150        var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode;
    148151        instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);
     152      } else if (instr.opCode == OpCodes.VariableCondition) {
     153        var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode;
     154        instr.iArg0 = (ushort)dataset.GetVariableIndex(variableConditionTreeNode.VariableName);
    149155      }
    150156      return instr;
     
    344350            return (f_0 + 2 * f_1 - 2 * f_3 - f_4) / 8; // h = 1
    345351          }
     352
     353        //mkommend: this symbol uses the logistic function f(x) = 1 / (1 + e^(-alpha * x) )
     354        //to determine the relative amounts of the true and false branch see http://en.wikipedia.org/wiki/Logistic_function
     355        case OpCodes.VariableCondition: {
     356            var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode;
     357            double variableValue = dataset[row, currentInstr.iArg0];
     358            double x = variableValue - variableConditionTreeNode.Threshold;
     359            double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
     360
     361            double trueBranch = Evaluate();
     362            double falseBranch = Evaluate();
     363
     364            return trueBranch * p + falseBranch * (1 - p);
     365          }
    346366        default: throw new NotSupportedException();
    347367      }
Note: See TracChangeset for help on using the changeset viewer.