Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/07/19 13:32:09 (5 years ago)
Author:
mkommend
Message:

#2974: Merged trunk changes into branch.

Location:
branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5151    }
    5252
    53     public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     53    /// <summary>
     54    /// Produces an infix expression for a given expression tree.
     55    /// </summary>
     56    /// <param name="symbolicExpressionTree">The tree representation of the expression.</param>
     57    /// <param name="numberFormat">Number format that should be used for numeric parameters (e.g. NumberFormatInfo.InvariantInfo (default)).</param>
     58    /// <param name="formatString">The format string for numeric parameters (e.g. \"G4\" to limit to 4 digits, default is \"G\")</param>
     59    /// <returns>Infix expression</returns>
     60    public string Format(ISymbolicExpressionTree symbolicExpressionTree, NumberFormatInfo numberFormat, string formatString="G") {
    5461      // skip root and start symbols
    5562      StringBuilder strBuilder = new StringBuilder();
    56       FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0), strBuilder);
     63      FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0), strBuilder, numberFormat, formatString);
    5764      return strBuilder.ToString();
    5865    }
    5966
    60     private void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     67    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     68      return Format(symbolicExpressionTree, NumberFormatInfo.InvariantInfo);
     69    }
     70
     71    private static void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, NumberFormatInfo numberFormat, string formatString) {
    6172      if (node.SubtreeCount > 1) {
    6273        var token = GetToken(node.Symbol);
     
    6677            token == "^") {
    6778          strBuilder.Append("(");
    68           FormatRecursively(node.Subtrees.First(), strBuilder);
     79          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString);
    6980
    7081          foreach (var subtree in node.Subtrees.Skip(1)) {
    7182            strBuilder.Append(" ").Append(token).Append(" ");
    72             FormatRecursively(subtree, strBuilder);
     83            FormatRecursively(subtree, strBuilder, numberFormat, formatString);
    7384          }
    7485          strBuilder.Append(")");
     
    7687          // function with multiple arguments
    7788          strBuilder.Append(token).Append("(");
    78           FormatRecursively(node.Subtrees.First(), strBuilder);
     89          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString);
    7990          foreach (var subtree in node.Subtrees.Skip(1)) {
    8091            strBuilder.Append(", ");
    81             FormatRecursively(subtree, strBuilder);
     92            FormatRecursively(subtree, strBuilder, numberFormat, formatString);
    8293          }
    8394          strBuilder.Append(")");
     
    8798        if (token == "-" || token == "NOT") {
    8899          strBuilder.Append("(").Append(token).Append("(");
    89           FormatRecursively(node.GetSubtree(0), strBuilder);
     100          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
    90101          strBuilder.Append("))");
    91102        } else if (token == "/") {
    92103          strBuilder.Append("1/");
    93           FormatRecursively(node.GetSubtree(0), strBuilder);
     104          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
    94105        } else if (token == "+" || token == "*") {
    95           FormatRecursively(node.GetSubtree(0), strBuilder);
     106          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
    96107        } else {
    97108          // function with only one argument
    98109          strBuilder.Append(token).Append("(");
    99           FormatRecursively(node.GetSubtree(0), strBuilder);
     110          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
    100111          strBuilder.Append(")");
    101112        }
     
    106117          if (!varNode.Weight.IsAlmost(1.0)) {
    107118            strBuilder.Append("(");
    108             strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", varNode.Weight);
     119            strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
    109120            strBuilder.Append("*");
    110121          }
     
    116127          }
    117128          strBuilder.Append(", ")
    118             .AppendFormat(CultureInfo.InvariantCulture, "{0}", varNode.Lag)
     129            .AppendFormat(numberFormat, "{0}", varNode.Lag)
    119130            .Append(")");
    120131        } else if (node.Symbol is Variable) {
     
    122133          if (!varNode.Weight.IsAlmost(1.0)) {
    123134            strBuilder.Append("(");
    124             strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", varNode.Weight);
     135            strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
    125136            strBuilder.Append("*");
    126137          }
     
    141152          }
    142153          strBuilder.AppendFormat("[{0}]",
    143             string.Join(", ", factorNode.Weights.Select(w => w.ToString(CultureInfo.InvariantCulture))));
     154            string.Join(", ", factorNode.Weights.Select(w => w.ToString(formatString, numberFormat))));
    144155        } else if (node.Symbol is BinaryFactorVariable) {
    145156          var factorNode = node as BinaryFactorVariableTreeNode;
    146157          if (!factorNode.Weight.IsAlmost(1.0)) {
    147158            strBuilder.Append("(");
    148             strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", factorNode.Weight);
     159            strBuilder.Append(factorNode.Weight.ToString(formatString, numberFormat));
    149160            strBuilder.Append("*");
    150161          }
     
    168179          var constNode = node as ConstantTreeNode;
    169180          if (constNode.Value >= 0.0)
    170             strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", constNode.Value);
     181            strBuilder.Append(constNode.Value.ToString(formatString, numberFormat));
    171182          else
    172             strBuilder.AppendFormat(CultureInfo.InvariantCulture, "({0})", constNode.Value); // (-1
     183            strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat)).Append(")"); // (-1
    173184        }
    174185      }
    175186    }
    176187
    177     private string GetToken(ISymbol symbol) {
     188    private static string GetToken(ISymbol symbol) {
    178189      var tok = InfixExpressionParser.knownSymbols.GetBySecond(symbol).FirstOrDefault();
    179190      if (tok == null)
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626using System.Text;
    2727using System.Text.RegularExpressions;
     28using HEAL.Attic;
    2829using HeuristicLab.Common;
    2930using HeuristicLab.Core;
    3031using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    31 using HEAL.Attic;
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    5656    }
    5757
    58     private string VariableName2Identifier(string name) {     
     58    private string VariableName2Identifier(string name) {
    5959      /*
    6060       * identifier-start-character:
     
    131131        } else if (node.Symbol is Tangent) {
    132132          FormatFunction(node, "Math.Tan", strBuilder);
     133        } else if (node.Symbol is HyperbolicTangent) {
     134          FormatFunction(node, "Math.Tanh", strBuilder);
    133135        } else if (node.Symbol is Square) {
    134136          FormatSquare(node, strBuilder);
    135137        } else if (node.Symbol is SquareRoot) {
    136138          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          strBuilder.Append("Cbrt(");
     143          FormatRecursively(node.GetSubtree(0), strBuilder);
     144          strBuilder.Append(")");
    137145        } else if (node.Symbol is Power) {
    138146          FormatFunction(node, "Math.Pow", strBuilder);
    139147        } else if (node.Symbol is Root) {
    140148          FormatRoot(node, strBuilder);
     149        } else if (node.Symbol is Absolute) {
     150          FormatFunction(node, "Math.Abs", strBuilder);
     151        } else if (node.Symbol is AnalyticQuotient) {
     152          strBuilder.Append("(");
     153          FormatRecursively(node.GetSubtree(0), strBuilder);
     154          strBuilder.Append(" / Math.Sqrt(1 + Math.Pow(");
     155          FormatRecursively(node.GetSubtree(1), strBuilder);
     156          strBuilder.Append(" , 2) )");
    141157        } else {
    142158          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter.");
     
    171187
    172188    private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     189      FormatPower(node, strBuilder, "2");
     190    }
     191    private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
    173192      strBuilder.Append("Math.Pow(");
    174193      FormatRecursively(node.GetSubtree(0), strBuilder);
    175       strBuilder.Append(", 2)");
     194      strBuilder.Append($", {exponent})");
    176195    }
    177196
     
    235254      strBuilder.AppendLine("public static class Model {");
    236255      GenerateAverageSource(strBuilder);
     256      GenerateCbrtSource(strBuilder);
    237257      GenerateIfThenElseSource(strBuilder);
    238258      GenerateFactorSource(strBuilder);
     
    276296      strBuilder.AppendLine("private static double Average(params double[] values) {");
    277297      strBuilder.AppendLine("  return values.Average();");
     298      strBuilder.AppendLine("}");
     299    }
     300    private void GenerateCbrtSource(StringBuilder strBuilder) {
     301      strBuilder.AppendLine("private static double Cbrt(double x) {");
     302      strBuilder.AppendLine("  return x < 0 ? -Math.Pow(-x, 1.0 / 3.0) : Math.Pow(x, 1.0 / 3.0);");
    278303      strBuilder.AppendLine("}");
    279304    }
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using System.Linq;
    2626using System.Text;
     27using HEAL.Attic;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Core;
    2930using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    30 using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    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) {
    122         stringBuilder.Append("(1/");
     126        stringBuilder.Append("(1/(");
    123127        stringBuilder.Append(node.SubtreeCount);
    124128        stringBuilder.Append(")*(");
     
    129133          stringBuilder.Append(")");
    130134        }
    131         stringBuilder.Append(")");
     135        stringBuilder.Append("))");
    132136      } else if (symbol is Constant) {
    133137        ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
     
    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        var arg_expr = FormatRecursively(node.GetSubtree(0));
     147        stringBuilder.Append($"IF({arg_expr} < 0, -POWER(-{arg_expr}, 1/3), POWER({arg_expr}, 1/3))");
    139148      } else if (symbol is Division) {
    140149        if (node.SubtreeCount == 1) {
    141           stringBuilder.Append("1/");
    142           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     150          stringBuilder.Append("1/(");
     151          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     152          stringBuilder.Append(")");
    143153        } else {
    144154          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     
    192202        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    193203        stringBuilder.Append(")");
    194 
     204      } else if (symbol is HyperbolicTangent) {
     205        stringBuilder.Append("TANH(");
     206        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     207        stringBuilder.Append(")");
    195208      } else if (symbol is Variable) {
    196209        VariableTreeNode variableTreeNode = node as VariableTreeNode;
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Linq;
    2525using System.Text;
     26using HEAL.Attic;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    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(@"\operatorname{cbrt}\left(");
    133141      } else if (node.Symbol is Sine) {
    134142        strBuilder.Append(@"\sin \left( ");
     
    137145      } else if (node.Symbol is Tangent) {
    138146        strBuilder.Append(@"\tan \left( ");
     147      } else if (node.Symbol is HyperbolicTangent) {
     148        strBuilder.Append(@"\tanh \left( ");
    139149      } else if (node.Symbol is AiryA) {
    140150        strBuilder.Append(@"\operatorname{airy}_a \left( ");
     
    287297        else
    288298          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( ");
    289303      } else if (node.Symbol is Average) {
    290304        strBuilder.Append(@" + ");
     
    297311      } else if (node.Symbol is SquareRoot) {
    298312        throw new InvalidOperationException();
     313      } else if (node.Symbol is Cube) {
     314        throw new InvalidOperationException();
     315      } else if (node.Symbol is CubeRoot) {
     316        throw new InvalidOperationException();
    299317      } else if (node.Symbol is Sine) {
    300318        throw new InvalidOperationException();
     
    302320        throw new InvalidOperationException();
    303321      } else if (node.Symbol is Tangent) {
     322        throw new InvalidOperationException();
     323      } else if (node.Symbol is HyperbolicTangent) {
    304324        throw new InvalidOperationException();
    305325      } else if (node.Symbol is AiryA) {
     
    383403        for (int i = 2; i < node.SubtreeCount; i++)
    384404          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}}");
    385409      } else if (node.Symbol is Average) {
    386410        strBuilder.Append(@" \right) ");
     
    393417      } else if (node.Symbol is SquareRoot) {
    394418        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)");
    395423      } else if (node.Symbol is Sine) {
    396424        strBuilder.Append(@" \right) ");
     
    398426        strBuilder.Append(@" \right) ");
    399427      } else if (node.Symbol is Tangent) {
     428        strBuilder.Append(@" \right) ");
     429      } else if (node.Symbol is HyperbolicTangent) {
    400430        strBuilder.Append(@" \right) ");
    401431      } else if (node.Symbol is AiryA) {
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Linq;
    2424using System.Text;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    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("NTHROOT(");
     191        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     192        stringBuilder.Append(", 3)");
    181193      } else if (symbol is GreaterThan) {
    182194        stringBuilder.Append("((");
     
    252264      } else if (symbol is Tangent) {
    253265        stringBuilder.Append("tan(");
     266        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     267        stringBuilder.Append(")");
     268      } else if (symbol is HyperbolicTangent) {
     269        stringBuilder.Append("tanh(");
    254270        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    255271        stringBuilder.Append(")");
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using System.Linq;
    2525using System.Text;
     26using HEAL.Attic;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
    2829using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    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);
     
    7078        } else if (node.Symbol is Tangent) {
    7179          FormatFunction(node, "Tan", strBuilder);
     80        } else if (node.Symbol is HyperbolicTangent) {
     81          FormatFunction(node, "Tanh", strBuilder);
    7282        } else if (node.Symbol is Exponential) {
    7383          FormatFunction(node, "Exp", strBuilder);
     
    102112        } else if (node.Symbol is SquareRoot) {
    103113          FormatFunction(node, "Sqrt", strBuilder);
     114        } else if (node.Symbol is Cube) {
     115          FormatPower(node, strBuilder, "3");
     116        } else if (node.Symbol is CubeRoot) {
     117          strBuilder.Append("CubeRoot[");
     118          FormatRecursively(node.GetSubtree(0), strBuilder);
     119          strBuilder.Append("]");
    104120        } else if (node.Symbol is Power) {
    105121          FormatFunction(node, "Power", strBuilder);
     
    203219
    204220    private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     221      FormatPower(node, strBuilder, "2");
     222    }
     223
     224    private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) {
    205225      strBuilder.Append("Power[");
    206226      FormatRecursively(node.GetSubtree(0), strBuilder);
    207       strBuilder.Append(", 2]");
     227      strBuilder.Append($", {exponent}]");
    208228    }
    209229
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    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(FormatRecursively(node.GetSubtree(0)));
     95        stringBuilder.Append(" cbrt");
    8696      } else if (symbol is Division) {
    8797        if (node.SubtreeCount == 1) {
     
    146156        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    147157        stringBuilder.Append(" sin");
     158      } else if (symbol is Square) {
     159        stringBuilder.Append(FormatPower(node.GetSubtree(0), "2"));
     160      } else if (symbol is SquareRoot) {
     161        stringBuilder.Append(FormatPower(node.GetSubtree(0), "(1/2)"));
    148162      } else if (symbol is Subtraction) {
    149163        if (node.SubtreeCount == 1) {
     
    160174        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    161175        stringBuilder.Append(" tan");
     176      } else if (symbol is HyperbolicTangent) {
     177        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     178        stringBuilder.Append(" tanh");
    162179      } else if (symbol is Variable) {
    163180        VariableTreeNode variableTreeNode = node as VariableTreeNode;
     
    181198    }
    182199
     200    private string FormatPower(ISymbolicExpressionTreeNode node, string exponent) {
     201      return $"(({FormatRecursively(node)}) log * {exponent}) exp ";
     202    }
     203
    183204    public override IDeepCloneable Clone(Cloner cloner) {
    184205      return new SymbolicDataAnalysisExpressionSmalltalkFormatter(this, cloner);
  • branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/TSQLExpressionFormatter.cs

    r16676 r17193  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
Note: See TracChangeset for help on using the changeset viewer.