Changeset 5412 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 02/03/11 14:14:36 (14 years ago)
- 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 71 71 } 72 72 } 73 74 private static bool IsInvalidValue(double d) {75 return double.IsNaN(d) || double.IsInfinity(d);76 }77 73 } 78 74 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/SimpleArithmeticExpressionInterpreterTest.cs
r4477 r5412 40 40 private const int Rows = 1000; 41 41 private const int Columns = 50; 42 private static SymbolicExpressionTree[] randomTrees;43 private static Dataset dataset;44 private static MersenneTwister twister;45 42 private TestContext testContextInstance; 46 43 … … 58 55 } 59 56 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); 64 61 var grammar = new GlobalSymbolicExpressionGrammar(new FullFunctionalExpressionGrammar()); 65 62 grammar.MaxFunctionArguments = 0; … … 67 64 grammar.MinFunctionArguments = 0; 68 65 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); 74 67 double[] estimation = new double[Rows]; 75 68 foreach (SymbolicExpressionTree tree in randomTrees) { … … 77 70 } 78 71 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 80 93 } 81 94 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/Util.cs
r4068 r5412 29 29 using HeuristicLab.Random; 30 30 using Microsoft.VisualStudio.TestTools.UnitTesting; 31 using HeuristicLab.Problems.DataAnalysis.Evaluators; 32 using System; 31 33 namespace HeuristicLab.Problems.DataAnalysis.Tests { 32 34 internal class Util { … … 80 82 } 81 83 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) { 84 85 // warm up 86 IEnumerable<int> rows = Enumerable.Range(0, dataset.Rows); 87 long nNodes = 0; 88 double c = 0; 85 89 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 87 92 } 88 93 89 94 Stopwatch watch = new Stopwatch(); 90 long nNodes = 0;91 95 for (int rep = 0; rep < repetitions; rep++) { 92 96 watch.Start(); 97 c = 0; 93 98 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 96 100 } 97 101 watch.Stop(); 98 102 } 99 Assert.Inconclusive("Random tree evaluation performance of " + interpreter.GetType() + ":" +103 Console.WriteLine("Random tree evaluation performance of " + interpreter.GetType() + ": " + 100 104 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); 102 107 } 103 108 }
Note: See TracChangeset
for help on using the changeset viewer.