- Timestamp:
- 12/15/21 11:50:57 (3 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/3140_NumberSymbol (added) merged: 18091,18093,18100,18112-18121,18123-18131
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Tests
- Property svn:mergeinfo changed
/branches/3140_NumberSymbol/HeuristicLab.Tests (added) merged: 18119-18120,18123,18126-18127,18131
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs
r17180 r18132 35 35 var formatter = new InfixExpressionFormatter(); 36 36 var parser = new InfixExpressionParser(); 37 Assert.AreEqual("0", Derive(" 3", "x"));37 Assert.AreEqual("0", Derive("<num=3>", "x")); 38 38 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")); 41 41 Assert.AreEqual("(2*'x')", Derive("x*x", "x")); 42 42 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")); 47 47 Assert.AreEqual("(1 / (SQR('x') * (-1)))", Derive("1/x", "x")); 48 48 Assert.AreEqual("('y' / (SQR('x') * (-1)))", Derive("y/x", "x")); … … 51 51 Assert.AreEqual("((((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + SQR('x'))))", Derive("(a+b)/(x+SQR(x))", "x")); 52 52 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")); 54 54 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 fractions57 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 denominator55 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 61 61 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")); 63 63 Assert.AreEqual("(SQR('x') * 3)", Derive("cube(x)", "x")); 64 64 Assert.AreEqual("(1 / (SQR(CUBEROOT('x')) * 3))", Derive("cuberoot(x)", "x")); -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionCrossoverTest.cs
r17180 r18132 110 110 grammar.MinimumFunctionDefinitions = 0; 111 111 112 var trees = Util.CreateRandomTrees(twister, dataset, grammar, PopulationSize, 1, MaxTreeLength, 0, 0);112 var trees = Util.CreateRandomTrees(twister, dataset, grammar, PopulationSize, MaxTreeLength); 113 113 foreach (ISymbolicExpressionTree tree in trees) { 114 114 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r17950 r18132 141 141 grammar.ConfigureAsDefaultRegressionGrammar(); 142 142 143 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1 , 100, 0,0);143 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 100); 144 144 foreach (ISymbolicExpressionTree tree in randomTrees) { 145 145 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); … … 155 155 156 156 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); 158 158 foreach (ISymbolicExpressionTree tree in randomTrees) { 159 159 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); … … 169 169 170 170 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); 172 172 foreach (SymbolicExpressionTree tree in randomTrees) { 173 173 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); … … 249 249 250 250 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); 252 252 foreach (ISymbolicExpressionTree tree in randomTrees) { 253 253 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); … … 299 299 grammar.Symbols.First(x => x is Power).Enabled = false; 300 300 301 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1 , 10, 0,0);301 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 10); 302 302 foreach (ISymbolicExpressionTree tree in randomTrees) { 303 303 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs
r17820 r18132 230 230 231 231 #region abs 232 AssertEqualAfterSimplification("(abs 2.0)", "2.0");233 AssertEqualAfterSimplification("(abs -2.0)", "2.0"); // constant folding232 AssertEqualAfterSimplification("(abs <num=2.0>)", "2.0"); 233 AssertEqualAfterSimplification("(abs <num=-2.0>)", "2.0"); // constant folding 234 234 AssertEqualAfterSimplification("(abs (exp (variable 2.0 x)))", "(exp (variable 2.0 x)))"); // exp is always positive 235 235 AssertEqualAfterSimplification("(abs (exp (variable 2.0 x)))", "(exp (variable 2.0 x)))"); // exp is always positive … … 238 238 AssertEqualAfterSimplification("(abs (cuberoot (variable 2.0 a)))", "(cuberoot (variable 2.0 a))"); // cuberoot is always positive (for our cases) 239 239 240 AssertEqualAfterSimplification("(* (abs (variable 2.0 x)) 2.0)", "(abs (variable 4.0 x))"); // can multiply positive constants into abs241 AssertEqualAfterSimplification("(* (abs (variable 2.0 x)) -2.0)", "(* (abs (variable 4.0 x)) -1.0)"); // for negative constants keep the sign240 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 242 242 243 243 AssertEqualAfterSimplification("(abs (* (variable 1.0 a) (variable 2.0 b)))", "(* (abs (variable 1.0 a)) (abs (variable 1.0 b)) 2.0))"); … … 265 265 266 266 #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))"); 269 269 270 270 #endregion 271 271 272 272 #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>)"); 276 276 // 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)"); 279 279 // 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>)"); 282 282 #endregion 283 283 } -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs
r16869 r18132 77 77 var twister = new MersenneTwister(31415); 78 78 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); 80 80 81 81 double s = 0; 82 82 var sw = new Stopwatch(); 83 83 84 var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchVariableWeights = false, Match ConstantValues = false };84 var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchVariableWeights = false, MatchParameterValues = false }; 85 85 86 86 sw.Start(); … … 115 115 var twister = new MersenneTwister(31415); 116 116 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); 118 118 119 var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { Match ConstantValues = strict, MatchVariableWeights = strict };119 var similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchParameterValues = strict, MatchVariableWeights = strict }; 120 120 var bottomUpSimilarity = 0d; 121 121 for (int i = 0; i < trees.Length - 1; ++i) { -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs
r11916 r18132 53 53 var twister = new MersenneTwister(31415); 54 54 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); 56 56 57 57 double s = 0; -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/Util.cs
r17180 r18132 35 35 varNode.Weight = twister.NextDouble() * 20.0 - 10.0; 36 36 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; 40 40 } 41 41 } … … 44 44 45 45 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); 47 47 } 48 48 49 49 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) { 52 51 foreach (Variable variableSymbol in grammar.Symbols.OfType<Variable>()) { 53 52 variableSymbol.VariableNames = dataset.VariableNames.Skip(1);
Note: See TracChangeset
for help on using the changeset viewer.