Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/04/19 16:27:08 (5 years ago)
Author:
gkronber
Message:

#2994: refactor / cleanup of unit tests related to intervals and new interpreters

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  
    1414    [TestCategory("Problems.DataAnalysis")]
    1515    [TestProperty("Time", "short")]
    16     public void TestIntervalAddOperation() {
     16    public void IntervalAdd() {
    1717      //add        [x1,x2] + [y1,y2] = [x1 + y1,x2 + y2]
    1818
     
    2828    [TestCategory("Problems.DataAnalysis")]
    2929    [TestProperty("Time", "short")]
    30     public void TestIntervalSubOperation() {
     30    public void IntervalSub() {
    3131      //subtract   [x1,x2] − [y1,y2] = [x1 − y2,x2 − y1]
    3232
     
    4242    [TestCategory("Problems.DataAnalysis")]
    4343    [TestProperty("Time", "short")]
    44     public void TestIntervalMutlipyOperation() {
     44    public void IntervalMutlipy() {
    4545      //multiply   [x1,x2] * [y1,y2] = [min(x1*y1,x1*y2,x2*y1,x2*y2),max(x1*y1,x1*y2,x2*y1,x2*y2)]
    4646
     
    5959    [TestCategory("Problems.DataAnalysis")]
    6060    [TestProperty("Time", "short")]
    61     public void TestIntervalDivideOperation() {
     61    public void IntervalDivide() {
    6262      //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].
    6363
     
    8383    [TestCategory("Problems.DataAnalysis")]
    8484    [TestProperty("Time", "short")]
    85     public void TestIntervalSineOperator() {
     85    public void IntervalSine() {
    8686      //sine depends on interval
    8787      //sin([0, 2*pi]) = [-1, 1]
     
    101101    [TestCategory("Problems.DataAnalysis")]
    102102    [TestProperty("Time", "short")]
    103     public void TestIntervalCosineOperator() {
     103    public void IntervalCosine() {
    104104      //Cosine uses sine Interval.Sine(Interval.Subtract(a, new Interval(Math.PI / 2, Math.PI / 2)));
    105105      Assert.AreEqual<Interval>(Interval.Cosine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1));
     
    110110    [TestCategory("Problems.DataAnalysis")]
    111111    [TestProperty("Time", "short")]
    112     public void TestIntervalLogOperator() {
     112    public void IntervalLog() {
    113113      //Log([3, 5]) = [log(3), log(5)]
    114114      Assert.AreEqual<Interval>(new Interval(Math.Log(3), Math.Log(5)), Interval.Logarithm(new Interval(3, 5)));
     
    125125    [TestCategory("Problems.DataAnalysis")]
    126126    [TestProperty("Time", "short")]
    127     public void TestIntervalExpOperator() {
     127    public void IntervalExp() {
    128128      //Exp([0, 1]) = [exp(0), exp(1)]
    129129      Assert.AreEqual<Interval>(new Interval(1, Math.Exp(1)), Interval.Exponential(new Interval(0, 1)));
     
    134134    [TestCategory("Problems.DataAnalysis")]
    135135    [TestProperty("Time", "short")]
    136     public void TestIntervalSqrOperator() {
     136    public void IntervalSqr() {
    137137      Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(1, 2)));
    138138      Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(-2, -1)));
     
    143143    [TestCategory("Problems.DataAnalysis")]
    144144    [TestProperty("Time", "short")]
    145     public void TestIntervalSqrtOperator() {
     145    public void IntervalSqrt() {
    146146      Assert.AreEqual<Interval>(new Interval(1, 2), Interval.SquareRoot(new Interval(1, 4)));
    147147      Assert.AreEqual<Interval>(new Interval(double.NaN, double.NaN), Interval.SquareRoot(new Interval(-4, -1)));
     
    151151    [TestCategory("Problems.DataAnalysis")]
    152152    [TestProperty("Time", "short")]
    153     public void TestIntervalCubeOperator() {
     153    public void IntervalCube() {
    154154      Assert.AreEqual<Interval>(new Interval(1, 8), Interval.Cube(new Interval(1, 2)));
    155155      Assert.AreEqual<Interval>(new Interval(-8, -1), Interval.Cube(new Interval(-2, -1)));
     
    160160    [TestCategory("Problems.DataAnalysis")]
    161161    [TestProperty("Time", "short")]
    162     public void TestIntervalCbrtOperator() {
     162    public void IntervalCbrt() {
    163163      Assert.AreEqual<Interval>(new Interval(1, 2), Interval.CubicRoot(new Interval(1, 8)));
    164164      Assert.AreEqual<Interval>(new Interval(-2, -2), Interval.CubicRoot(new Interval(-8, -8)));
     
    173173    [TestCategory("Problems.DataAnalysis")]
    174174    [TestProperty("Time", "short")]
    175     public void TestIntervalAbsoluteOperator() {
     175    public void IntervalAbsolute() {
    176176      Assert.AreEqual(new Interval(2, 2), Interval.Absolute(new Interval(-2, -2)));
    177177      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  
    5252    [TestCategory("Problems.DataAnalysis.Symbolic")]
    5353    [TestProperty("Time", "short")]
    54     public void TestIntervalInterpreterAdd() {
     54    public void IntervalInterpreterAdd() {
    5555      EvaluateTest("x1 + x2", new Interval(5, 14));
    5656      EvaluateTest("x1 + x2", new Interval(5, 16), variableRanges);
     
    6060    [TestCategory("Problems.DataAnalysis.Symbolic")]
    6161    [TestProperty("Time", "short")]
    62     public void TestIntervalInterpreterLogAdd() {
     62    public void IntervalInterpreterLogAdd() {
    6363      EvaluateTest("log(x1 + x2)", new Interval(Math.Log(5), Math.Log(14)));
    6464      EvaluateTest("log(x1 + x2)", new Interval(Math.Log(5), Math.Log(16)), variableRanges);
     
    6868    [TestCategory("Problems.DataAnalysis.Symbolic")]
    6969    [TestProperty("Time", "short")]
    70     public void TestIntervalInterpreterLogAddMul() {
     70    public void IntervalInterpreterLogAddMul() {
    7171      EvaluateTest("log(3*x1 + x2)", new Interval(Math.Log(11), Math.Log(30)));
    7272      EvaluateTest("log(3*x1 + x2)", new Interval(Math.Log(7), Math.Log(36)), variableRanges);
     
    7676    [TestCategory("Problems.DataAnalysis.Symbolic")]
    7777    [TestProperty("Time", "short")]
    78     public void TestIntervalInterpreterSin() {
     78    public void IntervalInterpreterSin() {
    7979      EvaluateTest("sin(x1+x2)", new Interval(-1, 1));
    8080      EvaluateTest("sin(x1+x2)", new Interval(-1, 1), variableRanges);
     
    9898    [TestCategory("Problems.DataAnalysis.Symbolic")]
    9999    [TestProperty("Time", "short")]
    100     public void TestIntervalInterpreterCos() {
     100    public void IntervalInterpreterCos() {
    101101      EvaluateTest("cos(x1+x2)", new Interval(-1, 1));
    102102      EvaluateTest("cos(x1+x2)", new Interval(-1, 1), variableRanges);
     
    121121    [TestCategory("Problems.DataAnalysis.Symbolic")]
    122122    [TestProperty("Time", "short")]
    123     public void TestIntervalInterpreterTan() {
     123    public void IntervalInterpreterTan() {
    124124      // critical values:
    125125      // lim tan(x) = -inf for x => -pi/2
     
    140140    [TestCategory("Problems.DataAnalysis.Symbolic")]
    141141    [TestProperty("Time", "short")]
    142     public void TestIntervalInterpreterTanh() {
     142    public void IntervalInterpreterTanh() {
    143143      // critical values:
    144144      // lim tanh(x) = -1 for x => -inf
     
    158158    [TestCategory("Problems.DataAnalysis.Symbolic")]
    159159    [TestProperty("Time", "short")]
    160     public void TestIntervalInterpreterExp() {
     160    public void IntervalInterpreterExp() {
    161161      EvaluateTest("exp(x1-x2)", new Interval(Math.Exp(-3), Math.Exp(6)));
    162162      EvaluateTest("exp(x1-x2)", new Interval(Math.Exp(-5), Math.Exp(6)), variableRanges);
     
    166166    [TestCategory("Problems.DataAnalysis.Symbolic")]
    167167    [TestProperty("Time", "short")]
    168     public void TestIntervalInterpreterExpRoot() {
     168    public void IntervalInterpreterExpRoot() {
    169169      EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(6)), Math.Exp(Math.Sqrt(48))));
    170170      EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(4)), Math.Exp(Math.Sqrt(60))), variableRanges);
     
    174174    [TestCategory("Problems.DataAnalysis.Symbolic")]
    175175    [TestProperty("Time", "short")]
    176     public void TestIntervalInterpreterPower() {
     176    public void IntervalInterpreterPower() {
    177177      EvaluateTest("pow(x1, 2)", new Interval(Math.Pow(3, 1), Math.Pow(8, 3)));
    178178    }
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs

    r17303 r17318  
    266266            Assert.AreEqual(sum, s, 1e-12, errorMessage);
    267267          }
    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);
    318268        }
    319269      }
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r17307 r17318  
    599599    <Compile Include="HeuristicLab.Persistence.Attic\UseCases.cs" />
    600600    <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" />
    602604    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\ClassificationVariableImpactCalculationTest.cs" />
    603605    <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" />
    606607    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\IntervalTest.cs" />
    607608    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\RegressionVariableImpactCalculationTest.cs" />
     
    611612    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\DeriveTest.cs" />
    612613    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\InfixExpressionParserTest.cs" />
    613     <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\AutoDiffIntervalInterpreterTest.cs" />
    614614    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\IntervalInterpreterTest.cs" />
    615615    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.