Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/13/13 11:59:36 (11 years ago)
Author:
mkommend
Message:

#2108: Added new resource folder for unit tests and removed run configuration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs

    r9828 r9955  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Diagnostics;
    2425using System.Globalization;
    2526using System.Linq;
     27using System.Linq.Expressions;
    2628using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2729using HeuristicLab.Random;
     
    109111      TestArithmeticGrammarPerformance(new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), 12.5e6);
    110112    }
     113
     114    [TestMethod]
     115    [TestCategory("Problems.DataAnalysis.Symbolic")]
     116    [TestProperty("Time", "long")]
     117    public void ExpressionTreeInterpreterTestArithmeticGrammarPerformance() {
     118      TestArithmeticGrammarPerformance(new ExpressionTreeInterpreter(), 12.5e6);
     119    }
     120
     121    [TestMethod]
     122    [TestCategory("Problems.DataAnalysis.Symbolic")]
     123    [TestProperty("Time", "long")]
     124    public void ExpressionTreeInterpreterTestCompilationPerformance() {
     125      var twister = new MersenneTwister(31415);
     126      var dataset = Util.CreateRandomDataset(twister, Rows, Columns);
     127      var grammar = new ArithmeticExpressionGrammar();
     128      //grammar.Symbols.OfType<Variable>().First().Enabled = false;
     129      grammar.MaximumFunctionArguments = 0;
     130      grammar.MaximumFunctionDefinitions = 0;
     131      grammar.MinimumFunctionArguments = 0;
     132      grammar.MinimumFunctionDefinitions = 0;
     133
     134      var trees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0).ToArray();
     135      foreach (SymbolicExpressionTree tree in trees)
     136        Util.InitTree(tree, twister, new List<string>(dataset.VariableNames));
     137
     138
     139      var data = dataset.DoubleVariables.ToDictionary(key => key, v => (IList<double>)dataset.GetReadOnlyDoubleValues(v));
     140      var param = Expression.Parameter(typeof(int), "row");
     141
     142      Stopwatch watch = new Stopwatch();
     143      int repetitions = 3;
     144
     145      long nNodes = trees.Aggregate<ISymbolicExpressionTree, long>(0, (current, t) => current + t.Length);
     146
     147      for (int rep = 0; rep < repetitions; rep++) {
     148        watch.Start();
     149        foreach (ISymbolicExpressionTree t in trees) {
     150          var exp = ExpressionTreeInterpreter.CreateExpression(t.Root.GetSubtree(0).GetSubtree(0), data, param);
     151          while (exp.CanReduce) exp = exp.Reduce();
     152          var function = Expression.Lambda<Func<int, double>>(exp, param).Compile();
     153          function(0);
     154        }
     155        watch.Stop();
     156      }
     157      Console.WriteLine("Random tree compilation performance of expression tree interpreter: " + Environment.NewLine +
     158        watch.ElapsedMilliseconds + "ms " + Environment.NewLine +
     159        Util.NodesPerSecond(nNodes * repetitions, watch) + " nodes/sec" + Environment.NewLine +
     160        Util.NodesPerSecond(trees.Length * repetitions, watch) + " trees/sec"
     161        );
     162
     163    }
     164
    111165
    112166    private void TestTypeCoherentGrammarPerformance(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double nodesPerSecThreshold) {
     
    149203      var dataset = Util.CreateRandomDataset(twister, Rows, Columns);
    150204      var grammar = new ArithmeticExpressionGrammar();
     205      //grammar.Symbols.OfType<Variable>().First().Enabled = false;
    151206      grammar.MaximumFunctionArguments = 0;
    152207      grammar.MaximumFunctionDefinitions = 0;
Note: See TracChangeset for help on using the changeset viewer.