Changeset 16946 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters
- Timestamp:
- 05/13/19 13:59:30 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16802,16822,16839,16858,16868,16905
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs
r16723 r16946 137 137 } else if (node.Symbol is SquareRoot) { 138 138 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(")"); 139 145 } else if (node.Symbol is Power) { 140 146 FormatFunction(node, "Math.Pow", strBuilder); 141 147 } else if (node.Symbol is Root) { 142 148 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) )"); 143 157 } else { 144 158 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter."); … … 173 187 174 188 private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 189 FormatPower(node, strBuilder, "2"); 190 } 191 private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) { 175 192 strBuilder.Append("Math.Pow("); 176 193 FormatRecursively(node.GetSubtree(0), strBuilder); 177 strBuilder.Append( ", 2)");194 strBuilder.Append($", {exponent})"); 178 195 } 179 196 … … 237 254 strBuilder.AppendLine("public static class Model {"); 238 255 GenerateAverageSource(strBuilder); 256 GenerateCbrtSource(strBuilder); 239 257 GenerateIfThenElseSource(strBuilder); 240 258 GenerateFactorSource(strBuilder); … … 278 296 strBuilder.AppendLine("private static double Average(params double[] values) {"); 279 297 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);"); 280 303 strBuilder.AppendLine("}"); 281 304 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r16801 r16946 119 119 } 120 120 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))"); 121 125 } else if (symbol is Average) { 122 126 stringBuilder.Append("(1/("); … … 129 133 stringBuilder.Append(")"); 130 134 } 131 stringBuilder.Append(") ");135 stringBuilder.Append("))"); 132 136 } else if (symbol is Constant) { 133 137 ConstantTreeNode constantTreeNode = node as ConstantTreeNode; … … 137 141 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 138 142 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))"); 139 148 } else if (symbol is Division) { 140 149 if (node.SubtreeCount == 1) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r16723 r16946 117 117 strBuilder.Append(@" \cfrac{ "); 118 118 } 119 } else if (node.Symbol is Absolute) { 120 strBuilder.Append(@"\operatorname{abs} \left( "); 121 } else if (node.Symbol is AnalyticQuotient) { 122 strBuilder.Append(@" \frac { "); 119 123 } else if (node.Symbol is Average) { 120 124 // skip output of (1/1) if only one subtree … … 131 135 } else if (node.Symbol is SquareRoot) { 132 136 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("); 133 141 } else if (node.Symbol is Sine) { 134 142 strBuilder.Append(@"\sin \left( "); … … 289 297 else 290 298 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( "); 291 303 } else if (node.Symbol is Average) { 292 304 strBuilder.Append(@" + "); … … 298 310 throw new InvalidOperationException(); 299 311 } 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) { 300 316 throw new InvalidOperationException(); 301 317 } else if (node.Symbol is Sine) { … … 387 403 for (int i = 2; i < node.SubtreeCount; i++) 388 404 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}}"); 389 409 } else if (node.Symbol is Average) { 390 410 strBuilder.Append(@" \right) "); … … 397 417 } else if (node.Symbol is SquareRoot) { 398 418 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)"); 399 423 } else if (node.Symbol is Sine) { 400 424 strBuilder.Append(@" \right) "); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
r16723 r16946 126 126 } 127 127 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)"); 128 132 } else if (symbol is And) { 129 133 stringBuilder.Append("(("); … … 179 183 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 180 184 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)"); 181 193 } else if (symbol is GreaterThan) { 182 194 stringBuilder.Append("(("); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs
r16723 r16946 56 56 if (node.Symbol is Addition) { 57 57 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]]"); 58 66 } else if (node.Symbol is Average) { 59 67 FormatAverage(node, strBuilder); … … 104 112 } else if (node.Symbol is SquareRoot) { 105 113 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("]"); 106 120 } else if (node.Symbol is Power) { 107 121 FormatFunction(node, "Power", strBuilder); … … 205 219 206 220 private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 221 FormatPower(node, strBuilder, "2"); 222 } 223 224 private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) { 207 225 strBuilder.Append("Power["); 208 226 FormatRecursively(node.GetSubtree(0), strBuilder); 209 strBuilder.Append( ", 2]");227 strBuilder.Append($", {exponent}]"); 210 228 } 211 229 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs
r16723 r16946 20 20 #endregion 21 21 22 using System; 22 23 using System.Globalization; 23 24 using System.Text; … … 69 70 } 70 71 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"); 71 76 } else if (symbol is Average) { 72 77 stringBuilder.Append("(1/"); … … 84 89 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 85 90 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"); 86 96 } else if (symbol is Division) { 87 97 if (node.SubtreeCount == 1) { … … 146 156 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 147 157 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)")); 148 162 } else if (symbol is Subtraction) { 149 163 if (node.SubtreeCount == 1) { … … 184 198 } 185 199 200 private string FormatPower(ISymbolicExpressionTreeNode node, string exponent) { 201 return $"(({FormatRecursively(node)}) log * {exponent}) exp "; 202 } 203 186 204 public override IDeepCloneable Clone(Cloner cloner) { 187 205 return new SymbolicDataAnalysisExpressionSmalltalkFormatter(this, cloner);
Note: See TracChangeset
for help on using the changeset viewer.