Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/21 11:50:57 (3 years ago)
Author:
gkronber
Message:

#3140: merged r18091:18131 from branch to trunk

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/HeuristicLab.Tests

  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs

    r17180 r18132  
    3535      var formatter = new InfixExpressionFormatter();
    3636      var parser = new InfixExpressionParser();
    37       Assert.AreEqual("0", Derive("3", "x"));
     37      Assert.AreEqual("0", Derive("<num=3>", "x"));
    3838      Assert.AreEqual("1", Derive("x", "x"));
    39       Assert.AreEqual("10", Derive("10*x", "x"));
    40       Assert.AreEqual("10", Derive("x*10", "x"));
     39      Assert.AreEqual("10", Derive("<num=10>*x", "x"));
     40      Assert.AreEqual("10", Derive("x*<num=10>", "x"));
    4141      Assert.AreEqual("(2*'x')", Derive("x*x", "x"));
    4242      Assert.AreEqual("((('x' * 'x') * 2) + ('x' * 'x'))", Derive("x*x*x", "x")); // simplifier does not merge (x*x)*2 + x*x  to 3*x*x
    43       Assert.AreEqual("0", Derive("10*x", "y"));
    44       Assert.AreEqual("20", Derive("10*x+20*y", "y"));
    45       Assert.AreEqual("6", Derive("2*3*x", "x"));
    46       Assert.AreEqual("(10*'y')", Derive("10*x*y+20*y", "x"));
     43      Assert.AreEqual("0", Derive("<num=10>*x", "y"));
     44      Assert.AreEqual("20", Derive("<num=10>*x+<num=20>*y", "y"));
     45      Assert.AreEqual("6", Derive("<num=2>*<num=3>*x", "x"));
     46      Assert.AreEqual("(10*'y')", Derive("<num=10>*x*y+<num=20>*y", "x"));
    4747      Assert.AreEqual("(1 / (SQR('x') * (-1)))", Derive("1/x", "x"));
    4848      Assert.AreEqual("('y' / (SQR('x') * (-1)))", Derive("y/x", "x"));
     
    5151      Assert.AreEqual("((((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + SQR('x'))))", Derive("(a+b)/(x+SQR(x))", "x"));
    5252      Assert.AreEqual("EXP('x')", Derive("exp(x)", "x"));
    53       Assert.AreEqual("(EXP((3*'x')) * 3)", Derive("exp(3*x)", "x"));
     53      Assert.AreEqual("(EXP((3*'x')) * 3)", Derive("exp(<num=3>*x)", "x"));
    5454      Assert.AreEqual("(1 / 'x')", Derive("log(x)", "x"));
    55       Assert.AreEqual("(1 / 'x')", Derive("log(3*x)", "x"));   // 3 * 1/(3*x)
    56       Assert.AreEqual("(1 / ('x' + (0.333333333333333*'y')))", Derive("log(3*x+y)", "x"));  // simplifier does not try to keep fractions
    57       Assert.AreEqual("(1 / (SQRT(((3*'x') + 'y')) * 0.666666666666667))", Derive("sqrt(3*x+y)", "x"));   // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y))
    58       Assert.AreEqual("(COS((3*'x')) * 3)", Derive("sin(3*x)", "x"));
    59       Assert.AreEqual("(SIN((3*'x')) * (-3))", Derive("cos(3*x)", "x"));
    60       Assert.AreEqual("(1 / (SQR(COS((3*'x'))) * 0.333333333333333))", Derive("tan(3*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator
     55      Assert.AreEqual("(1 / 'x')", Derive("log(<num=3>*x)", "x"));   // 3 * 1/(3*x)
     56      Assert.AreEqual("(1 / ('x' + (0.333333333333333*'y')))", Derive("log(<num=3>*x+y)", "x"));  // simplifier does not try to keep fractions
     57      Assert.AreEqual("(1 / (SQRT(((3*'x') + 'y')) * 0.666666666666667))", Derive("sqrt(<num=3>*x+y)", "x"));   // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y))
     58      Assert.AreEqual("(COS((3*'x')) * 3)", Derive("sin(<num=3>*x)", "x"));
     59      Assert.AreEqual("(SIN((3*'x')) * (-3))", Derive("cos(<num=3>*x)", "x"));
     60      Assert.AreEqual("(1 / (SQR(COS((3*'x'))) * 0.333333333333333))", Derive("tan(<num=3>*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator
    6161
    62       Assert.AreEqual("((9*'x') / ABS((3*'x')))", Derive("abs(3*x)", "x"));
     62      Assert.AreEqual("((9*'x') / ABS((3*'x')))", Derive("abs(<num=3>*x)", "x"));
    6363      Assert.AreEqual("(SQR('x') * 3)", Derive("cube(x)", "x"));
    6464      Assert.AreEqual("(1 / (SQR(CUBEROOT('x')) * 3))", Derive("cuberoot(x)", "x"));
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionCrossoverTest.cs

    r17180 r18132  
    110110      grammar.MinimumFunctionDefinitions = 0;
    111111
    112       var trees = Util.CreateRandomTrees(twister, dataset, grammar, PopulationSize, 1, MaxTreeLength, 0, 0);
     112      var trees = Util.CreateRandomTrees(twister, dataset, grammar, PopulationSize, MaxTreeLength);
    113113      foreach (ISymbolicExpressionTree tree in trees) {
    114114        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs

    r17950 r18132  
    141141      grammar.ConfigureAsDefaultRegressionGrammar();
    142142
    143       var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0);
     143      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 100);
    144144      foreach (ISymbolicExpressionTree tree in randomTrees) {
    145145        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
     
    155155
    156156      var grammar = new FullFunctionalExpressionGrammar();
    157       var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0);
     157      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 100);
    158158      foreach (ISymbolicExpressionTree tree in randomTrees) {
    159159        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
     
    169169
    170170      var grammar = new ArithmeticExpressionGrammar();
    171       var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0);
     171      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 100);
    172172      foreach (SymbolicExpressionTree tree in randomTrees) {
    173173        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
     
    249249
    250250      var rows = Enumerable.Range(0, numRows).ToList();
    251       var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 10, 0, 0);
     251      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 10);
    252252      foreach (ISymbolicExpressionTree tree in randomTrees) {
    253253        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
     
    299299      grammar.Symbols.First(x => x is Power).Enabled = false;
    300300
    301       var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 10, 0, 0);
     301      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 10);
    302302      foreach (ISymbolicExpressionTree tree in randomTrees) {
    303303        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs

    r17820 r18132  
    230230
    231231      #region abs
    232       AssertEqualAfterSimplification("(abs 2.0)", "2.0");
    233       AssertEqualAfterSimplification("(abs -2.0)", "2.0"); // constant folding
     232      AssertEqualAfterSimplification("(abs <num=2.0>)", "2.0");
     233      AssertEqualAfterSimplification("(abs <num=-2.0>)", "2.0"); // constant folding
    234234      AssertEqualAfterSimplification("(abs (exp (variable 2.0 x)))", "(exp (variable 2.0 x)))"); // exp is always positive
    235235      AssertEqualAfterSimplification("(abs (exp (variable 2.0 x)))", "(exp (variable 2.0 x)))"); // exp is always positive
     
    238238      AssertEqualAfterSimplification("(abs (cuberoot (variable 2.0 a)))", "(cuberoot (variable 2.0 a))"); // cuberoot is always positive (for our cases)
    239239
    240       AssertEqualAfterSimplification("(* (abs (variable 2.0 x)) 2.0)", "(abs (variable 4.0 x))");  // can multiply positive constants into abs
    241       AssertEqualAfterSimplification("(* (abs (variable 2.0 x)) -2.0)", "(* (abs (variable 4.0 x)) -1.0)"); // for negative constants keep the sign
     240      AssertEqualAfterSimplification("(* (abs (variable 2.0 x)) <num=2.0>)", "(abs (variable 4.0 x))");  // can multiply positive constants into abs
     241      AssertEqualAfterSimplification("(* (abs (variable 2.0 x)) <num=-2.0>)", "(* (abs (variable 4.0 x)) -1.0)"); // for negative constants keep the sign
    242242
    243243      AssertEqualAfterSimplification("(abs (* (variable 1.0 a) (variable 2.0 b)))", "(* (abs (variable 1.0 a)) (abs (variable 1.0 b)) 2.0))");
     
    265265
    266266      #region AQ
    267       AssertEqualAfterSimplification("(* (aq (variable 1.0 x) (variable 1.0 y)) 2.0)", "(aq (variable 2.0 x) (variable 1.0 y))");
    268       AssertEqualAfterSimplification("(/ (aq (variable 1.0 x) (variable 1.0 y)) 2.0)", "(aq (variable 0.5 x) (variable 1.0 y))");
     267      AssertEqualAfterSimplification("(* (aq (variable 1.0 x) (variable 1.0 y)) <num=2.0>)", "(aq (variable 2.0 x) (variable 1.0 y))");
     268      AssertEqualAfterSimplification("(/ (aq (variable 1.0 x) (variable 1.0 y)) <num=2.0>)", "(aq (variable 0.5 x) (variable 1.0 y))");
    269269
    270270      #endregion
    271271
    272272      #region do not drop subtrees with small weights
    273       AssertEqualAfterSimplification("(* 1e-14 (variable 1.0 a))", "(variable 1e-14 a)");
    274       AssertEqualAfterSimplification("(+ (variable 1.0 a) 1e-14)",
    275                                      "(+ (variable 1.0 a) 1e-14)");
     273      AssertEqualAfterSimplification("(* <num=1e-14> (variable 1.0 a))", "(variable 1e-14 a)");
     274      AssertEqualAfterSimplification("(+ (variable 1.0 a) <num=1e-14>)",
     275                                     "(+ (variable 1.0 a) <num=1e-14>)");
    276276      // a scenario where a term with small weight can have large effect
    277       AssertEqualAfterSimplification("(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)",
    278                                      "(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)");
     277      AssertEqualAfterSimplification("(+ (* (pow (variable 1.0 a) <num=10>) <num=1e-14>) 1.0)",
     278                                     "(+ (* (pow (variable 1.0 a) <num=10>) <num=1e-14>) 1.0)");
    279279      // a test case (from ticket #2985)
    280       AssertEqualAfterSimplification("(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)",
    281                                      "(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)");
     280      AssertEqualAfterSimplification("(+ (* (exp (variable 3.5861E+001 a)) <num=5.5606E-016>) <num=5.9323E-002>)",
     281                                     "(+ (* (exp (variable 3.5861E+001 a)) <num=5.5606E-016>) <num=5.9323E-002>)");
    282282      #endregion
    283283    }
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs

    r16869 r18132  
    7777      var twister = new MersenneTwister(31415);
    7878      var ds = Util.CreateRandomDataset(twister, Rows, Columns);
    79       var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 1, 100, 0, 0);
     79      var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 100);
    8080
    8181      double s = 0;
    8282      var sw = new Stopwatch();
    8383
    84       var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchVariableWeights = false, MatchConstantValues = false };
     84      var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchVariableWeights = false, MatchParameterValues = false };
    8585
    8686      sw.Start();
     
    115115      var twister = new MersenneTwister(31415);
    116116      var ds = Util.CreateRandomDataset(twister, Rows, Columns);
    117       var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 1, 100, 0, 0);
     117      var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 100);
    118118
    119       var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchConstantValues = strict, MatchVariableWeights = strict };
     119      var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchParameterValues = strict, MatchVariableWeights = strict };
    120120      var bottomUpSimilarity = 0d;
    121121      for (int i = 0; i < trees.Length - 1; ++i) {
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs

    r11916 r18132  
    5353      var twister = new MersenneTwister(31415);
    5454      var ds = Util.CreateRandomDataset(twister, Rows, Columns);
    55       var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 1, 100, 0, 0);
     55      var trees = Util.CreateRandomTrees(twister, ds, grammar, N, 100);
    5656
    5757      double s = 0;
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/Util.cs

    r17180 r18132  
    3535          varNode.Weight = twister.NextDouble() * 20.0 - 10.0;
    3636          varNode.VariableName = varNames[twister.Next(varNames.Count)];
    37         } else if (node is ConstantTreeNode) {
    38           var constantNode = node as ConstantTreeNode;
    39           constantNode.Value = twister.NextDouble() * 20.0 - 10.0;
     37        } else if (node is NumberTreeNode) {
     38          var numNode = node as NumberTreeNode;
     39          numNode.Value = twister.NextDouble() * 20.0 - 10.0;
    4040        }
    4141      }
     
    4444
    4545    public static ISymbolicExpressionTree[] CreateRandomTrees(MersenneTwister twister, Dataset dataset, ISymbolicExpressionGrammar grammar, int popSize) {
    46       return CreateRandomTrees(twister, dataset, grammar, popSize, 1, 200, 3, 3);
     46      return CreateRandomTrees(twister, dataset, grammar, popSize, 200);
    4747    }
    4848
    4949    public static ISymbolicExpressionTree[] CreateRandomTrees(MersenneTwister twister, Dataset dataset, ISymbolicExpressionGrammar grammar,
    50       int popSize, int minSize, int maxSize,
    51       int maxFunctionDefinitions, int maxFunctionArguments) {
     50      int popSize, int maxSize) {
    5251      foreach (Variable variableSymbol in grammar.Symbols.OfType<Variable>()) {
    5352        variableSymbol.VariableNames = dataset.VariableNames.Skip(1);
Note: See TracChangeset for help on using the changeset viewer.