Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/17/20 16:22:18 (4 years ago)
Author:
pfleck
Message:

#3040

  • Extended importer (vectorvariable, vec-aggregations, ...).
  • Started adding unit test for vector simplifications.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs

    r17180 r17606  
    193193
    194194      AssertEqualAfterSimplification("(+ 3.0 (binfactor a val 4.0 ))", "(+ (binfactor a val 4.0 ) 3.0))"); // not allowed
    195       AssertEqualAfterSimplification("(- 3.0 (binfactor a val 4.0 ))", "(+ (binfactor a val -4.0 ) 3.0)"); 
     195      AssertEqualAfterSimplification("(- 3.0 (binfactor a val 4.0 ))", "(+ (binfactor a val -4.0 ) 3.0)");
    196196      AssertEqualAfterSimplification("(+ (binfactor a val 4.0 ) 3.0)", "(+ (binfactor a val 4.0 ) 3.0)");  // not allowed
    197       AssertEqualAfterSimplification("(- (binfactor a val 4.0 ) 3.0)", "(+ (binfactor a val 4.0 ) -3.0)"); 
     197      AssertEqualAfterSimplification("(- (binfactor a val 4.0 ) 3.0)", "(+ (binfactor a val 4.0 ) -3.0)");
    198198      AssertEqualAfterSimplification("(* 2.0 (binfactor a val 4.0))", "(binfactor a val 8.0 )");
    199199      AssertEqualAfterSimplification("(* (binfactor a val 4.0) 2.0)", "(binfactor a val 8.0 )");
     
    202202
    203203      // exp( binfactor w val=a) = if(val=a) exp(w) else exp(0) = binfactor( (exp(w) - 1) val a) + 1
    204       AssertEqualAfterSimplification("(exp (binfactor a val 3.0))", 
     204      AssertEqualAfterSimplification("(exp (binfactor a val 3.0))",
    205205        string.Format(CultureInfo.InvariantCulture, "(+ (binfactor a val {0}) 1.0)", Math.Exp(3.0) - 1)
    206         ); 
     206        );
    207207      AssertEqualAfterSimplification("(sqrt (binfactor a val 16.0))", "(binfactor a val 4.0))"); // sqrt(0) = 0
    208208      AssertEqualAfterSimplification("(sqr (binfactor a val 3.0))", "(binfactor a val 9.0))"); // 0*0 = 0
     
    212212      AssertEqualAfterSimplification("(sin (binfactor a val 2.0) )",
    213213        string.Format(CultureInfo.InvariantCulture, "(binfactor a val {0}))", Math.Sin(2.0))); // sin(0) = 0
    214       AssertEqualAfterSimplification("(cos (binfactor a val 2.0) )", 
     214      AssertEqualAfterSimplification("(cos (binfactor a val 2.0) )",
    215215        string.Format(CultureInfo.InvariantCulture, "(+ (binfactor a val {0}) 1.0)", Math.Cos(2.0) - 1)); // cos(0) = 1
    216216      AssertEqualAfterSimplification("(tan (binfactor a val 2.0) )",
     
    269269
    270270      #endregion
     271
     272      #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)) )");
     282      #endregion
    271283    }
    272284
     
    278290      var expectedTree = importer.Import(expected);
    279291      Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    280 
     292    }
     293
     294    private void AssertEqualAfterVectorSimplification(string original, string expected) {
     295      var formatter = new SymbolicExpressionTreeStringFormatter();
     296      var importer = new SymbolicExpressionImporter();
     297      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));
    281301    }
    282302  }
Note: See TracChangeset for help on using the changeset viewer.