Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/03/11 14:14:36 (14 years ago)
Author:
gkronber
Message:

Improved test cases for data analysis plugins. #1336

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleRSquaredEvaluator.cs

    r4722 r5412  
    7171      }
    7272    }
    73 
    74     private static bool IsInvalidValue(double d) {
    75       return double.IsNaN(d) || double.IsInfinity(d);
    76     }
    7773  }
    7874}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/SimpleArithmeticExpressionInterpreterTest.cs

    r4477 r5412  
    4040    private const int Rows = 1000;
    4141    private const int Columns = 50;
    42     private static SymbolicExpressionTree[] randomTrees;
    43     private static Dataset dataset;
    44     private static MersenneTwister twister;
    4542    private TestContext testContextInstance;
    4643
     
    5855    }
    5956
    60     [ClassInitialize()]
    61     public static void CreateRandomTrees(TestContext testContext) {
    62       twister = new MersenneTwister();
    63       dataset = Util.CreateRandomDataset(twister, Rows, Columns);
     57    [TestMethod]
     58    public void FullGrammarSimpleArithmeticExpressionInterpreterPerformanceTest() {
     59      var twister = new MersenneTwister();
     60      var dataset = Util.CreateRandomDataset(twister, Rows, Columns);
    6461      var grammar = new GlobalSymbolicExpressionGrammar(new FullFunctionalExpressionGrammar());
    6562      grammar.MaxFunctionArguments = 0;
     
    6764      grammar.MinFunctionArguments = 0;
    6865      grammar.MinFunctionDefinitions = 0;
    69       randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0);
    70     }
    71 
    72     [TestMethod]
    73     public void SimpleArithmeticExpressionInterpreterPerformanceTest() {
     66      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0);
    7467      double[] estimation = new double[Rows];
    7568      foreach (SymbolicExpressionTree tree in randomTrees) {
     
    7770      }
    7871      SimpleArithmeticExpressionInterpreter interpreter = new SimpleArithmeticExpressionInterpreter();
    79       Util.EvaluateTrees(randomTrees, interpreter, dataset, 10);
     72      double nodesPerSec = Util.CalculateEvaluatedNodesPerSec(randomTrees, interpreter, dataset, 3);
     73      Assert.IsTrue(nodesPerSec > 15.0e6); // evaluated nodes per seconds must be larger than 15mNodes/sec
     74    }
     75
     76    [TestMethod]
     77    public void ArithmeticGrammarSimpleArithmeticExpressionInterpreterPerformanceTest() {
     78      var twister = new MersenneTwister();
     79      var dataset = Util.CreateRandomDataset(twister, Rows, Columns);
     80      var grammar = new GlobalSymbolicExpressionGrammar(new ArithmeticExpressionGrammar());
     81      grammar.MaxFunctionArguments = 0;
     82      grammar.MaxFunctionDefinitions = 0;
     83      grammar.MinFunctionArguments = 0;
     84      grammar.MinFunctionDefinitions = 0;
     85      var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0);
     86      double[] estimation = new double[Rows];
     87      foreach (SymbolicExpressionTree tree in randomTrees) {
     88        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
     89      }
     90      SimpleArithmeticExpressionInterpreter interpreter = new SimpleArithmeticExpressionInterpreter();
     91      double nodesPerSec = Util.CalculateEvaluatedNodesPerSec(randomTrees, interpreter, dataset, 3);
     92      Assert.IsTrue(nodesPerSec > 15.0e6); // evaluated nodes per seconds must be larger than 15mNodes/sec
    8093    }
    8194
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/Util.cs

    r4068 r5412  
    2929using HeuristicLab.Random;
    3030using Microsoft.VisualStudio.TestTools.UnitTesting;
     31using HeuristicLab.Problems.DataAnalysis.Evaluators;
     32using System;
    3133namespace HeuristicLab.Problems.DataAnalysis.Tests {
    3234  internal class Util {
     
    8082    }
    8183
    82     public static void EvaluateTrees(SymbolicExpressionTree[] trees, ISymbolicExpressionTreeInterpreter interpreter, Dataset dataset, int repetitions) {
    83       double[] estimation = new double[dataset.Rows];
     84    public static double CalculateEvaluatedNodesPerSec(SymbolicExpressionTree[] trees, ISymbolicExpressionTreeInterpreter interpreter, Dataset dataset, int repetitions) {
    8485      // warm up
     86      IEnumerable<int> rows = Enumerable.Range(0, dataset.Rows);
     87      long nNodes = 0;
     88      double c = 0;
    8589      for (int i = 0; i < trees.Length; i++) {
    86         estimation = interpreter.GetSymbolicExpressionTreeValues(trees[i], dataset, Enumerable.Range(0, dataset.Rows)).ToArray();
     90        nNodes += trees[i].Size * (dataset.Rows - 1);
     91        c = interpreter.GetSymbolicExpressionTreeValues(trees[i], dataset, rows).Count(); // count needs to evaluate all rows
    8792      }
    8893
    8994      Stopwatch watch = new Stopwatch();
    90       long nNodes = 0;
    9195      for (int rep = 0; rep < repetitions; rep++) {
    9296        watch.Start();
     97        c = 0;
    9398        for (int i = 0; i < trees.Length; i++) {
    94           nNodes += trees[i].Size * (dataset.Rows - 1);
    95           estimation = interpreter.GetSymbolicExpressionTreeValues(trees[i], dataset, Enumerable.Range(0, dataset.Rows)).ToArray();
     99          interpreter.GetSymbolicExpressionTreeValues(trees[i], dataset, rows).Count(); // count needs to evaluate all rows
    96100        }
    97101        watch.Stop();
    98102      }
    99       Assert.Inconclusive("Random tree evaluation performance of " + interpreter.GetType() + ":" +
     103      Console.WriteLine("Random tree evaluation performance of " + interpreter.GetType() + ": " +
    100104        watch.ElapsedMilliseconds + "ms " +
    101         Util.NodesPerSecond(nNodes, watch) + " nodes/sec");
     105        Util.NodesPerSecond(nNodes * repetitions, watch) + " nodes/sec");
     106      return Util.NodesPerSecond(nNodes * repetitions, watch);
    102107    }
    103108  }
Note: See TracChangeset for help on using the changeset viewer.