Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17797


Ignore:
Timestamp:
12/22/20 08:48:27 (3 years ago)
Author:
gkronber
Message:

#2985: removed all usages of IsAlmost from TreeSimplifier (+ minor rearrangement of operands in unit test to match the actual output).

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs

    r17180 r17797  
    933933        var constB = b as ConstantTreeNode;
    934934        var constBValue = Math.Round(constB.Value);
    935         if (constBValue.IsAlmost(1.0)) {
     935        if (constBValue == 1.0) {
    936936          return a;
    937         } else if (constBValue.IsAlmost(0.0)) {
     937        } else if (constBValue == 0.0) {
    938938          return MakeConstant(1.0);
    939         } else if (constBValue.IsAlmost(-1.0)) {
     939        } else if (constBValue == -1.0) {
    940940          return MakeFraction(MakeConstant(1.0), a);
    941941        } else if (constBValue < 0) {
     
    987987        var constB = b as ConstantTreeNode;
    988988        double exponent = Math.Round(constB.Value);
    989         if (exponent.IsAlmost(0.0)) {
     989        if (exponent == 0.0) {
    990990          return MakeConstant(1.0);
    991         } else if (exponent.IsAlmost(1.0)) {
     991        } else if (exponent == 1.0) {
    992992          return a;
    993         } else if (exponent.IsAlmost(-1.0)) {
     993        } else if (exponent == -1.0) {
    994994          return MakeFraction(MakeConstant(1.0), a);
    995995        } else if (exponent < 0) {
     
    10181018        // fold constants
    10191019        return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value);
    1020       } else if ((IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0))) {
     1020      } else if ((IsConstant(a) && ((ConstantTreeNode)a).Value != 1.0)) {
    10211021        return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a)));
    10221022      } else if (IsVariableBase(a) && IsConstant(b)) {
     
    10941094        // b is not constant => make sure constant is on the right
    10951095        return MakeSum(b, a);
    1096       } else if (IsConstant(b) && ((ConstantTreeNode)b).Value.IsAlmost(0.0)) {
     1096      } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 0.0) {
    10971097        // x + 0 => x
    10981098        return a;
     
    12101210      foreach (var unchangedSubtree in unchangedSubtrees)
    12111211        sum.AddSubtree(unchangedSubtree);
    1212       if (!constant.IsAlmost(0.0)) {
     1212      if (constant != 0.0) {
    12131213        sum.AddSubtree(MakeConstant(constant));
    12141214      }
     
    12681268        if (wi < 0) throw new ArgumentException();
    12691269        return MakeBinFactor(node1.Symbol, node1.VariableName, node1.VariableValue, node1.Weight * node0.Weights[wi]);
    1270       } else if (IsConstant(b) && ((ConstantTreeNode)b).Value.IsAlmost(1.0)) {
     1270      } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 1.0) {
    12711271        // $ * 1.0 => $
    12721272        return a;
    1273       } else if (IsConstant(b) && ((ConstantTreeNode)b).Value.IsAlmost(0.0)) {
     1273      } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 0.0) {
    12741274        return MakeConstant(0);
    12751275      } else if (IsConstant(b) && IsVariableBase(a)) {
     
    14191419        prod.AddSubtree(unchangedSubtree);
    14201420
    1421       if (!constantProduct.IsAlmost(1.0)) {
     1421      if (constantProduct != 1.0) {
    14221422        prod.AddSubtree(MakeConstant(constantProduct));
    14231423      }
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs

    r17796 r17797  
    272272      #region do not drop subtrees with small weights
    273273      AssertEqualAfterSimplification("(* 1e-14 (variable 1.0 a))", "(variable 1e-14 a)");
    274       AssertEqualAfterSimplification("(+ 1e-14 (variable 1.0 a))", "(+ 1e-14 (variable 1.0 a))");
     274      AssertEqualAfterSimplification("(+ (variable 1.0 a) 1e-14)",
     275                                     "(+ (variable 1.0 a) 1e-14)");
    275276      // a scenario where a term with small weight can have large effect
    276       AssertEqualAfterSimplification("(+ (* 1e-14 (pow (variable 1.0 a) 10)) 1.0)",
    277                                      "(+ (* 1e-14 (pow (variable 1.0 a) 10)) 1.0)");
     277      AssertEqualAfterSimplification("(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)",
     278                                     "(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)");
    278279      // a test case (from ticket #2985)
    279       AssertEqualAfterSimplification("(+ 5.9323E-002 (* 5.5606E-016 (exp (variable 3.5861E+001 a))))",
    280                                      "(+ 5.9323E-002 (* 5.5606E-016 (exp (variable 3.5861E+001 a))))");
     280      AssertEqualAfterSimplification("(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)",
     281                                     "(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)");
    281282      #endregion
    282283    }
Note: See TracChangeset for help on using the changeset viewer.