Changeset 17603


Ignore:
Timestamp:
06/16/20 13:37:57 (3 months ago)
Author:
pfleck
Message:

#3040

  • Added additive simplification rules for stdev and variance symbols.
  • Extended simplifications of constants to simplification of all scalar-nodes for aggregation symbols.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/VectorTreeSimplifier.cs

    r17602 r17603  
    13991399
    14001400    private ISymbolicExpressionTreeNode MakeSumAggregation(ISymbolicExpressionTreeNode node) {
    1401       if (IsConstant(node)) { // assumes scalar constant
     1401      if (IsScalarNode(node)) {
    14021402        return node;
    14031403      } else if (IsAddition(node) || IsSubtraction(node)) {
     
    14671467
    14681468    private ISymbolicExpressionTreeNode MakeMeanAggregation(ISymbolicExpressionTreeNode node) {
    1469       if (IsConstant(node)) { // assumes scalar constant
     1469      if (IsScalarNode(node)) {
    14701470        return node;
    14711471      } else if (IsAddition(node) || IsSubtraction(node)) {
     
    15321532
    15331533    private ISymbolicExpressionTreeNode MakeLengthAggregation(ISymbolicExpressionTreeNode node) {
    1534       if (IsConstant(node)) { // assumes scalar constant
     1534      if (IsScalarNode(node)) {
    15351535        return MakeConstant(1.0);
    15361536      } else if (IsAddition(node) || IsSubtraction(node)) {
     
    15841584
    15851585    private ISymbolicExpressionTreeNode MakeStandardDeviationAggregation(ISymbolicExpressionTreeNode node) {
    1586       if (IsConstant(node)) {
     1586      if (IsScalarNode(node)) {
    15871587        return MakeConstant(0.0);
     1588      } else if (IsAddition(node) || IsSubtraction(node)) { // scalars drop out
     1589        var terms = node.Subtrees;
     1590
     1591        var scalarTerms = terms.Where(IsScalarNode).ToList();
     1592        var remainingTerms = terms.Except(scalarTerms).ToList();
     1593
     1594        if (remainingTerms.Any()) {
     1595          var vectorNode = remainingTerms.Aggregate(MakeSum);
     1596
     1597          var stdevNode = standardDeviationSymbol.CreateTreeNode();
     1598          stdevNode.AddSubtree(vectorNode);
     1599
     1600          return stdevNode;
     1601        } else if (scalarTerms.Any()) {
     1602          return MakeConstant(0.0);
     1603        } else
     1604          throw new InvalidOperationException("Addition does not contain any terms to simplify.");
    15881605      } else if (IsMultiplication(node) || IsDivision(node)) {
    15891606        var factors = node.Subtrees;
     
    16251642
    16261643    private ISymbolicExpressionTreeNode MakeVarianceAggregation(ISymbolicExpressionTreeNode node) {
    1627       if (IsConstant(node)) {
     1644      if (IsScalarNode(node)) {
    16281645        return MakeConstant(0.0);
     1646      } else if (IsAddition(node) || IsSubtraction(node)) { // scalars drop out
     1647        var terms = node.Subtrees;
     1648
     1649        var scalarTerms = terms.Where(IsScalarNode).ToList();
     1650        var remainingTerms = terms.Except(scalarTerms).ToList();
     1651
     1652        if (remainingTerms.Any()) {
     1653          var vectorNode = remainingTerms.Aggregate(MakeSum);
     1654
     1655          var varNode = varianceSymbol.CreateTreeNode();
     1656          varNode.AddSubtree(vectorNode);
     1657
     1658          return varNode;
     1659        } else if (scalarTerms.Any()) {
     1660          return MakeConstant(0.0);
     1661        } else
     1662          throw new InvalidOperationException("Addition does not contain any terms to simplify.");
    16291663      } else if (IsMultiplication(node) || IsDivision(node)) {
    16301664        var factors = node.Subtrees;
Note: See TracChangeset for help on using the changeset viewer.