Changeset 7136
 Timestamp:
 12/06/11 17:07:10 (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r7038 r7136 90 90 private void FormatBegin(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 91 91 if (node.Symbol is Addition) { 92 strBuilder.Append(@" ");92 strBuilder.Append(@" ( "); 93 93 } else if (node.Symbol is Subtraction) { 94 94 if (node.SubtreeCount == 1) { 95 strBuilder.Append(@" ");95 strBuilder.Append(@" ( "); 96 96 } else { 97 strBuilder.Append(@" ");97 strBuilder.Append(@" ( "); 98 98 } 99 99 } else if (node.Symbol is Multiplication) { … … 109 109 strBuilder.Append(@" \cfrac{1}{" + node.SubtreeCount + @"}"); 110 110 } 111 strBuilder.Append(@" ");111 strBuilder.Append(@" ( "); 112 112 } else if (node.Symbol is Logarithm) { 113 strBuilder.Append(@"\log ");113 strBuilder.Append(@"\log ( "); 114 114 } else if (node.Symbol is Exponential) { 115 strBuilder.Append(@"\exp ");115 strBuilder.Append(@"\exp ( "); 116 116 } else if (node.Symbol is Sine) { 117 strBuilder.Append(@"\sin ");117 strBuilder.Append(@"\sin ( "); 118 118 } else if (node.Symbol is Cosine) { 119 strBuilder.Append(@"\cos ");119 strBuilder.Append(@"\cos ( "); 120 120 } else if (node.Symbol is Tangent) { 121 strBuilder.Append(@"\tan ");121 strBuilder.Append(@"\tan ( "); 122 122 } else if (node.Symbol is GreaterThan) { 123 strBuilder.Append(@" ");123 strBuilder.Append(@" ( "); 124 124 } else if (node.Symbol is LessThan) { 125 strBuilder.Append(@" ");125 strBuilder.Append(@" ( "); 126 126 } else if (node.Symbol is And) { 127 strBuilder.Append(@" ");127 strBuilder.Append(@" ( "); 128 128 } else if (node.Symbol is Or) { 129 strBuilder.Append(@" ");129 strBuilder.Append(@" ( "); 130 130 } else if (node.Symbol is Not) { 131 strBuilder.Append(@" \neg ");131 strBuilder.Append(@" \neg ( "); 132 132 } else if (node.Symbol is IfThenElse) { 133 strBuilder.Append(@" \operatorname{if} 0 < ");133 strBuilder.Append(@" \operatorname{if} ( 0 < "); 134 134 } else if (node.Symbol is Constant) { 135 135 strBuilder.Append("c_{" + constants.Count + "} "); … … 159 159 } else if (node.Symbol is InvokeFunction) { 160 160 var invokeNode = node as InvokeFunctionTreeNode; 161 strBuilder.Append(invokeNode.Symbol.FunctionName + @" ");161 strBuilder.Append(invokeNode.Symbol.FunctionName + @" ( "); 162 162 } else if (node.Symbol is StartSymbol) { 163 163 strBuilder.Append("Result & = "); … … 166 166 strBuilder.Append(" ARG+" + argSym.ArgumentIndex + " "); 167 167 } else if (node.Symbol is Derivative) { 168 strBuilder.Append(@" \cfrac{d ");168 strBuilder.Append(@" \cfrac{d ( "); 169 169 } else if (node.Symbol is TimeLag) { 170 170 var laggedNode = node as ILaggedTreeNode; 171 171 currentLag += laggedNode.Lag; 172 172 } else if (node.Symbol is Power) { 173 strBuilder.Append(@" ");173 strBuilder.Append(@" ( "); 174 174 } else if (node.Symbol is Root) { 175 strBuilder.Append(@" ");175 strBuilder.Append(@" ( "); 176 176 } else if (node.Symbol is Integral) { 177 177 // actually a new variable for t is needed in all subtrees (TODO) 178 178 var laggedTreeNode = node as ILaggedTreeNode; 179 strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 ");179 strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 ( "); 180 180 } else if (node.Symbol is VariableCondition) { 181 181 var conditionTreeNode = node as VariableConditionTreeNode; … … 184 184 p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + "  c_{" + constants.Count + @"} "; 185 185 constants.Add(conditionTreeNode.Threshold); 186 strBuilder.Append(@" " + p + @"\cdot ");186 strBuilder.Append(@" ( " + p + @"\cdot "); 187 187 } else { 188 188 throw new NotImplementedException("Export of " + node.Symbol + " is not implemented."); … … 216 216 strBuilder.Append(@" < "); 217 217 } else if (node.Symbol is And) { 218 strBuilder.Append(@" > 0 \land");218 strBuilder.Append(@" > 0 ) \land ("); 219 219 } else if (node.Symbol is Or) { 220 strBuilder.Append(@" > 0 \lor");220 strBuilder.Append(@" > 0 ) \lor ("); 221 221 } else if (node.Symbol is Not) { 222 222 throw new InvalidOperationException(); 223 223 } else if (node.Symbol is IfThenElse) { 224 strBuilder.Append(@" ,");224 strBuilder.Append(@" ) , ("); 225 225 } else if (node.Symbol is ProgramRootSymbol) { 226 226 strBuilder.Append(@"\\" + Environment.NewLine); … … 231 231 strBuilder.Append(@"\\" + Environment.NewLine + " & "); 232 232 } else if (node.Symbol is Power) { 233 strBuilder.Append(@" ^ { \operatorname{round}");233 strBuilder.Append(@") ^ { \operatorname{round} ("); 234 234 } else if (node.Symbol is Root) { 235 strBuilder.Append(@" ^ { \cfrac{1}{ \operatorname{round}");235 strBuilder.Append(@") ^ { \cfrac{1}{ \operatorname{round} ("); 236 236 } else if (node.Symbol is VariableCondition) { 237 237 var conditionTreeNode = node as VariableConditionTreeNode; 238 string p = @"1 / 1 + \exp c_{" + constants.Count + "} ";238 string p = @"1 / ( 1 + \exp (  c_{" + constants.Count + "} "; 239 239 constants.Add(conditionTreeNode.Slope); 240 p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + "  c_{" + constants.Count + @"} ";240 p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + "  c_{" + constants.Count + @"} ) ) ) "; 241 241 constants.Add(conditionTreeNode.Threshold); 242 strBuilder.Append(@" + 1  " + p + @"\cdot ");242 strBuilder.Append(@" + ( 1  " + p + @" ) \cdot "); 243 243 } else { 244 244 throw new NotImplementedException("Export of " + node.Symbol + " is not implemented."); … … 248 248 private void FormatEnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 249 249 if (node.Symbol is Addition) { 250 strBuilder.Append(@" ");250 strBuilder.Append(@" ) "); 251 251 } else if (node.Symbol is Subtraction) { 252 strBuilder.Append(@" ");252 strBuilder.Append(@" ) "); 253 253 } else if (node.Symbol is Multiplication) { 254 254 } else if (node.Symbol is Division) { … … 260 260 } 261 261 } else if (node.Symbol is Average) { 262 strBuilder.Append(@" ");262 strBuilder.Append(@" ) "); 263 263 } else if (node.Symbol is Logarithm) { 264 strBuilder.Append(@" ");264 strBuilder.Append(@" ) "); 265 265 } else if (node.Symbol is Exponential) { 266 strBuilder.Append(@" ");266 strBuilder.Append(@" ) "); 267 267 } else if (node.Symbol is Sine) { 268 strBuilder.Append(@" ");268 strBuilder.Append(@" ) "); 269 269 } else if (node.Symbol is Cosine) { 270 strBuilder.Append(@" ");270 strBuilder.Append(@" ) "); 271 271 } else if (node.Symbol is Tangent) { 272 strBuilder.Append(@" ");272 strBuilder.Append(@" ) "); 273 273 } else if (node.Symbol is GreaterThan) { 274 strBuilder.Append(@" ");274 strBuilder.Append(@" ) "); 275 275 } else if (node.Symbol is LessThan) { 276 strBuilder.Append(@" ");276 strBuilder.Append(@" ) "); 277 277 } else if (node.Symbol is And) { 278 strBuilder.Append(@" > 0 278 strBuilder.Append(@" > 0 ) ) "); 279 279 } else if (node.Symbol is Or) { 280 strBuilder.Append(@" > 0 280 strBuilder.Append(@" > 0 ) ) "); 281 281 } else if (node.Symbol is Not) { 282 strBuilder.Append(@" ");282 strBuilder.Append(@" ) "); 283 283 } else if (node.Symbol is IfThenElse) { 284 strBuilder.Append(@" 284 strBuilder.Append(@" ) ) "); 285 285 } else if (node.Symbol is Constant) { 286 286 } else if (node.Symbol is LaggedVariable) { … … 298 298 } else if (node.Symbol is Defun) { 299 299 } else if (node.Symbol is InvokeFunction) { 300 strBuilder.Append(@" ");300 strBuilder.Append(@" ) "); 301 301 } else if (node.Symbol is StartSymbol) { 302 302 } else if (node.Symbol is Argument) { 303 303 } else if (node.Symbol is Derivative) { 304 strBuilder.Append(@" }{dt} ");304 strBuilder.Append(@" ) }{dt} "); 305 305 } else if (node.Symbol is TimeLag) { 306 306 var laggedNode = node as ILaggedTreeNode; 307 307 currentLag = laggedNode.Lag; 308 308 } else if (node.Symbol is Power) { 309 strBuilder.Append(@" } ");309 strBuilder.Append(@" ) } "); 310 310 } else if (node.Symbol is Root) { 311 strBuilder.Append(@" }} ");311 strBuilder.Append(@" ) } ) } "); 312 312 } else if (node.Symbol is Integral) { 313 313 var laggedTreeNode = node as ILaggedTreeNode; 314 strBuilder.Append(@" ");314 strBuilder.Append(@" ) "); 315 315 } else if (node.Symbol is VariableCondition) { 316 316 strBuilder.Append(@"\left) ");
Note: See TracChangeset
for help on using the changeset viewer.