Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16802


Ignore:
Timestamp:
04/17/19 17:51:09 (6 years ago)
Author:
gkronber
Message:

#2915 added support for abs(), aq(), cube(), cuberoot() to formatters. Skipped the TSQLFormatter.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/Formatters/SymbolicExpressionTreeLatexFormatter.cs

    r16565 r16802  
    3535    {
    3636      {"ProgramRootSymbol", "Prog"},
    37       {"StartSymbol","RPB"}
     37      {"StartSymbol","RPB"},
     38      // short form
     39      {"Subtraction", "-" },
     40      {"Addition", "+" },
     41      {"Multiplication", "*" },
     42      {"Division", "/" },
     43      {"Absolute", "abs" },
     44      {"AnalyticQuotient", "AQ" },
     45      {"Sine", "sin" },
     46      {"Cosine", "cos" },
     47      {"Tanget", "tan" },
     48      {"HyperbolicTangent", "tanh" },
     49      {"Exponential", "exp" },
     50      {"Logarithm", "log" },
     51      {"SquareRoot", "sqrt" },
     52      {"Square", "sqr" },
     53      {"CubeRoot", "cbrt" },
     54      {"Cube", "cube" },
     55      {"GreaterThan", ">" },
     56      {"LessThan", "<" },
    3857    };
    3958
  • trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeGraphvizFormatter.cs

    r16565 r16802  
    3333      // match Koza style
    3434      {"ProgramRootSymbol", "Prog"},
    35       {"StartSymbol", "RPB"},
     35      {"StartSymbol", "RPB"},
     36
     37      // short form
     38      {"Subtraction", "-" },
     39      {"Addition", "+" },
     40      {"Multiplication", "*" },
     41      {"Division", "/" },
     42      {"Absolute", "abs" },
     43      {"AnalyticQuotient", "AQ" },
     44      {"Sine", "sin" },
     45      {"Cosine", "cos" },
     46      {"Tanget", "tan" },
     47      {"HyperbolicTangent", "tanh" },
     48      {"Exponential", "exp" },
     49      {"Logarithm", "log" },
     50      {"SquareRoot", "sqrt" },
     51      {"Square", "sqr" },
     52      {"CubeRoot", "cbrt" },
     53      {"Cube", "cube" },
     54      {"GreaterThan", ">" },
     55      {"LessThan", "<" },
    3656    };
    3757
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r16702 r16802  
    137137        } else if (node.Symbol is SquareRoot) {
    138138          FormatFunction(node, "Math.Sqrt", strBuilder);
     139        } else if (node.Symbol is Cube) {
     140          FormatPower(node, strBuilder, "3");
     141        } else if (node.Symbol is CubeRoot) {
     142          FormatPower(node, strBuilder, "1.0/3");
    139143        } else if (node.Symbol is Power) {
    140144          FormatFunction(node, "Math.Pow", strBuilder);
    141145        } else if (node.Symbol is Root) {
    142146          FormatRoot(node, strBuilder);
     147        } else if (node.Symbol is Absolute) {
     148          FormatFunction(node, "Math.Abs", strBuilder);
     149        } else if (node.Symbol is AnalyticQuotient) {
     150          strBuilder.Append("(");
     151          FormatRecursively(node.GetSubtree(0), strBuilder);
     152          strBuilder.Append(" / Math.Sqrt(1 + Math.Pow(");
     153          FormatRecursively(node.GetSubtree(1), strBuilder);
     154          strBuilder.Append(" , 2) )");
    143155        } else {
    144156          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter.");
     
    173185
    174186    private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     187      FormatPower(node, strBuilder, "2");
     188    }
     189    private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
    175190      strBuilder.Append("Math.Pow(");
    176191      FormatRecursively(node.GetSubtree(0), strBuilder);
    177       strBuilder.Append(", 2)");
     192      strBuilder.Append($", {exponent})");
    178193    }
    179194
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r16764 r16802  
    119119        }
    120120        stringBuilder.Append(")");
     121      } else if (symbol is Absolute) {
     122        stringBuilder.Append($"ABS({FormatRecursively(node.GetSubtree(0))})");
     123      } else if (symbol is AnalyticQuotient) {
     124        stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) / SQRT(1 + POWER({FormatRecursively(node.GetSubtree(1))}, 2))");
    121125      } else if (symbol is Average) {
    122126        stringBuilder.Append("(1/(");
     
    137141        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    138142        stringBuilder.Append(")");
     143      } else if (symbol is Cube) {
     144        stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 3)");
     145      } else if (symbol is CubeRoot) {
     146        stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 1/3)");
    139147      } else if (symbol is Division) {
    140148        if (node.SubtreeCount == 1) {
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r16702 r16802  
    117117          strBuilder.Append(@" \cfrac{ ");
    118118        }
     119      } else if (node.Symbol is Absolute) {
     120        strBuilder.Append(@"\operatorname{abs} \left( ");
     121      } else if (node.Symbol is AnalyticQuotient) {
     122        strBuilder.Append(@" \frac { ");
    119123      } else if (node.Symbol is Average) {
    120124        // skip output of (1/1) if only one subtree
     
    131135      } else if (node.Symbol is SquareRoot) {
    132136        strBuilder.Append(@"\sqrt{");
     137      } else if (node.Symbol is Cube) {
     138        strBuilder.Append(@"\left(");
     139      } else if (node.Symbol is CubeRoot) {
     140        strBuilder.Append(@"\left(");
    133141      } else if (node.Symbol is Sine) {
    134142        strBuilder.Append(@"\sin \left( ");
     
    289297        else
    290298          strBuilder.Append(@" }{ \cfrac{ ");
     299      } else if (node.Symbol is Absolute) {
     300        throw new InvalidOperationException();
     301      } else if (node.Symbol is AnalyticQuotient) {
     302        strBuilder.Append(@"}{\sqrt{1 + \left( ");
    291303      } else if (node.Symbol is Average) {
    292304        strBuilder.Append(@" + ");
     
    298310        throw new InvalidOperationException();
    299311      } else if (node.Symbol is SquareRoot) {
     312        throw new InvalidOperationException();
     313      } else if (node.Symbol is Cube) {
     314        throw new InvalidOperationException();
     315      } else if (node.Symbol is CubeRoot) {
    300316        throw new InvalidOperationException();
    301317      } else if (node.Symbol is Sine) {
     
    387403        for (int i = 2; i < node.SubtreeCount; i++)
    388404          strBuilder.Append(" } ");
     405      } else if (node.Symbol is Absolute) {
     406        strBuilder.Append(@" \right)");
     407      } else if (node.Symbol is AnalyticQuotient) {
     408        strBuilder.Append(@" \right)^2}}");
    389409      } else if (node.Symbol is Average) {
    390410        strBuilder.Append(@" \right) ");
     
    397417      } else if (node.Symbol is SquareRoot) {
    398418        strBuilder.Append(@"}");
     419      } else if (node.Symbol is Cube) {
     420        strBuilder.Append(@"\right)^3");
     421      } else if (node.Symbol is CubeRoot) {
     422        strBuilder.Append(@"\right)^\frac{1}{3}");
    399423      } else if (node.Symbol is Sine) {
    400424        strBuilder.Append(@" \right) ");
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs

    r16702 r16802  
    126126        }
    127127        stringBuilder.Append(")");
     128      } else if (symbol is Absolute) {
     129        stringBuilder.Append($"abs({FormatRecursively(node.GetSubtree(0))})");
     130      } else if (symbol is AnalyticQuotient) {
     131        stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) / sqrt(1 + ({FormatRecursively(node.GetSubtree(1))}).^2)");
    128132      } else if (symbol is And) {
    129133        stringBuilder.Append("((");
     
    179183        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    180184        stringBuilder.Append(")");
     185      } else if (symbol is Cube) {
     186        stringBuilder.Append("(");
     187        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     188        stringBuilder.Append(").^3");
     189      } else if (symbol is CubeRoot) {
     190        stringBuilder.Append("(");
     191        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     192        stringBuilder.Append(").^(1/3)");
    181193      } else if (symbol is GreaterThan) {
    182194        stringBuilder.Append("((");
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs

    r16702 r16802  
    5656        if (node.Symbol is Addition) {
    5757          FormatFunction(node, "Plus", strBuilder);
     58        } else if (node.Symbol is Absolute) {
     59          FormatFunction(node, "Abs", strBuilder);
     60        } else if (node.Symbol is AnalyticQuotient) {
     61          strBuilder.Append("[");
     62          FormatRecursively(node.GetSubtree(0), strBuilder);
     63          strBuilder.Append("]/Sqrt[ 1 + Power[");
     64          FormatRecursively(node.GetSubtree(1), strBuilder);
     65          strBuilder.Append(", 2]]");
    5866        } else if (node.Symbol is Average) {
    5967          FormatAverage(node, strBuilder);
     
    104112        } else if (node.Symbol is SquareRoot) {
    105113          FormatFunction(node, "Sqrt", strBuilder);
     114        } else if (node.Symbol is Cube) {
     115          FormatPower(node, strBuilder, "3");
     116        } else if (node.Symbol is CubeRoot) {
     117          FormatPower(node, strBuilder, "1/3");
    106118        } else if (node.Symbol is Power) {
    107119          FormatFunction(node, "Power", strBuilder);
     
    205217
    206218    private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     219      FormatPower(node, strBuilder, "2");
     220    }
     221
     222    private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
    207223      strBuilder.Append("Power[");
    208224      FormatRecursively(node.GetSubtree(0), strBuilder);
    209       strBuilder.Append(", 2]");
     225      strBuilder.Append($", {exponent}]");
    210226    }
    211227
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs

    r16702 r16802  
    2020#endregion
    2121
     22using System;
    2223using System.Globalization;
    2324using System.Text;
     
    6970        }
    7071        stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]");
     72      } else if (symbol is Absolute) {
     73        stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) abs");
     74      } else if (symbol is AnalyticQuotient) {
     75        stringBuilder.Append($"({FormatRecursively(node.GetSubtree(0))}) / (1 + ({FormatPower(node.GetSubtree(1), "2")})) sqrt");
    7176      } else if (symbol is Average) {
    7277        stringBuilder.Append("(1/");
     
    8489        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    8590        stringBuilder.Append(" cos");
     91      } else if (symbol is Cube) {
     92        stringBuilder.Append(FormatPower(node.GetSubtree(0), "3"));
     93      } else if (symbol is CubeRoot) {
     94        stringBuilder.Append(FormatPower(node.GetSubtree(0), "(1/3)"));
    8695      } else if (symbol is Division) {
    8796        if (node.SubtreeCount == 1) {
     
    146155        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    147156        stringBuilder.Append(" sin");
     157      } else if (symbol is Square) {
     158        stringBuilder.Append(FormatPower(node.GetSubtree(0), "2"));
     159      } else if (symbol is SquareRoot) {
     160        stringBuilder.Append(FormatPower(node.GetSubtree(0), "(1/2)"));
    148161      } else if (symbol is Subtraction) {
    149162        if (node.SubtreeCount == 1) {
     
    184197    }
    185198
     199    private string FormatPower(ISymbolicExpressionTreeNode node, string exponent) {
     200      return $"(({FormatRecursively(node)}) log * {exponent}) exp ";
     201    }
     202
    186203    public override IDeepCloneable Clone(Cloner cloner) {
    187204      return new SymbolicDataAnalysisExpressionSmalltalkFormatter(this, cloner);
Note: See TracChangeset for help on using the changeset viewer.