Changeset 9955 for trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
- Timestamp:
- 09/13/13 11:59:36 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r9828 r9955 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics; 24 25 using System.Globalization; 25 26 using System.Linq; 27 using System.Linq.Expressions; 26 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 29 using HeuristicLab.Random; … … 109 111 TestArithmeticGrammarPerformance(new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), 12.5e6); 110 112 } 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 111 165 112 166 private void TestTypeCoherentGrammarPerformance(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double nodesPerSecThreshold) { … … 149 203 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); 150 204 var grammar = new ArithmeticExpressionGrammar(); 205 //grammar.Symbols.OfType<Variable>().First().Enabled = false; 151 206 grammar.MaximumFunctionArguments = 0; 152 207 grammar.MaximumFunctionDefinitions = 0;
Note: See TracChangeset
for help on using the changeset viewer.