Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/31/10 15:58:04 (14 years ago)
Author:
gkronber
Message:

Added support for simplification of average functions and improved simplification of division function. #1026.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs

    r3494 r3876  
    6767        // return the correct argument sub-tree (already macro-expanded)
    6868        return (SymbolicExpressionTreeNode)argumentTrees[argSym.ArgumentIndex].Clone();
    69       } else if(node.Symbol is StartSymbol) {
     69      } else if (node.Symbol is StartSymbol) {
    7070        return MacroExpand(root, subtrees[0], argumentTrees);
    7171      } else {
     
    136136          return
    137137            MakeMultiplication(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeMultiplication(a, b))));
     138        }
     139      } else if (IsAverage(original)) {
     140        if (original.SubTrees.Count == 1) {
     141          return GetSimplifiedTree(original.SubTrees[0]);
     142        } else {
     143          // simpliy expressions x0..xn
     144          // make sum(x0..xn) / n
     145          Trace.Assert(original.SubTrees.Count > 1);
     146          var sum = original.SubTrees
     147            .Select(x => GetSimplifiedTree(x))
     148            .Aggregate((a, b) => MakeAddition(a, b));
     149          return MakeDivision(sum, MakeConstant(original.SubTrees.Count));
    138150        }
    139151      } else {
     
    297309      } else if (IsConstant(b) && IsAddition(a)) {
    298310        return a.SubTrees.Select(x => MakeMultiplication(x, b)).Aggregate((c, d) => MakeAddition(c, d));
     311      } else if(IsDivision(a) && IsDivision(b)) {
     312        return MakeDivision(MakeMultiplication(a.SubTrees[0], b.SubTrees[0]), MakeMultiplication(a.SubTrees[1], b.SubTrees[1]));
    299313      } else if (IsDivision(a)) {
    300314        Trace.Assert(a.SubTrees.Count == 2);
     
    351365      return original.Symbol is Constant;
    352366    }
     367
     368    private bool IsAverage(SymbolicExpressionTreeNode original) {
     369      return original.Symbol is Average;
     370    }
    353371    #endregion
    354372
Note: See TracChangeset for help on using the changeset viewer.