private static void SymbolicDataAnalysisCrossoverPerformanceTest(ISymbolicDataAnalysisExpressionCrossover <IRegressionProblemData> crossover) { var twister = new MersenneTwister(31415); var dataset = Util.CreateRandomDataset(twister, Rows, Columns); var grammar = new FullFunctionalExpressionGrammar(); var stopwatch = new Stopwatch(); grammar.MaximumFunctionArguments = 0; grammar.MaximumFunctionDefinitions = 0; grammar.MinimumFunctionArguments = 0; grammar.MinimumFunctionDefinitions = 0; var trees = Util.CreateRandomTrees(twister, dataset, grammar, PopulationSize, 1, MaxTreeLength, 0, 0); foreach (ISymbolicExpressionTree tree in trees) { Util.InitTree(tree, twister, new List <string>(dataset.VariableNames)); } var problemData = new RegressionProblemData(dataset, dataset.VariableNames, dataset.VariableNames.Last()); var problem = new SymbolicRegressionSingleObjectiveProblem(); problem.ProblemData = problemData; var globalScope = new Scope("Global Scope"); globalScope.Variables.Add(new Core.Variable("Random", twister)); var context = new ExecutionContext(null, problem, globalScope); context = new ExecutionContext(context, crossover, globalScope); stopwatch.Start(); for (int i = 0; i != PopulationSize; ++i) { var parent0 = (ISymbolicExpressionTree)trees.SampleRandom(twister).Clone(); var scopeParent0 = new Scope(); scopeParent0.Variables.Add(new Core.Variable(crossover.ParentsParameter.ActualName, parent0)); context.Scope.SubScopes.Add(scopeParent0); var parent1 = (ISymbolicExpressionTree)trees.SampleRandom(twister).Clone(); var scopeParent1 = new Scope(); scopeParent1.Variables.Add(new Core.Variable(crossover.ParentsParameter.ActualName, parent1)); context.Scope.SubScopes.Add(scopeParent1); crossover.Execute(context, new CancellationToken()); context.Scope.SubScopes.Remove(scopeParent0); // clean the scope in preparation for the next iteration context.Scope.SubScopes.Remove(scopeParent1); // clean the scope in preparation for the next iteration } stopwatch.Stop(); double msPerCrossover = 2 * stopwatch.ElapsedMilliseconds / (double)PopulationSize; Console.WriteLine(crossover.Name + ": " + Environment.NewLine + msPerCrossover + " ms per crossover (~" + Math.Round(1000.0 / (msPerCrossover)) + " crossover operations / s)"); foreach (var tree in trees) { HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Tests.Util.IsValid(tree); } }
private void TestFullGrammarPerformance(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double nodesPerSecThreshold) { var twister = new MersenneTwister(31415); var dataset = Util.CreateRandomDataset(twister, Rows, Columns); var grammar = new FullFunctionalExpressionGrammar(); grammar.MaximumFunctionArguments = 0; grammar.MaximumFunctionDefinitions = 0; grammar.MinimumFunctionArguments = 0; grammar.MinimumFunctionDefinitions = 0; var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); foreach (ISymbolicExpressionTree tree in randomTrees) { Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); } double nodesPerSec = Util.CalculateEvaluatedNodesPerSec(randomTrees, interpreter, dataset, 3); //mkommend: commented due to performance issues on the builder //Assert.IsTrue(nodesPerSec > nodesPerSecThreshold); // evaluated nodes per seconds must be larger than 15mNodes/sec }
private void TestFullGrammarPerformance(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double nodesPerSecThreshold) { var twister = new MersenneTwister(31415); var dataset = Util.CreateRandomDataset(twister, Rows, Columns); var grammar = new FullFunctionalExpressionGrammar(); var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); foreach (ISymbolicExpressionTree tree in randomTrees) { Util.InitTree(tree, twister, new List <string>(dataset.VariableNames)); } double nodesPerSec = Util.CalculateEvaluatedNodesPerSec(randomTrees, interpreter, dataset, 3); //mkommend: commented due to performance issues on the builder //Assert.IsTrue(nodesPerSec > nodesPerSecThreshold); // evaluated nodes per seconds must be larger than 15mNodes/sec }
private static void SymbolicDataAnalysisCrossoverPerformanceTest(ISymbolicDataAnalysisExpressionCrossover<IRegressionProblemData> crossover) { var twister = new MersenneTwister(31415); var dataset = Util.CreateRandomDataset(twister, Rows, Columns); var grammar = new FullFunctionalExpressionGrammar(); var stopwatch = new Stopwatch(); grammar.MaximumFunctionArguments = 0; grammar.MaximumFunctionDefinitions = 0; grammar.MinimumFunctionArguments = 0; grammar.MinimumFunctionDefinitions = 0; var trees = Util.CreateRandomTrees(twister, dataset, grammar, PopulationSize, 1, MaxTreeLength, 0, 0); foreach (ISymbolicExpressionTree tree in trees) { Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); } var problemData = new RegressionProblemData(dataset, dataset.VariableNames, dataset.VariableNames.Last()); var problem = new SymbolicRegressionSingleObjectiveProblem(); problem.ProblemData = problemData; var globalScope = new Scope("Global Scope"); globalScope.Variables.Add(new Core.Variable("Random", twister)); var context = new ExecutionContext(null, problem, globalScope); context = new ExecutionContext(context, crossover, globalScope); stopwatch.Start(); for (int i = 0; i != PopulationSize; ++i) { var parent0 = (ISymbolicExpressionTree)trees.SampleRandom(twister).Clone(); var scopeParent0 = new Scope(); scopeParent0.Variables.Add(new Core.Variable(crossover.ParentsParameter.ActualName, parent0)); context.Scope.SubScopes.Add(scopeParent0); var parent1 = (ISymbolicExpressionTree)trees.SampleRandom(twister).Clone(); var scopeParent1 = new Scope(); scopeParent1.Variables.Add(new Core.Variable(crossover.ParentsParameter.ActualName, parent1)); context.Scope.SubScopes.Add(scopeParent1); crossover.Execute(context, new CancellationToken()); context.Scope.SubScopes.Remove(scopeParent0); // clean the scope in preparation for the next iteration context.Scope.SubScopes.Remove(scopeParent1); // clean the scope in preparation for the next iteration } stopwatch.Stop(); double msPerCrossover = 2 * stopwatch.ElapsedMilliseconds / (double)PopulationSize; Console.WriteLine(crossover.Name + ": " + Environment.NewLine + msPerCrossover + " ms per crossover (~" + Math.Round(1000.0 / (msPerCrossover)) + " crossover operations / s)"); foreach (var tree in trees) HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Tests.Util.IsValid(tree); }