Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12264 for trunk


Ignore:
Timestamp:
03/28/15 09:02:13 (10 years ago)
Author:
gkronber
Message:

#2363: fixed a bug in the simplifier introduced with r12262 (an a few minor code improvments)

File:
1 edited

Legend:

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

    r12262 r12264  
    287287        // make sum(x0..xn) / n
    288288        var sum = original.Subtrees
    289           .Select(x => GetSimplifiedTree(x))
    290           .Aggregate((a, b) => MakeSum(a, b));
     289          .Select(GetSimplifiedTree)
     290          .Aggregate(MakeSum);
    291291        return MakeFraction(sum, MakeConstant(original.Subtrees.Count()));
    292292      }
     
    299299        // simplify expressions x0..xn
    300300        // make multiplication (x0 * 1/(x1 * x1 * .. * xn))
    301         var first = original.Subtrees.First();
    302         var remaining = original.Subtrees.Skip(1);
     301        var first = original.GetSubtree(0);
     302        var second = original.GetSubtree(1);
     303        var remaining = original.Subtrees.Skip(2);
    303304        return
    304           MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate((a, b) => MakeProduct(a, GetSimplifiedTree(b)))));
     305          MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate(GetSimplifiedTree(second), (a, b) => MakeProduct(a, GetSimplifiedTree(b)))));
    305306      }
    306307    }
     
    831832    private void MergeVariablesInSum(ISymbolicExpressionTreeNode sum) {
    832833      var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees);
    833       while (sum.Subtrees.Count() > 0) sum.RemoveSubtree(0);
     834      while (sum.Subtrees.Any()) sum.RemoveSubtree(0);
    834835      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
    835836                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
     
    949950    private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) {
    950951      var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees);
    951       while (prod.Subtrees.Count() > 0) prod.RemoveSubtree(0);
     952      while (prod.Subtrees.Any()) prod.RemoveSubtree(0);
    952953      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
    953954                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
     
    10041005      } else if (IsAddition(x)) {
    10051006        // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn)       
    1006         List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);
    1007         while (x.Subtrees.Count() > 0) x.RemoveSubtree(0);
     1007        var subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);
     1008        while (x.Subtrees.Any()) x.RemoveSubtree(0);
    10081009        foreach (var subtree in subtrees) {
    10091010          x.AddSubtree(Negate(subtree));
Note: See TracChangeset for help on using the changeset viewer.