Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17790


Ignore:
Timestamp:
12/10/20 08:28:40 (4 years ago)
Author:
chaider
Message:

#3073 Merged trunk into branch

Location:
branches/3073_IA_constraint_splitting
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis

  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r17581 r17790  
    2929using HeuristicLab.Core;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     31using Microsoft.SqlServer.Server;
    3132
    3233namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    8384          if (!varNode.Weight.IsAlmost(1.0)) {
    8485            strBuilder.Append("(");
    85             if (constants != null) {
    86               strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", varNode.Weight);
    87             } else {
    88               strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
    89             }
     86            AppendConstant(strBuilder, constants, varNode.Weight, formatString, numberFormat);
    9087            strBuilder.Append("*");
    9188          }
    9289
    9390          strBuilder.Append("LAG(");
    94           if (varNode.VariableName.Contains("'"))
    95             strBuilder.AppendFormat("\"{0}\"", varNode.VariableName);
    96           else
    97             strBuilder.AppendFormat("'{0}'", varNode.VariableName);
    98 
     91          AppendVariableName(strBuilder, varNode.VariableName);
    9992          strBuilder.Append(", ")
    10093                    .AppendFormat(numberFormat, "{0}", varNode.Lag)
    10194                    .Append(")");
     95          if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
    10296        } else if (node.Symbol is Variable) {
    10397          var varNode = node as VariableTreeNode;
    10498          if (!varNode.Weight.IsAlmost(1.0)) {
    10599            strBuilder.Append("(");
    106             if (constants != null) {
    107               string constantKey = $"c_{constants.Count}";
    108               strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", constantKey);
    109               constants.Add(new KeyValuePair<string, double>(constantKey, varNode.Weight));
    110             } else {
    111               strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
    112             }
    113 
     100            AppendConstant(strBuilder, constants, varNode.Weight, formatString, numberFormat);
    114101            strBuilder.Append("*");
    115102          }
    116103
    117           if (varNode.VariableName.Contains("'"))
    118             strBuilder.AppendFormat("\"{0}\"", varNode.VariableName);
    119           else
    120             strBuilder.AppendFormat("'{0}'", varNode.VariableName);
     104          AppendVariableName(strBuilder, varNode.VariableName);
    121105
    122106          if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
    123107        } else if (node.Symbol is FactorVariable) {
    124108          var factorNode = node as FactorVariableTreeNode;
    125           if (factorNode.VariableName.Contains("'"))
    126             strBuilder.AppendFormat("\"{0}\"", factorNode.VariableName);
    127           else
    128             strBuilder.AppendFormat("'{0}'", factorNode.VariableName);
    129 
    130           strBuilder.AppendFormat("[{0}]",
    131             string.Join(", ", factorNode.Weights.Select(w => w.ToString(formatString, numberFormat))));
     109          AppendVariableName(strBuilder, factorNode.VariableName);
     110
     111          strBuilder.Append("[");
     112          for (int i = 0; i < factorNode.Weights.Length; i++) {
     113            if (i > 0) strBuilder.Append(", ");
     114            AppendConstant(strBuilder, constants, factorNode.Weights[i], formatString, numberFormat);
     115          }
     116          strBuilder.Append("]");
    132117        } else if (node.Symbol is BinaryFactorVariable) {
    133118          var factorNode = node as BinaryFactorVariableTreeNode;
    134119          if (!factorNode.Weight.IsAlmost(1.0)) {
    135120            strBuilder.Append("(");
    136             if (constants != null) {
    137               strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", factorNode.Weight);
    138             } else {
    139               strBuilder.Append(factorNode.Weight.ToString(formatString, numberFormat));
    140             }
     121            AppendConstant(strBuilder, constants, factorNode.Weight, formatString, numberFormat);
    141122
    142123            strBuilder.Append("*");
    143124          }
    144125
    145           if (factorNode.VariableName.Contains("'"))
    146             strBuilder.AppendFormat("\"{0}\"", factorNode.VariableName);
    147           else
    148             strBuilder.AppendFormat("'{0}'", factorNode.VariableName);
    149 
     126          AppendVariableName(strBuilder, factorNode.VariableName);
    150127          strBuilder.Append(" = ");
    151           if (factorNode.VariableValue.Contains("'"))
    152             strBuilder.AppendFormat("\"{0}\"", factorNode.VariableValue);
    153           else
    154             strBuilder.AppendFormat("'{0}'", factorNode.VariableValue);
     128          AppendVariableName(strBuilder, factorNode.VariableValue);
    155129
    156130          if (!factorNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
    157131        } else if (node.Symbol is Constant) {
    158132          var constNode = node as ConstantTreeNode;
    159           if (constants != null) {
    160             string constantKey = $"c_{constants.Count}";
    161 
    162             strBuilder.AppendFormat(CultureInfo.InvariantCulture, constantKey);
    163             constants.Add(new KeyValuePair<string, double>(constantKey, constNode.Value));
     133          if(constants==null && constNode.Value < 0) {
     134            strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat))
     135                      .Append(")"); // (-1
    164136          } else {
    165             if (constNode.Value >= 0.0)
    166               strBuilder.Append(constNode.Value.ToString(formatString, numberFormat));
    167             else
    168               strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat))
    169                         .Append(")"); // (-1
     137            AppendConstant(strBuilder, constants, constNode.Value, formatString, numberFormat);
    170138          }
    171139        }
    172140      }
     141    }
     142
     143    private static void AppendConstant(StringBuilder strBuilder, List<KeyValuePair<string, double>> constants, double value, string formatString, NumberFormatInfo numberFormat) {
     144      if (constants != null) {
     145        string constantKey = $"c_{constants.Count}";
     146        strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", constantKey);
     147        constants.Add(new KeyValuePair<string, double>(constantKey, value));
     148      } else {
     149        strBuilder.Append(value.ToString(formatString, numberFormat));
     150      }
     151    }
     152
     153    private static void AppendVariableName(StringBuilder strBuilder, string name) {
     154      if (name.Contains("'"))
     155        strBuilder.AppendFormat("\"{0}\"", name);
     156      else
     157        strBuilder.AppendFormat("'{0}'", name);
    173158    }
    174159
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r17180 r17790  
    154154          strBuilder.Append(" / Math.Sqrt(1 + Math.Pow(");
    155155          FormatRecursively(node.GetSubtree(1), strBuilder);
    156           strBuilder.Append(" , 2) )");
     156          strBuilder.Append(" , 2) ) )");
    157157        } else {
    158158          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter.");
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r17180 r17790  
    517517
    518518    private void FormatStartSymbol(StringBuilder strBuilder) {
    519       strBuilder.Append(targetVariable ?? "target_" + (targetCount++));
     519      strBuilder.Append(EscapeLatexString(targetVariable) ?? "target_{" + targetCount++ + "}");
    520520      if (containsTimeSeriesSymbol)
    521521        strBuilder.Append("(t)");
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Views

  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/PartialDependencePlot.cs

    r17579 r17790  
    646646
    647647    private void sharedFixedVariables_Reset(object sender, EventArgs e) {
     648      RecalculateInternalDataset();
    648649      var newValue = sharedFixedVariables.GetDoubleValue(FreeVariable, 0);
    649650      VerticalLineAnnotation.X = newValue;
    650       UpdateCursor(); // triggers update of InternalDataset
     651      UpdateCursor();
    651652    }
    652653
Note: See TracChangeset for help on using the changeset viewer.