Changeset 16802 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 04/17/19 17:51:09 (6 years ago)
- 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
r16702 r16802 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 FormatPower(node, strBuilder, "1.0/3"); 139 143 } else if (node.Symbol is Power) { 140 144 FormatFunction(node, "Math.Pow", strBuilder); 141 145 } else if (node.Symbol is Root) { 142 146 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) )"); 143 155 } else { 144 156 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter."); … … 173 185 174 186 private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 187 FormatPower(node, strBuilder, "2"); 188 } 189 private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) { 175 190 strBuilder.Append("Math.Pow("); 176 191 FormatRecursively(node.GetSubtree(0), strBuilder); 177 strBuilder.Append( ", 2)");192 strBuilder.Append($", {exponent})"); 178 193 } 179 194 -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r16764 r16802 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/("); … … 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 stringBuilder.Append($"POWER({FormatRecursively(node.GetSubtree(0))}, 1/3)"); 139 147 } else if (symbol is Division) { 140 148 if (node.SubtreeCount == 1) { -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r16702 r16802 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(@"\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)^\frac{1}{3}"); 399 423 } else if (node.Symbol is Sine) { 400 424 strBuilder.Append(@" \right) "); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
r16702 r16802 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("("); 191 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 192 stringBuilder.Append(").^(1/3)"); 181 193 } else if (symbol is GreaterThan) { 182 194 stringBuilder.Append("(("); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs
r16702 r16802 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 FormatPower(node, strBuilder, "1/3"); 106 118 } else if (node.Symbol is Power) { 107 119 FormatFunction(node, "Power", strBuilder); … … 205 217 206 218 private void FormatSquare(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 219 FormatPower(node, strBuilder, "2"); 220 } 221 222 private void FormatPower(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, string exponent) { 207 223 strBuilder.Append("Power["); 208 224 FormatRecursively(node.GetSubtree(0), strBuilder); 209 strBuilder.Append( ", 2]");225 strBuilder.Append($", {exponent}]"); 210 226 } 211 227 -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs
r16702 r16802 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(FormatPower(node.GetSubtree(0), "(1/3)")); 86 95 } else if (symbol is Division) { 87 96 if (node.SubtreeCount == 1) { … … 146 155 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 147 156 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)")); 148 161 } else if (symbol is Subtraction) { 149 162 if (node.SubtreeCount == 1) { … … 184 197 } 185 198 199 private string FormatPower(ISymbolicExpressionTreeNode node, string exponent) { 200 return $"(({FormatRecursively(node)}) log * {exponent}) exp "; 201 } 202 186 203 public override IDeepCloneable Clone(Cloner cloner) { 187 204 return new SymbolicDataAnalysisExpressionSmalltalkFormatter(this, cloner);
Note: See TracChangeset
for help on using the changeset viewer.