Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5915 for trunk


Ignore:
Timestamp:
03/31/11 18:41:41 (14 years ago)
Author:
gkronber
Message:

#1418 Fixed bug in symbolic data analysis expression tree simplifier and added test cases.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r5809 r5915  
    905905      } else if (IsMultiplication(x) || IsDivision(x)) {
    906906        // x0 * x1 * .. * xn * -1 => x0 * x1 * .. * -xn
    907         x.RemoveSubtree(x.Subtrees.Count() - 1);
    908         x.AddSubtree(Negate(x.Subtrees.Last())); // last is maybe a constant, prefer to negate the constant
     907        var lastSubTree = x.Subtrees.Last();
     908        x.RemoveSubtree(x.SubtreesCount - 1);
     909        x.AddSubtree(Negate(lastSubTree)); // last is maybe a constant, prefer to negate the constant
    909910      } else {
    910911        // any other function
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs

    r5809 r5915  
    162162        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    163163      }
     164      {
     165        // exp transformation
     166        var actualTree = simplifier.Simplify(importer.Import("(exp (- (variable 2.0 a) (* (variable 3.0 b) (variable 4.0 c))))"));
     167        var expectedTree = importer.Import("(* (exp (variable 2.0 a)) (exp (* (variable 1.0 b) (variable 1.0 c) -12.0)))");
     168        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     169      }
     170      {
     171        // exp transformation
     172        var actualTree = simplifier.Simplify(importer.Import("(exp (- (variable 2.0 a) (* (variable 3.0 b) (cos (variable 4.0 c)))))"));
     173        var expectedTree = importer.Import("(* (exp (variable 2.0 a)) (exp (* (variable 1.0 b) (cos (variable 4.0 c)) -3.0)))");
     174        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     175      }
    164176      #endregion
    165177      #region power rules
Note: See TracChangeset for help on using the changeset viewer.