Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/07/19 14:20:33 (6 years ago)
Author:
gkronber
Message:

#2915: Corrected calculation of cuberoot function in all interpreters and updated all formatters.
I tested a run with all interpreters and got the same results with all of them.

Location:
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r16802 r16905  
    140140          FormatPower(node, strBuilder, "3");
    141141        } else if (node.Symbol is CubeRoot) {
    142           FormatPower(node, strBuilder, "1.0/3");
     142          strBuilder.Append("Cbrt(");
     143          FormatRecursively(node.GetSubtree(0), strBuilder);
     144          strBuilder.Append(")");
    143145        } else if (node.Symbol is Power) {
    144146          FormatFunction(node, "Math.Pow", strBuilder);
     
    252254      strBuilder.AppendLine("public static class Model {");
    253255      GenerateAverageSource(strBuilder);
     256      GenerateCbrtSource(strBuilder);
    254257      GenerateIfThenElseSource(strBuilder);
    255258      GenerateFactorSource(strBuilder);
     
    293296      strBuilder.AppendLine("private static double Average(params double[] values) {");
    294297      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);");
    295303      strBuilder.AppendLine("}");
    296304    }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r16868 r16905  
    144144        stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 3)");
    145145      } else if (symbol is CubeRoot) {
    146         stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 1/3)");
     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))");
    147148      } else if (symbol is Division) {
    148149        if (node.SubtreeCount == 1) {
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r16802 r16905  
    138138        strBuilder.Append(@"\left(");
    139139      } else if (node.Symbol is CubeRoot) {
    140         strBuilder.Append(@"\left(");
     140        strBuilder.Append(@"\operatorname{cbrt}\left(");
    141141      } else if (node.Symbol is Sine) {
    142142        strBuilder.Append(@"\sin \left( ");
     
    420420        strBuilder.Append(@"\right)^3");
    421421      } else if (node.Symbol is CubeRoot) {
    422         strBuilder.Append(@"\right)^\frac{1}{3}");
     422        strBuilder.Append(@"\right)");
    423423      } else if (node.Symbol is Sine) {
    424424        strBuilder.Append(@" \right) ");
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs

    r16802 r16905  
    188188        stringBuilder.Append(").^3");
    189189      } else if (symbol is CubeRoot) {
    190         stringBuilder.Append("(");
    191         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    192         stringBuilder.Append(").^(1/3)");
     190        stringBuilder.Append("NTHROOT(");
     191        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     192        stringBuilder.Append(", 3)");
    193193      } else if (symbol is GreaterThan) {
    194194        stringBuilder.Append("((");
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs

    r16802 r16905  
    115115          FormatPower(node, strBuilder, "3");
    116116        } else if (node.Symbol is CubeRoot) {
    117           FormatPower(node, strBuilder, "1/3");
     117          strBuilder.Append("CubeRoot[");
     118          FormatRecursively(node.GetSubtree(0), strBuilder);
     119          strBuilder.Append("]");
    118120        } else if (node.Symbol is Power) {
    119121          FormatFunction(node, "Power", strBuilder);
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs

    r16802 r16905  
    9292        stringBuilder.Append(FormatPower(node.GetSubtree(0), "3"));
    9393      } else if (symbol is CubeRoot) {
    94         stringBuilder.Append(FormatPower(node.GetSubtree(0), "(1/3)"));
     94        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     95        stringBuilder.Append(" cbrt");
    9596      } else if (symbol is Division) {
    9697        if (node.SubtreeCount == 1) {
Note: See TracChangeset for help on using the changeset viewer.