Changeset 16711 for branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4
- Timestamp:
- 03/25/19 17:18:21 (6 years ago)
- Location:
- branches/2936_GQAPIntegration/HeuristicLab.Tests
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/2936_GQAPIntegration/HeuristicLab.Tests
- Property svn:mergeinfo changed
-
branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs
r15583 r16711 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 61 61 62 62 Console.WriteLine(formatter.Format(parser.Parse("log(3)"))); 63 Console.WriteLine(formatter.Format(parser.Parse("log(-3)"))); 63 Console.WriteLine(formatter.Format(parser.Parse("log(-3)"))); // should produce log(-3) as output 64 64 Console.WriteLine(formatter.Format(parser.Parse("exp(3)"))); 65 Console.WriteLine(formatter.Format(parser.Parse("exp(-3)"))); 65 Console.WriteLine(formatter.Format(parser.Parse("exp(-3)"))); // should produce exp(-3) as output 66 66 Console.WriteLine(formatter.Format(parser.Parse("sqrt(3)"))); 67 67 68 Console.WriteLine(formatter.Format(parser.Parse("sqr((-3))"))); 68 Console.WriteLine(formatter.Format(parser.Parse("sqr((-3))"))); // should produce sqr((-3)) as output 69 69 70 Console.WriteLine(formatter.Format(parser.Parse("3/3+2/2+1/1"))); 71 Console.WriteLine(formatter.Format(parser.Parse("-3+30-2+20-1+10"))); 70 Console.WriteLine(formatter.Format(parser.Parse("3/3+2/2+1/1"))); // ((3 * 1 / 3) + (2 * 1 / 2) + (1 * 1 / 1)) 71 Console.WriteLine(formatter.Format(parser.Parse("-3+30-2+20-1+10"))); // not (30 + 20 + 10 + ((-1) * (3 + 2 + 1))) 72 72 // round trip 73 Console.WriteLine(formatter.Format(parser.Parse(formatter.Format(parser.Parse("-3+30-2+20-1+10"))))); 73 Console.WriteLine(formatter.Format(parser.Parse(formatter.Format(parser.Parse("-3+30-2+20-1+10"))))); // not (30 + 20 + 10 + ((-(1)) * (3 + 2 + 1))) 74 74 75 75 Console.WriteLine(formatter.Format(parser.Parse("\"x1\""))); -
branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionCrossoverTest.cs
r15583 r16711 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r15583 r16711 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 119 119 public void LinearInterpreterTestArithmeticGrammarPerformance() { 120 120 TestArithmeticGrammarPerformance(new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), 12.5e6); 121 } 122 123 [TestMethod] 124 [TestCategory("Problems.DataAnalysis.Symbolic")] 125 [TestProperty("Time", "long")] 126 public void BatchInterpreterTestTypeCoherentGrammarPerformance() { 127 TestTypeCoherentGrammarPerformance(new SymbolicDataAnalysisExpressionTreeBatchInterpreter(), 12.5e6); 128 } 129 [TestMethod] 130 [TestCategory("Problems.DataAnalysis.Symbolic")] 131 [TestProperty("Time", "long")] 132 public void BatchInterpreterTestArithmeticGrammarPerformance() { 133 TestArithmeticGrammarPerformance(new SymbolicDataAnalysisExpressionTreeBatchInterpreter(), 12.5e6); 121 134 } 122 135 -
branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs
r15583 r16711 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 228 228 AssertEqualAfterSimplification("(- (factor a 2.0 3.0) (binfactor a x0 2.0))", "(factor a 0.0 3.0)"); 229 229 #endregion 230 231 #region abs 232 AssertEqualAfterSimplification("(abs 2.0)", "2.0"); 233 AssertEqualAfterSimplification("(abs -2.0)", "2.0"); // constant folding 234 AssertEqualAfterSimplification("(abs (exp (variable 2.0 x)))", "(exp (variable 2.0 x)))"); // exp is always positive 235 AssertEqualAfterSimplification("(abs (exp (variable 2.0 x)))", "(exp (variable 2.0 x)))"); // exp is always positive 236 AssertEqualAfterSimplification("(abs (sqr (variable 2.0 a)))", "(sqr (variable 2.0 a))"); // sqr is always positive 237 AssertEqualAfterSimplification("(abs (sqrt (variable 2.0 a)))", "(sqrt (variable 2.0 a))"); // sqrt is always positive (for our cases) 238 AssertEqualAfterSimplification("(abs (cuberoot (variable 2.0 a)))", "(cuberoot (variable 2.0 a))"); // cuberoot is always positive (for our cases) 239 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 242 243 AssertEqualAfterSimplification("(abs (* (variable 1.0 a) (variable 2.0 b)))", "(* (abs (variable 1.0 a)) (abs (variable 1.0 b)) 2.0))"); 244 AssertEqualAfterSimplification("(abs (/ (variable 1.0 a) (variable 2.0 b)))", "(/ (abs (variable 1.0 a)) (abs (variable 2.0 b))))"); 245 #endregion 246 247 #region square and sqrt 248 AssertEqualAfterSimplification("(sqr (sqrt (variable 2.0 x)))", "(variable 2.0 x)"); 249 AssertEqualAfterSimplification("(sqrt (sqr (variable 2.0 x)))", "(variable 2.0 x)"); 250 AssertEqualAfterSimplification("(sqr (abs (variable 2.0 a)))", "(sqr (variable 2.0 a))"); 251 AssertEqualAfterSimplification("(sqr (exp (variable 2.0 x)))", "(exp (variable 4.0 x))"); 252 253 AssertEqualAfterSimplification("(sqr (* (variable 2.0 a) (variable 3.0 b) (variable 4.0 c)))", 254 "(* (sqr (variable 1.0 a)) (sqr (variable 1.0 b)) (sqr (variable 1.0 c)) 576)"); // 2²*3²*4² 255 #endregion 256 257 #region cube and cuberoot 258 AssertEqualAfterSimplification("(cube (cuberoot (variable 2.0 x)))", "(variable 2.0 x)"); 259 AssertEqualAfterSimplification("(cuberoot (cube (variable 2.0 x)))", "(variable 2.0 x)"); 260 AssertEqualAfterSimplification("(cube (exp (variable 2.0 x)))", "(exp (variable 6.0 x))"); 261 262 AssertEqualAfterSimplification("(sqr (cube (variable 2.0 x)))", "(pow (variable 2.0 x) 6)"); 263 AssertEqualAfterSimplification("(cube (sqr (variable 2.0 x)))", "(pow (variable 2.0 x) 6)"); 264 #endregion 265 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))"); 269 270 #endregion 230 271 } 231 272 -
branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs
r14354 r16711 7 7 [TestClass] 8 8 public class BottomUpSimilarityCalculatorTest { 9 private readonly SymbolicExpressionTreeBottomUpSimilarityCalculator busCalculator;10 private readonly SymbolicExpressionImporter importer ;9 private readonly SymbolicExpressionTreeBottomUpSimilarityCalculator similarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator() { MatchConstantValues = false, MatchVariableWeights = false }; 10 private readonly SymbolicExpressionImporter importer = new SymbolicExpressionImporter(); 11 11 12 private const int N = 1 50;12 private const int N = 1000; 13 13 private const int Rows = 1; 14 14 private const int Columns = 10; 15 15 16 16 public BottomUpSimilarityCalculatorTest() { 17 busCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator(); 18 importer = new SymbolicExpressionImporter(); 17 var parser = new InfixExpressionParser(); 19 18 } 20 19 … … 23 22 [TestProperty("Time", "short")] 24 23 public void BottomUpTreeSimilarityCalculatorTestMapping() { 25 TestMatchedNodes("(+ 1 2)", "(+ 2 1)", 5); 26 TestMatchedNodes("(- 2 1)", "(- 1 2)", 2); 27 TestMatchedNodes("(* (variable 1 X1) (variable 1 X2))", "(* (+ (variable 1 X1) 1) (+ (variable 1 X2) 1))", 2); 24 TestMatchedNodes("(+ 1 1)", "(+ 2 2)", 0, strict: true); 25 TestMatchedNodes("(+ 1 1)", "(+ 2 2)", 3, strict: false); 26 TestMatchedNodes("(+ 1 1)", "(+ 1 2)", 1, strict: true); 27 TestMatchedNodes("(+ 2 1)", "(+ 1 2)", 3, strict: true); 28 28 29 TestMatchedNodes("(* (variable 1 X1) (variable 1 X2))", "(* (+ (variable 1 X1) 1) (variable 1 X2))", 2); 29 TestMatchedNodes("(- 1 1)", "(- 2 2)", 0, strict: true); 30 TestMatchedNodes("(- 1 1)", "(- 2 2)", 3, strict: false); 30 31 31 TestMatchedNodes("(+ (variable 1 a) (variable 1 b))", "(+ (variable 1 a) (variable 1 a))", 1); 32 TestMatchedNodes("(+ (+ (variable 1 a) (variable 1 b)) (variable 1 b))", "(+ (* (+ (variable 1 a) (variable 1 b)) (variable 1 b)) (+ (+ (variable 1 a) (variable 1 b)) (variable 1 b)))", 5); 33 34 TestMatchedNodes( 35 "(* (+ 2.84 (exp (+ (log (/ (variable 2.0539 X5) (variable -9.2452e-1 X6))) (/ (variable 2.0539 X5) (variable -9.2452e-1 X6))))) 2.9081)", 36 "(* (- (variable 9.581e-1 X6) (+ (- (variable 5.1491e-1 X5) 1.614e+1) (+ (/ (variable 2.0539 X5) (variable -9.2452e-1 X6)) (log (/ (variable 2.0539 X5) (variable -9.2452e-1 X6)))))) 2.9081)", 37 9); 38 39 TestMatchedNodes("(* (* (* (variable 1.68 x) (* (variable 1.68 x) (variable 2.55 x))) (variable 1.68 x)) (* (* (variable 1.68 x) (* (variable 1.68 x) (* (variable 1.68 x) (variable 2.55 x)))) (variable 2.55 x)))", "(* (variable 2.55 x) (* (variable 1.68 x) (* (variable 1.68 x) (* (variable 1.68 x) (variable 2.55 x)))))", 9); 40 41 TestMatchedNodes("(+ (exp 2.1033) (/ -4.3072 (variable 2.4691 X7)))", "(/ 1 (+ (/ -4.3072 (variable 2.4691 X7)) (exp 2.1033)))", 6); 42 TestMatchedNodes("(+ (exp 2.1033) (/ -4.3072 (variable 2.4691 X7)))", "(/ 1 (+ (/ (variable 2.4691 X7) -4.3072) (exp 2.1033)))", 4); 43 44 const string expr1 = "(* (- 1.2175e+1 (+ (/ (exp -1.4134e+1) (exp 9.2013)) (exp (log (exp (/ (exp (- (* -4.2461 (variable 2.2634 X5)) (- -9.6267e-1 3.3243))) (- (/ (/ (variable 1.0883 X1) (variable 6.9620e-1 X2)) (log 1.3011e+1)) (variable -4.3098e-1 X7)))))))) (log 1.3011e+1))"; 45 const string expr2 = "(* (- 1.2175e+1 (+ (/ (/ (+ (variable 3.0140 X9) (variable 1.3430 X8)) -1.0864e+1) (exp 9.2013)) (exp (log (exp (/ (exp (- (* -4.2461 (variable 2.2634 X5)) (- -9.6267e-1 3.3243))) (- (/ (/ (variable 1.0883 X1) (variable 6.9620e-1 X2)) (log 1.3011e+1)) (variable -4.3098e-1 X7)))))))) (exp (variable 4.0899e-1 X7)))"; 46 47 TestMatchedNodes(expr1, expr2, 23); 48 32 TestMatchedNodes("(- 2 1)", "(- 1 2)", 2, strict: true); 33 TestMatchedNodes("(- 2 1)", "(- 1 2)", 3, strict: false); 49 34 } 50 35 51 private void TestMatchedNodes(string expr1, string expr2, int expected ) {36 private void TestMatchedNodes(string expr1, string expr2, int expected, bool strict) { 52 37 var t1 = importer.Import(expr1); 53 38 var t2 = importer.Import(expr2); 54 39 55 var mapping = busCalculator.ComputeBottomUpMapping(t1.Root, t2.Root); 56 var c = mapping.Count; 40 var map = SymbolicExpressionTreeBottomUpSimilarityCalculator.ComputeBottomUpMapping(t1, t2, strict); 57 41 58 if ( c!= expected) {59 throw new Exception( "Match count " + c + " is different than expected value " + expected);42 if (map.Count != expected) { 43 throw new Exception($"Match count {map.Count} is different than expected value {expected} for expressions:\n{expr1} and {expr2} (strict = {strict})"); 60 44 } 61 45 } … … 77 61 for (int i = 0; i < trees.Length - 1; ++i) { 78 62 for (int j = i + 1; j < trees.Length; ++j) { 79 s += busCalculator.CalculateSimilarity(trees[i], trees[j]);63 s += similarityCalculator.CalculateSimilarity(trees[i], trees[j]); 80 64 } 81 65 } -
branches/2936_GQAPIntegration/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/Util.cs
r15583 r16711 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab.
Note: See TracChangeset
for help on using the changeset viewer.