Ignore:
Timestamp:
09/26/16 18:26:45 (3 years ago)
Author:
gkronber
Message:

#2632: merged r14255 from trunk to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r14186 r14309  
    3636    private int targetCount;
    3737    private int currentLag;
     38    private string targetVariable;
     39    private bool containsTimeSeriesSymbol;
    3840
    3941    [StorableConstructor]
     
    5557
    5658    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     59      return Format(symbolicExpressionTree, null);
     60    }
     61    public string Format(ISymbolicExpressionTree symbolicExpressionTree, string targetVariable) {
    5762      try {
    5863        StringBuilder strBuilder = new StringBuilder();
    5964        constants.Clear();
     65        this.targetVariable = targetVariable;
     66        containsTimeSeriesSymbol = symbolicExpressionTree.IterateNodesBreadth().Any(n => IsTimeSeriesSymbol(n.Symbol));
    6067        strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root));
    6168        return strBuilder.ToString();
     
    6471        return ex.Message + Environment.NewLine + ex.StackTrace;
    6572      }
     73    }
     74    static bool IsTimeSeriesSymbol(ISymbol s) {
     75      return s is TimeLag || s is Integral || s is Derivative || s is LaggedVariable;
    6676    }
    6777
     
    197207        strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
    198208      } else if (node.Symbol is StartSymbol) {
    199         strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
     209        FormatStartSymbol(strBuilder);
    200210      } else if (node.Symbol is Argument) {
    201211        var argSym = node.Symbol as Argument;
     
    303313      } else if (node.Symbol is StartSymbol) {
    304314        strBuilder.Append(@"\\" + Environment.NewLine);
    305         strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
     315        FormatStartSymbol(strBuilder);
    306316      } else if (node.Symbol is Power) {
    307317        strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
     
    433443    }
    434444
     445    private void FormatStartSymbol(StringBuilder strBuilder) {
     446      strBuilder.Append(targetVariable ?? "target_" + (targetCount++));
     447      if (containsTimeSeriesSymbol)
     448        strBuilder.Append("(t)");
     449      strBuilder.Append(" & = ");
     450    }
     451
    435452    private string LagToString(int lag) {
    436453      if (lag < 0) {
Note: See TracChangeset for help on using the changeset viewer.