Changeset 17318 for branches/2994-AutoDiffForIntervals
- Timestamp:
- 10/04/19 16:27:08 (5 years ago)
- Location:
- branches/2994-AutoDiffForIntervals/HeuristicLab.Tests
- Files:
-
- 4 added
- 4 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/IntervalTest.cs
r17314 r17318 14 14 [TestCategory("Problems.DataAnalysis")] 15 15 [TestProperty("Time", "short")] 16 public void TestIntervalAddOperation() {16 public void IntervalAdd() { 17 17 //add [x1,x2] + [y1,y2] = [x1 + y1,x2 + y2] 18 18 … … 28 28 [TestCategory("Problems.DataAnalysis")] 29 29 [TestProperty("Time", "short")] 30 public void TestIntervalSubOperation() {30 public void IntervalSub() { 31 31 //subtract [x1,x2] − [y1,y2] = [x1 − y2,x2 − y1] 32 32 … … 42 42 [TestCategory("Problems.DataAnalysis")] 43 43 [TestProperty("Time", "short")] 44 public void TestIntervalMutlipyOperation() {44 public void IntervalMutlipy() { 45 45 //multiply [x1,x2] * [y1,y2] = [min(x1*y1,x1*y2,x2*y1,x2*y2),max(x1*y1,x1*y2,x2*y1,x2*y2)] 46 46 … … 59 59 [TestCategory("Problems.DataAnalysis")] 60 60 [TestProperty("Time", "short")] 61 public void TestIntervalDivideOperation() {61 public void IntervalDivide() { 62 62 //divide [x1, x2] / [y1, y2] = [x1, x2] * (1/[y1, y2]), where 1 / [y1,y2] = [1 / y2,1 / y1] if 0 not in [y_1, y_2]. 63 63 … … 83 83 [TestCategory("Problems.DataAnalysis")] 84 84 [TestProperty("Time", "short")] 85 public void TestIntervalSineOperator() {85 public void IntervalSine() { 86 86 //sine depends on interval 87 87 //sin([0, 2*pi]) = [-1, 1] … … 101 101 [TestCategory("Problems.DataAnalysis")] 102 102 [TestProperty("Time", "short")] 103 public void TestIntervalCosineOperator() {103 public void IntervalCosine() { 104 104 //Cosine uses sine Interval.Sine(Interval.Subtract(a, new Interval(Math.PI / 2, Math.PI / 2))); 105 105 Assert.AreEqual<Interval>(Interval.Cosine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1)); … … 110 110 [TestCategory("Problems.DataAnalysis")] 111 111 [TestProperty("Time", "short")] 112 public void TestIntervalLogOperator() {112 public void IntervalLog() { 113 113 //Log([3, 5]) = [log(3), log(5)] 114 114 Assert.AreEqual<Interval>(new Interval(Math.Log(3), Math.Log(5)), Interval.Logarithm(new Interval(3, 5))); … … 125 125 [TestCategory("Problems.DataAnalysis")] 126 126 [TestProperty("Time", "short")] 127 public void TestIntervalExpOperator() {127 public void IntervalExp() { 128 128 //Exp([0, 1]) = [exp(0), exp(1)] 129 129 Assert.AreEqual<Interval>(new Interval(1, Math.Exp(1)), Interval.Exponential(new Interval(0, 1))); … … 134 134 [TestCategory("Problems.DataAnalysis")] 135 135 [TestProperty("Time", "short")] 136 public void TestIntervalSqrOperator() {136 public void IntervalSqr() { 137 137 Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(1, 2))); 138 138 Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(-2, -1))); … … 143 143 [TestCategory("Problems.DataAnalysis")] 144 144 [TestProperty("Time", "short")] 145 public void TestIntervalSqrtOperator() {145 public void IntervalSqrt() { 146 146 Assert.AreEqual<Interval>(new Interval(1, 2), Interval.SquareRoot(new Interval(1, 4))); 147 147 Assert.AreEqual<Interval>(new Interval(double.NaN, double.NaN), Interval.SquareRoot(new Interval(-4, -1))); … … 151 151 [TestCategory("Problems.DataAnalysis")] 152 152 [TestProperty("Time", "short")] 153 public void TestIntervalCubeOperator() {153 public void IntervalCube() { 154 154 Assert.AreEqual<Interval>(new Interval(1, 8), Interval.Cube(new Interval(1, 2))); 155 155 Assert.AreEqual<Interval>(new Interval(-8, -1), Interval.Cube(new Interval(-2, -1))); … … 160 160 [TestCategory("Problems.DataAnalysis")] 161 161 [TestProperty("Time", "short")] 162 public void TestIntervalCbrtOperator() {162 public void IntervalCbrt() { 163 163 Assert.AreEqual<Interval>(new Interval(1, 2), Interval.CubicRoot(new Interval(1, 8))); 164 164 Assert.AreEqual<Interval>(new Interval(-2, -2), Interval.CubicRoot(new Interval(-8, -8))); … … 173 173 [TestCategory("Problems.DataAnalysis")] 174 174 [TestProperty("Time", "short")] 175 public void TestIntervalAbsoluteOperator() {175 public void IntervalAbsolute() { 176 176 Assert.AreEqual(new Interval(2, 2), Interval.Absolute(new Interval(-2, -2))); 177 177 Assert.AreEqual(new Interval(5, 5), Interval.Absolute(new Interval(5, 5))); -
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/IntervalInterpreterTest.cs
r17289 r17318 52 52 [TestCategory("Problems.DataAnalysis.Symbolic")] 53 53 [TestProperty("Time", "short")] 54 public void TestIntervalInterpreterAdd() {54 public void IntervalInterpreterAdd() { 55 55 EvaluateTest("x1 + x2", new Interval(5, 14)); 56 56 EvaluateTest("x1 + x2", new Interval(5, 16), variableRanges); … … 60 60 [TestCategory("Problems.DataAnalysis.Symbolic")] 61 61 [TestProperty("Time", "short")] 62 public void TestIntervalInterpreterLogAdd() {62 public void IntervalInterpreterLogAdd() { 63 63 EvaluateTest("log(x1 + x2)", new Interval(Math.Log(5), Math.Log(14))); 64 64 EvaluateTest("log(x1 + x2)", new Interval(Math.Log(5), Math.Log(16)), variableRanges); … … 68 68 [TestCategory("Problems.DataAnalysis.Symbolic")] 69 69 [TestProperty("Time", "short")] 70 public void TestIntervalInterpreterLogAddMul() {70 public void IntervalInterpreterLogAddMul() { 71 71 EvaluateTest("log(3*x1 + x2)", new Interval(Math.Log(11), Math.Log(30))); 72 72 EvaluateTest("log(3*x1 + x2)", new Interval(Math.Log(7), Math.Log(36)), variableRanges); … … 76 76 [TestCategory("Problems.DataAnalysis.Symbolic")] 77 77 [TestProperty("Time", "short")] 78 public void TestIntervalInterpreterSin() {78 public void IntervalInterpreterSin() { 79 79 EvaluateTest("sin(x1+x2)", new Interval(-1, 1)); 80 80 EvaluateTest("sin(x1+x2)", new Interval(-1, 1), variableRanges); … … 98 98 [TestCategory("Problems.DataAnalysis.Symbolic")] 99 99 [TestProperty("Time", "short")] 100 public void TestIntervalInterpreterCos() {100 public void IntervalInterpreterCos() { 101 101 EvaluateTest("cos(x1+x2)", new Interval(-1, 1)); 102 102 EvaluateTest("cos(x1+x2)", new Interval(-1, 1), variableRanges); … … 121 121 [TestCategory("Problems.DataAnalysis.Symbolic")] 122 122 [TestProperty("Time", "short")] 123 public void TestIntervalInterpreterTan() {123 public void IntervalInterpreterTan() { 124 124 // critical values: 125 125 // lim tan(x) = -inf for x => -pi/2 … … 140 140 [TestCategory("Problems.DataAnalysis.Symbolic")] 141 141 [TestProperty("Time", "short")] 142 public void TestIntervalInterpreterTanh() {142 public void IntervalInterpreterTanh() { 143 143 // critical values: 144 144 // lim tanh(x) = -1 for x => -inf … … 158 158 [TestCategory("Problems.DataAnalysis.Symbolic")] 159 159 [TestProperty("Time", "short")] 160 public void TestIntervalInterpreterExp() {160 public void IntervalInterpreterExp() { 161 161 EvaluateTest("exp(x1-x2)", new Interval(Math.Exp(-3), Math.Exp(6))); 162 162 EvaluateTest("exp(x1-x2)", new Interval(Math.Exp(-5), Math.Exp(6)), variableRanges); … … 166 166 [TestCategory("Problems.DataAnalysis.Symbolic")] 167 167 [TestProperty("Time", "short")] 168 public void TestIntervalInterpreterExpRoot() {168 public void IntervalInterpreterExpRoot() { 169 169 EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(6)), Math.Exp(Math.Sqrt(48)))); 170 170 EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(4)), Math.Exp(Math.Sqrt(60))), variableRanges); … … 174 174 [TestCategory("Problems.DataAnalysis.Symbolic")] 175 175 [TestProperty("Time", "short")] 176 public void TestIntervalInterpreterPower() {176 public void IntervalInterpreterPower() { 177 177 EvaluateTest("pow(x1, 2)", new Interval(Math.Pow(3, 1), Math.Pow(8, 3))); 178 178 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r17303 r17318 266 266 Assert.AreEqual(sum, s, 1e-12, errorMessage); 267 267 } 268 }269 }270 }271 272 [TestMethod]273 [TestCategory("Problems.DataAnalysis.Symbolic")]274 [TestProperty("Time", "long")]275 public void TestVectorInterpretersEstimatedValuesConsistency() {276 var twister = new MersenneTwister();277 twister.Seed(31415);278 const int numRows = 100;279 var dataset = Util.CreateRandomDataset(twister, numRows, Columns);280 281 var grammar = new TypeCoherentExpressionGrammar();282 grammar.ConfigureAsDefaultRegressionGrammar();283 grammar.Symbols.First(s => s is Square).Enabled = true;284 grammar.Symbols.First(s => s is SquareRoot).Enabled = true;285 grammar.Symbols.First(s => s is Cube).Enabled = true;286 grammar.Symbols.First(s => s is CubeRoot).Enabled = true;287 grammar.Symbols.First(s => s is Exponential).Enabled = true;288 grammar.Symbols.First(s => s is Logarithm).Enabled = true;289 grammar.Symbols.First(s => s is Sine).Enabled = true;290 grammar.Symbols.First(s => s is Cosine).Enabled = true;291 grammar.Symbols.First(s => s is Absolute).Enabled = true;292 grammar.Symbols.First(s => s is AnalyticQuotient).Enabled = true;293 294 var refInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();295 var newInterpreter = new VectorEvaluator();296 var newAutoDiffInterpreter = new VectorAutoDiffEvaluator();297 298 var rows = Enumerable.Range(0, numRows).ToList();299 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 10, 0, 0);300 foreach (ISymbolicExpressionTree tree in randomTrees) {301 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));302 }303 304 for (int i = 0; i < randomTrees.Length; ++i) {305 var tree = randomTrees[i];306 var refValues = refInterpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToArray();307 var newValues = newInterpreter.Evaluate(tree, dataset, rows.ToArray()).ToArray();308 var newAutoDiffValues = new double[numRows];309 newAutoDiffInterpreter.Evaluate(tree, dataset, rows.ToArray(), new ISymbolicExpressionTreeNode[0], newAutoDiffValues, null);310 311 for (int j = 0; j < rows.Count; j++) {312 if (double.IsNaN(refValues[j]) && double.IsNaN(newValues[j]) && double.IsNaN(newAutoDiffValues[j])) continue;313 string errorMessage = string.Format("Interpreters do not agree on tree {0} {1}.", i, (new InfixExpressionFormatter()).Format(tree));314 315 var relDelta = Math.Abs(refValues[j]) * 1e-5;316 Assert.AreEqual(refValues[j], newValues[j], relDelta, errorMessage);317 Assert.AreEqual(newValues[j], newAutoDiffValues[j], relDelta, errorMessage);318 268 } 319 269 } -
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r17307 r17318 599 599 <Compile Include="HeuristicLab.Persistence.Attic\UseCases.cs" /> 600 600 <Compile Include="HeuristicLab.PluginInfraStructure-3.3\TypeExtensionsTest.cs" /> 601 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\AutoDiffInterpreterTest.cs" /> 601 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\AlgebraicIntervalTest.cs" /> 602 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\IntervalEvaluatorAutoDiffTest.cs" /> 603 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\VectorAutoDiffEvaluatorTest.cs" /> 602 604 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\ClassificationVariableImpactCalculationTest.cs" /> 603 605 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\DatasetTest.cs" /> 604 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\AutoDiffIntervalTest.cs" /> 605 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\IntervalCalculationComparison.cs" /> 606 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\IntervalEvaluatorTest.cs" /> 606 607 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\IntervalTest.cs" /> 607 608 <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\RegressionVariableImpactCalculationTest.cs" /> … … 611 612 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\DeriveTest.cs" /> 612 613 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\InfixExpressionParserTest.cs" /> 613 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\AutoDiffIntervalInterpreterTest.cs" />614 614 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\IntervalInterpreterTest.cs" /> 615 615 <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.