Changeset 16238


Ignore:
Timestamp:
10/18/18 15:29:59 (3 years ago)
Author:
gkronber
Message:

#2915: implemented all symbols in all interpreters

Location:
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r16236 r16238  
    5959      var square = new Square();
    6060      square.InitialFrequency = 0.0;
     61      var cube = new Cube();
     62      cube.InitialFrequency = 0.0;
    6163      var root = new Root();
    6264      root.InitialFrequency = 0.0;
    6365      var sqrt = new SquareRoot();
    6466      sqrt.InitialFrequency = 0.0;
     67      var cubeRoot = new CubeRoot();
     68      cubeRoot.InitialFrequency = 0.0;
    6569      var airyA = new AiryA();
    6670      airyA.InitialFrequency = 0.0;
     
    125129      autoregressiveVariable.Enabled = false;
    126130
    127       var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, pow, sqrt, root, exp,
     131      var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp,
    128132        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
    129133        @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };
    130       var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
     134      var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
    131135        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
    132136      };
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r15944 r16238  
    6969      var root = new Root();
    7070      var sqrt = new SquareRoot();
     71      var cube = new Cube();
     72      var cubeRoot = new CubeRoot();
    7173      var exp = new Exponential();
    7274      var abs = new Absolute();
     
    8789      var psi = new Psi();
    8890      var sineIntegral = new SineIntegral();
     91      var analyticalQuotient = new AnalyticalQuotient();
    8992
    9093      var @if = new IfThenElse();
     
    112115
    113116      #region group symbol declaration
    114       var arithmeticSymbols = new GroupSymbol(ArithmeticFunctionsName, new List<ISymbol>() { add, sub, mul, div, mean, abs });
     117      var arithmeticSymbols = new GroupSymbol(ArithmeticFunctionsName, new List<ISymbol>() { add, sub, mul, div, mean });
    115118      var trigonometricSymbols = new GroupSymbol(TrigonometricFunctionsName, new List<ISymbol>() { sin, cos, tan });
    116119      var exponentialAndLogarithmicSymbols = new GroupSymbol(ExponentialFunctionsName, new List<ISymbol> { exp, log });
    117       var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi,
    118         fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral});
     120      var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { abs, airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi,
     121        fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral, analyticalQuotient});
    119122      var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol, binFactorVariable, factorVariable });
    120123      var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols });
    121124
    122       var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { square, pow, sqrt, root });
     125      var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { square, pow, sqrt, root, cube, cubeRoot });
    123126
    124127      var conditionSymbols = new GroupSymbol(ConditionsName, new List<ISymbol> { @if, variableCondition });
     
    141144      SetSubtreeCount(root, 2, 2);
    142145      SetSubtreeCount(square, 1, 1);
     146      SetSubtreeCount(cube, 1, 1);
    143147      SetSubtreeCount(sqrt, 1, 1);
     148      SetSubtreeCount(cubeRoot, 1, 1);
    144149      SetSubtreeCount(exponentialAndLogarithmicSymbols, 1, 1);
    145       SetSubtreeCount(specialFunctions, 1, 1);
     150      foreach(var sy in specialFunctions.Symbols.Except(new[] { analyticalQuotient})) {
     151        SetSubtreeCount(sy, 1, 1);
     152      }
     153      SetSubtreeCount(analyticalQuotient, 2, 2);
     154
    146155      SetSubtreeCount(terminalSymbols, 0, 0);
    147156
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r16236 r16238  
    209209    <Compile Include="Symbols\BinaryFactorVariableTreeNode.cs" />
    210210    <Compile Include="Symbols\AnalyticalQuotient.cs" />
     211    <Compile Include="Symbols\Cube.cs" />
    211212    <Compile Include="Symbols\FactorVariableTreeNode.cs" />
    212213    <Compile Include="Symbols\FactorVariable.cs" />
    213214    <Compile Include="Symbols\Absolute.cs" />
     215    <Compile Include="Symbols\CubeRoot.cs" />
    214216    <Compile Include="Symbols\VariableBase.cs" />
    215217    <Compile Include="Symbols\VariableTreeNodeBase.cs" />
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r16237 r16238  
    8787    public const byte Absolute = 48;
    8888    public const byte AnalyticalQuotient = 49;
     89    public const byte Cube = 50;
     90    public const byte CubeRoot = 51;
    8991
    9092
     
    138140      { typeof(FactorVariable), OpCodes.FactorVariable },
    139141      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
    140       { typeof(Absolute), OpCodes.Absolute },
    141       { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient }
     142      { typeof(Absolute), OpCodes.Absolute },
     143      { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient },
     144      { typeof(Cube), OpCodes.Cube },
     145      { typeof(CubeRoot), OpCodes.CubeRoot }
    142146    };
    143147
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r15583 r16238  
    4141
    4242    #region method info for the commonly called functions
     43    private static readonly MethodInfo Abs = typeof(Math).GetMethod("Abs", new[] { typeof(double) });
    4344    private static readonly MethodInfo Sin = typeof(Math).GetMethod("Sin", new[] { typeof(double) });
    4445    private static readonly MethodInfo Cos = typeof(Math).GetMethod("Cos", new[] { typeof(double) });
     
    207208            return Expression.Divide(result, Expression.Constant((double)node.SubtreeCount));
    208209          }
     210        case OpCodes.Absolute: {
     211            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
     212            return Expression.Call(Abs, arg);
     213          }
    209214        case OpCodes.Cos: {
    210215            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
     
    222227            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
    223228            return Expression.Power(arg, Expression.Constant(2.0));
     229          }
     230        case OpCodes.Cube: {
     231            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
     232            return Expression.Power(arg, Expression.Constant(3.0));
    224233          }
    225234        case OpCodes.Power: {
     
    231240            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
    232241            return Expression.Call(Sqrt, arg);
     242          }
     243        case OpCodes.CubeRoot: {
     244            var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
     245            return Expression.Power(arg, Expression.Constant(1.0 / 3.0));
    233246          }
    234247        case OpCodes.Root: {
     
    493506                Expression.Assign(result, Expression.Call(Bessel, arg))),
    494507              result);
     508          }
     509        case OpCodes.AnalyticalQuotient: {
     510            var x1 = MakeExpr(node.GetSubtree(0), variableIndices, row, columns);
     511            var x2 = MakeExpr(node.GetSubtree(1), variableIndices, row, columns);
     512            return Expression.Divide(x1,
     513              Expression.Call(Sqrt,
     514              Expression.Add(
     515                Expression.Constant(1.0),
     516                Expression.Multiply(x2, x2))));
    495517          }
    496518        case OpCodes.IfThenElse: {
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r15583 r16238  
    5050    private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) });
    5151    private static MethodInfo sqrt = typeof(Math).GetMethod("Sqrt", new Type[] { typeof(double) });
     52    private static MethodInfo abs = typeof(Math).GetMethod("Abs", new Type[] { typeof(double) });
    5253
    5354    private static MethodInfo airyA = thisType.GetMethod("AiryA", new Type[] { typeof(double) });
     
    264265            return;
    265266          }
     267        case OpCodes.Absolute: {
     268            CompileInstructions(il, state, ds);
     269            il.Emit(System.Reflection.Emit.OpCodes.Call, abs);
     270            return;
     271          }
    266272        case OpCodes.Cos: {
    267273            CompileInstructions(il, state, ds);
     
    311317            return;
    312318          }
     319        case OpCodes.Cube: {
     320            CompileInstructions(il, state, ds);
     321            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 3.0);
     322            il.Emit(System.Reflection.Emit.OpCodes.Call, power);
     323            return;
     324          }
    313325        case OpCodes.SquareRoot: {
    314326            CompileInstructions(il, state, ds);
     
    316328            return;
    317329          }
     330        case OpCodes.CubeRoot: {
     331            CompileInstructions(il, state, ds);
     332            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0 / 3.0);
     333            il.Emit(System.Reflection.Emit.OpCodes.Call, power);
     334            return;
     335          }
    318336        case OpCodes.AiryA: {
    319337            CompileInstructions(il, state, ds);
     
    389407            CompileInstructions(il, state, ds);
    390408            il.Emit(System.Reflection.Emit.OpCodes.Call, sinIntegral);
     409            return;
     410          }
     411        case OpCodes.AnalyticalQuotient: {
     412            CompileInstructions(il, state, ds); // x1
     413            CompileInstructions(il, state, ds); // x2
     414
     415            il.Emit(System.Reflection.Emit.OpCodes.Dup);
     416            il.Emit(System.Reflection.Emit.OpCodes.Mul); // x2*x2
     417            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0);
     418            il.Emit(System.Reflection.Emit.OpCodes.Mul); // 1+x2*x2
     419            il.Emit(System.Reflection.Emit.OpCodes.Call, sqrt);
     420            il.Emit(System.Reflection.Emit.OpCodes.Div);
    391421            return;
    392422          }
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r15944 r16238  
    218218            return Math.Pow(Evaluate(dataset, ref row, state), 2);
    219219          }
     220        case OpCodes.Cube: {
     221            return Math.Pow(Evaluate(dataset, ref row, state), 3);
     222          }
    220223        case OpCodes.Power: {
    221224            double x = Evaluate(dataset, ref row, state);
     
    226229            return Math.Sqrt(Evaluate(dataset, ref row, state));
    227230          }
     231        case OpCodes.CubeRoot: {
     232            return Math.Pow(Evaluate(dataset, ref row, state), 1.0 / 3.0);
     233          }
    228234        case OpCodes.Root: {
    229235            double x = Evaluate(dataset, ref row, state);
     
    343349            if (double.IsNaN(x)) return double.NaN;
    344350            else return alglib.besseli0(x);
     351          }
     352
     353        case OpCodes.AnalyticalQuotient: {
     354            var x1 = Evaluate(dataset, ref row, state);
     355            var x2 = Evaluate(dataset, ref row, state);
     356            return x1 / Math.Pow(1 + x2 * x2, 0.5);
    345357          }
    346358        case OpCodes.IfThenElse: {
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r16236 r16238  
    233233        } else if (instr.opCode == OpCodes.Tan) {
    234234          instr.value = Math.Tan(code[instr.childIndex].value);
    235         } else if (instr.opCode == OpCodes.Square) {
     235        } else if(instr.opCode == OpCodes.Square) {
    236236          instr.value = Math.Pow(code[instr.childIndex].value, 2);
     237        } else if(instr.opCode == OpCodes.Cube) {
     238          instr.value = Math.Pow(code[instr.childIndex].value, 3);
    237239        } else if (instr.opCode == OpCodes.Power) {
    238240          double x = code[instr.childIndex].value;
    239241          double y = Math.Round(code[instr.childIndex + 1].value);
    240242          instr.value = Math.Pow(x, y);
    241         } else if (instr.opCode == OpCodes.SquareRoot) {
     243        } else if(instr.opCode == OpCodes.SquareRoot) {
    242244          instr.value = Math.Sqrt(code[instr.childIndex].value);
     245        } else if(instr.opCode == OpCodes.CubeRoot) {
     246          instr.value = Math.Pow(code[instr.childIndex].value, 1.0 / 3.0);
    243247        } else if (instr.opCode == OpCodes.Root) {
    244248          double x = code[instr.childIndex].value;
Note: See TracChangeset for help on using the changeset viewer.