Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17827


Ignore:
Timestamp:
01/31/21 08:08:32 (4 years ago)
Author:
gkronber
Message:

#3073 merged r17811:17826 from trunk to branch

Location:
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
5 edited

Legend:

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

  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs

    r17798 r17827  
    934934        var constBValue = Math.Round(constB.Value);
    935935        if (constBValue == 1.0) {
     936          // root(a, 1) => a
    936937          return a;
    937938        } else if (constBValue == 0.0) {
    938           return MakeConstant(1.0);
     939          // root(a, 0) is not defined
     940          //return MakeConstant(1.0);
     941          return MakeConstant(double.NaN);
    939942        } else if (constBValue == -1.0) {
     943          // root(a, -1) => a^(-1/1) => 1/a
    940944          return MakeFraction(MakeConstant(1.0), a);
    941945        } else if (constBValue < 0) {
     946          // root(a, -b) => a^(-1/b) => (1/a)^(1/b) => root(1, b) / root(a, b) => 1 / root(a, b)
    942947          var rootNode = rootSymbol.CreateTreeNode();
    943948          rootNode.AddSubtree(a);
     
    988993        double exponent = Math.Round(constB.Value);
    989994        if (exponent == 0.0) {
     995          // a^0 => 1
    990996          return MakeConstant(1.0);
    991997        } else if (exponent == 1.0) {
     998          // a^1 => a
    992999          return a;
    9931000        } else if (exponent == -1.0) {
     1001          // a^-1 => 1/a
    9941002          return MakeFraction(MakeConstant(1.0), a);
    9951003        } else if (exponent < 0) {
     1004          // a^-b => (1/a)^b => 1/(a^b)
    9961005          var powNode = powSymbol.CreateTreeNode();
    9971006          powNode.AddSubtree(a);
     
    10191028        return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value);
    10201029      } else if ((IsConstant(a) && ((ConstantTreeNode)a).Value != 1.0)) {
     1030        // a / x => (a * 1/a) / (x * 1/a) => 1 / (x * 1/a)
    10211031        return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a)));
    10221032      } else if (IsVariableBase(a) && IsConstant(b)) {
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs

    r17180 r17827  
    258258      if (node.Symbol is CubeRoot) {
    259259        return cbrt(ConvertToAutoDiff(node.GetSubtree(0)));
     260      }
     261      if (node.Symbol is Power) {
     262        var powerNode = node.GetSubtree(1) as ConstantTreeNode;
     263        if (powerNode == null)
     264          throw new NotSupportedException("Only integer powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol.");
     265        var intPower = Math.Truncate(powerNode.Value);
     266        if (intPower != powerNode.Value)
     267          throw new NotSupportedException("Only integer powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol.");
     268        return AutoDiff.TermBuilder.Power(ConvertToAutoDiff(node.GetSubtree(0)), intPower);
    260269      }
    261270      if (node.Symbol is Sine) {
     
    340349          !(n.Symbol is AnalyticQuotient) &&
    341350          !(n.Symbol is Cube) &&
    342           !(n.Symbol is CubeRoot)
     351          !(n.Symbol is CubeRoot) &&
     352          !(n.Symbol is Power)
    343353        select n).Any();
    344354      return !containsUnknownSymbol;
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r17790 r17827  
    2929using HeuristicLab.Core;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    31 using Microsoft.SqlServer.Server;
    3231
    3332namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3938        // operators
    4039        if (token == "+" || token == "-" || token == "OR" || token == "XOR" ||
    41             token == "*" || token == "/" || token == "AND" ||
    42             token == "^") {
     40            token == "*" || token == "/" || token == "AND") {
    4341          strBuilder.Append("(");
    4442          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants);
     
    4745            strBuilder.Append(" ").Append(token).Append(" ");
    4846            FormatRecursively(subtree, strBuilder, numberFormat, formatString, constants);
     47          }
     48
     49          strBuilder.Append(")");
     50        } else if (token == "^") {
     51          // handle integer powers directly
     52          strBuilder.Append("(");
     53          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants);
     54
     55          var power = node.GetSubtree(1);
     56          if(power is ConstantTreeNode constNode && Math.Truncate(constNode.Value) == constNode.Value) {
     57            strBuilder.Append(" ").Append(token).Append(" ").Append(constNode.Value.ToString(formatString, numberFormat));
     58          } else {
     59            strBuilder.Append(" ").Append(token).Append(" ");
     60            FormatRecursively(power, strBuilder, numberFormat, formatString, constants);
    4961          }
    5062
     
    131143        } else if (node.Symbol is Constant) {
    132144          var constNode = node as ConstantTreeNode;
    133           if(constants==null && constNode.Value < 0) {
     145          if (constants == null && constNode.Value < 0) {
    134146            strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat))
    135147                      .Append(")"); // (-1
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r17790 r17827  
    517517
    518518    private void FormatStartSymbol(StringBuilder strBuilder) {
    519       strBuilder.Append(EscapeLatexString(targetVariable) ?? "target_{" + targetCount++ + "}");
     519      strBuilder.Append(targetVariable != null ? EscapeLatexString(targetVariable) : "\\text{target}_{" + targetCount++ + "}");
    520520      if (containsTimeSeriesSymbol)
    521521        strBuilder.Append("(t)");
Note: See TracChangeset for help on using the changeset viewer.