Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10774 for trunk/sources


Ignore:
Timestamp:
04/23/14 13:12:07 (11 years ago)
Author:
mkommend
Message:

#2177: Implemented XOR symbol and adapted the interpreters and grammars.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
1 added
6 edited

Legend:

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

    r9456 r10774  
    9999      var or = new Or();
    100100      var not = new Not();
     101      var xor = new Xor();
    101102
    102103      var timeLag = new TimeLag();
     
    122123      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, square, pow, sqrt, root, exp,
    123124        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
    124         @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable,autoregressiveVariable, variableCondition };
     125        @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, laggedVariable,autoregressiveVariable, variableCondition };
    125126      var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
    126127        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
     
    128129
    129130      var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, variableCondition };
    130       var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or };
     131      var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor };
    131132      var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable, autoregressiveVariable };
    132133
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r9992 r10774  
    9393      var or = new Or();
    9494      var not = new Not();
     95      var xor = new Xor();
    9596      var variableCondition = new VariableCondition();
    9697
     
    120121      var conditionSymbols = new GroupSymbol(ConditionsName, new List<ISymbol> { @if, variableCondition });
    121122      var comparisonSymbols = new GroupSymbol(ComparisonsName, new List<ISymbol> { gt, lt });
    122       var booleanOperationSymbols = new GroupSymbol(BooleanOperatorsName, new List<ISymbol> { and, or, not });
     123      var booleanOperationSymbols = new GroupSymbol(BooleanOperatorsName, new List<ISymbol> { and, or, not, xor });
    123124      var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols });
    124125
     
    148149      SetSubtreeCount(or, 2, 2);
    149150      SetSubtreeCount(not, 1, 1);
     151      SetSubtreeCount(xor, 2, 2);
    150152
    151153      SetSubtreeCount(timeLag, 1, 1);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r10562 r10774  
    186186    <Compile Include="Symbols\AiryB.cs" />
    187187    <Compile Include="Symbols\Bessel.cs" />
     188    <Compile Include="Symbols\Xor.cs" />
    188189    <Compile Include="Symbols\Erf.cs" />
    189190    <Compile Include="Symbols\Norm.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r9456 r10774  
    4646    public const byte OR = 14;
    4747    public const byte NOT = 15;
     48    public const byte XOR = 45;
    4849
    4950
     
    99100      { typeof(Or), OpCodes.OR },
    100101      { typeof(Not), OpCodes.NOT},
     102      { typeof(Xor),OpCodes.XOR},
    101103      { typeof(Average), OpCodes.Average},
    102104      { typeof(InvokeFunction), OpCodes.Call },
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r9828 r10774  
    344344            return Evaluate(dataset, ref row, state) > 0.0 ? -1.0 : 1.0;
    345345          }
     346        case OpCodes.XOR: {
     347            double firstArgument = Evaluate(dataset, ref row, state);
     348            double result = 1.0;
     349            for (int i = 1; i < currentInstr.nArguments; i++) {
     350              if (result <= 0.0) {
     351                state.SkipInstructions();
     352              } else {
     353                double evalutationResult = Evaluate(dataset, ref row, state);
     354                if (firstArgument <= 0 && evalutationResult > 0) result = -1.0;
     355                else if (firstArgument > 0 && evalutationResult <= 0) result = -1.0;
     356              }
     357            }
     358            return result > 0.0 ? 1.0 : -1.0;
     359          }
    346360        case OpCodes.GT: {
    347361            double x = Evaluate(dataset, ref row, state);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r9944 r10774  
    311311        } else if (instr.opCode == OpCodes.NOT) {
    312312          instr.value = code[instr.childIndex].value > 0.0 ? -1.0 : 1.0;
     313        } else if (instr.opCode == OpCodes.XOR) {
     314          double firstArgument = code[instr.childIndex].value;
     315          instr.value = 1.0;
     316          for (int j = 1; j < instr.nArguments; j++) {
     317            if (instr.value > 0.0) {
     318              if (firstArgument <= 0 && code[instr.childIndex + j].value > 0) instr.value = -1.0;
     319              if (firstArgument > 0 && code[instr.childIndex + j].value <= 0) instr.value = -1.0;
     320            } else break;
     321          }
     322          instr.value = instr.value > 0.0 ? 1.0 : -1.0;
    313323        } else if (instr.opCode == OpCodes.GT) {
    314324          double x = code[instr.childIndex].value;
Note: See TracChangeset for help on using the changeset viewer.