Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12277


Ignore:
Timestamp:
04/01/15 15:52:38 (10 years ago)
Author:
mkommend
Message:

#2363: Merged r12227, r12262 and r12264 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r12009 r12277  
    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 simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x));
     301        var first = original.GetSubtree(0);
     302        var second = original.GetSubtree(1);
     303        var remaining = original.Subtrees.Skip(2);
    302304        return
    303           MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeProduct(a, b))));
     305          MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate(GetSimplifiedTree(second), (a, b) => MakeProduct(a, GetSimplifiedTree(b)))));
    304306      }
    305307    }
     
    310312      } else {
    311313        return original.Subtrees
    312           .Select(x => GetSimplifiedTree(x))
    313           .Aggregate((a, b) => MakeProduct(a, b));
     314          .Select(GetSimplifiedTree)
     315          .Aggregate(MakeProduct);
    314316      }
    315317    }
     
    321323        // simplify expressions x0..xn
    322324        // make addition (x0,-x1..-xn)
    323         var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x));
    324         return simplifiedTrees.Take(1)
    325           .Concat(simplifiedTrees.Skip(1).Select(x => Negate(x)))
    326           .Aggregate((a, b) => MakeSum(a, b));
     325        var first = original.Subtrees.First();
     326        var remaining = original.Subtrees.Skip(1);
     327        return remaining.Aggregate(GetSimplifiedTree(first), (a, b) => MakeSum(a, Negate(GetSimplifiedTree(b))));
    327328      }
    328329    }
     
    335336        // make addition (x0..xn)
    336337        return original.Subtrees
    337           .Select(x => GetSimplifiedTree(x))
    338           .Aggregate((a, b) => MakeSum(a, b));
     338          .Select(GetSimplifiedTree)
     339          .Aggregate(MakeSum);
    339340      }
    340341    }
     
    345346    private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) {
    346347      return original.Subtrees
    347         .Select(x => GetSimplifiedTree(x))
    348         .Aggregate((a, b) => MakeOr(a, b));
     348        .Select(GetSimplifiedTree)
     349        .Aggregate(MakeOr);
    349350    }
    350351    private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) {
    351352      return original.Subtrees
    352         .Select(x => GetSimplifiedTree(x))
    353         .Aggregate((a, b) => MakeAnd(a, b));
     353        .Select(GetSimplifiedTree)
     354        .Aggregate(MakeAnd);
    354355    }
    355356    private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) {
     
    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.