Changeset 17624


Ignore:
Timestamp:
06/22/20 14:55:40 (3 weeks ago)
Author:
pfleck
Message:

#3040

  • Switched vector-simplification unit-test to infix notation to avoid ambiguities between the peek-string "VAR" for variables and the variance function.
  • Added additional unit tests for mean, length, stdev and var simplifications.
Location:
branches/3040_VectorBasedGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

    r17622 r17624  
    132132        { "EXPINT", new ExponentialIntegralEi()},
    133133        { "AQ", new AnalyticQuotient() },
    134         { "MEAN", new Average()},
     134        //{ "MEAN", new Average()},
    135135        { "IF", new IfThenElse()},
    136136        { "GT", new GreaterThan()},
     
    142142        { "DIFF", new Derivative()},
    143143        { "LAG", new LaggedVariable() },
     144        { "SUM", new Sum() },
     145        { "MEAN", new Mean() },
     146        { "LENGTH", new Length() },
     147        { "STDEV", new StandardDeviation() },
     148        { "VAR", new Variance() },
    144149      };
    145150
  • branches/3040_VectorBasedGP/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs

    r17606 r17624  
    271271
    272272      #region vectors
    273       AssertEqualAfterVectorSimplification(
    274         "(sum (vectorvariable 2.0 a))",
    275         "(* (sum (vectorvariable 1.0 a)) 2.0)");
    276       AssertEqualAfterVectorSimplification(
    277         "(sum (* 2.0 (vectorvariable 1.0 a)))",
    278         "(* (sum (vectorvariable 1.0 a)) 2.0)");
    279       AssertEqualAfterVectorSimplification(
    280         "(sum (+ 2.0 (vectorvariable 1.0 a)))",
    281         "(+ (* (length (vectorvariable 1.0 a)) 2.0)(sum (vectorvariable 1.0 a)) )");
     273      AssertEqualAfterVectorSimplification("remove aggregation for scalars from Sum",
     274        "SUM(a)",
     275        "a");
     276      AssertEqualAfterVectorSimplification("factor out multiplicative scalar from Sum",
     277        "SUM(a{} * 2.0)",
     278        "SUM(a{}) * 2.0");
     279      AssertEqualAfterVectorSimplification("factor out additive scalar from Sum",
     280        "SUM(a{} + 2.0)",
     281        "LENGTH(a{}) * 2.0 + SUM(a{})");
     282
     283      AssertEqualAfterVectorSimplification("remove aggregation for scalars from Mean",
     284        "MEAN(a)",
     285        "a");
     286      AssertEqualAfterVectorSimplification("factor out multiplicative scalar from Mean",
     287        "MEAN(2.0 * a{})",
     288        "MEAN(a{}) * 2.0");
     289      AssertEqualAfterVectorSimplification("factor out additive scalar from Mean",
     290        "MEAN(a{} + 2.0)",
     291        "MEAN(a{}) + 2.0");
     292
     293      AssertEqualAfterVectorSimplification("remove aggregation for scalars from Length",
     294        "LENGTH(a)",
     295        "1.0");
     296      AssertEqualAfterVectorSimplification("factor out multiplicative scalar from Length",
     297        "LENGTH(a{} * 2.0)",
     298        "LENGTH(a{})");
     299      AssertEqualAfterVectorSimplification("factor out additive scalar from Length",
     300        "LENGTH(a{} + 2.0)",
     301        "LENGTH(a{})");
     302
     303      AssertEqualAfterVectorSimplification("remove aggregation for scalars from StandardDeviation",
     304        "STDEV(a)",
     305        "0.0");
     306      AssertEqualAfterVectorSimplification("factor out multiplicative scalar from StandardDeviation",
     307        "STDEV(2.0 * a{})",
     308        "STDEV(a{}) * 2.0");
     309      AssertEqualAfterVectorSimplification("factor out additive scalar from StandardDeviation",
     310        "STDEV(a{} + 2.0)",
     311        "STDEV(a{})");
     312
     313      AssertEqualAfterVectorSimplification("remove aggregation for scalars from Variance",
     314        "VAR(a)",
     315        "0.0");
     316      AssertEqualAfterVectorSimplification("factor out multiplicative scalar from Variance",
     317        "VAR(a{} * 2.0)",
     318        "VAR(a{}) * 4.0");
     319      AssertEqualAfterVectorSimplification("factor out additive scalar from Variance",
     320        "VAR(a{} + 2.0)",
     321        "VAR(a{})");
    282322      #endregion
    283323    }
     
    292332    }
    293333
    294     private void AssertEqualAfterVectorSimplification(string original, string expected) {
    295       var formatter = new SymbolicExpressionTreeStringFormatter();
    296       var importer = new SymbolicExpressionImporter();
     334    private void AssertEqualAfterVectorSimplification(string msg, string original, string expected) {
     335      var formatter = new InfixExpressionFormatter();
     336      var parser = new InfixExpressionParser();
    297337      var simplifier = new VectorTreeSimplifier(new SymbolicDataAnalysisExpressionTreeVectorInterpreter());
    298       var actualTree = simplifier.Simplify(importer.Import(original));
    299       var expectedTree = importer.Import(expected);
    300       Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     338      var actualTree = simplifier.Simplify(parser.Parse(original));
     339      var expectedTree = parser.Parse(expected);
     340      Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree), msg);
    301341    }
    302342  }
Note: See TracChangeset for help on using the changeset viewer.