1 | using BenchmarkDotNet.Attributes;
|
---|
2 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
3 | using HeuristicLab.Problems.DataAnalysis;
|
---|
4 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
5 | using HeuristicLab.Problems.DataAnalysis.Symbolic.ConstantsOptimization;
|
---|
6 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
7 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
8 | using HeuristicLab.Random;
|
---|
9 | using System.Collections.Generic;
|
---|
10 | using System.Linq;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Benchmarks {
|
---|
13 | [ClrJob]
|
---|
14 | [MinColumn, MaxColumn, MeanColumn, MedianColumn]
|
---|
15 | public class ConstantsOptimizationPerformance {
|
---|
16 | private static readonly int seed = 1234;
|
---|
17 | private static readonly int maxTreeSize = 50;
|
---|
18 | private static readonly int nTrees = 1000;
|
---|
19 |
|
---|
20 | private ISymbolicExpressionTree[] trees;
|
---|
21 | private IRegressionProblemData problemData;
|
---|
22 | private TypeCoherentExpressionGrammar grammar;
|
---|
23 | private int[] rows;
|
---|
24 |
|
---|
25 | private readonly ISymbolicDataAnalysisExpressionTreeInterpreter interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
|
---|
26 |
|
---|
27 | [GlobalSetup]
|
---|
28 | public void Setup() {
|
---|
29 | var twister = new MersenneTwister((uint)seed);
|
---|
30 | problemData = new RegressionRealWorldInstanceProvider().LoadData(new Tower());
|
---|
31 | rows = Enumerable.Range(0, Rows).ToArray();
|
---|
32 |
|
---|
33 | grammar = new TypeCoherentExpressionGrammar();
|
---|
34 | grammar.ConfigureAsDefaultRegressionGrammar();
|
---|
35 |
|
---|
36 | trees = Util.CreateRandomTrees(twister, problemData.Dataset, grammar, nTrees, 1, maxTreeSize, 0, 0);
|
---|
37 | foreach (SymbolicExpressionTree tree in trees) {
|
---|
38 | Util.InitTree(tree, twister, problemData.AllowedInputVariables.ToList());
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | //public IEnumerable<int> RowsValues => Util.IntRange(100, 5000, 100, closed: true);
|
---|
43 | //public IEnumerable<int> RowsValues => new[] { 100, 250, 500, 750, 1000, 1500, 2000, 3000, 4000, 4999 };
|
---|
44 | public IEnumerable<int> RowsValues => new[] { 4999 };
|
---|
45 | public IEnumerable<int> IterationsValues => Util.IntRange(5, 30, 5, closed: true);
|
---|
46 | //public IEnumerable<int> IterationsValues => new[] { 0 };
|
---|
47 |
|
---|
48 | [ParamsSource(nameof(RowsValues))]
|
---|
49 | public int Rows { get; set; }
|
---|
50 |
|
---|
51 | [ParamsSource(nameof(IterationsValues))]
|
---|
52 | public int Iterations { get; set; }
|
---|
53 |
|
---|
54 | [Benchmark]
|
---|
55 | public double Tower() {
|
---|
56 | double avgQuality = 0;
|
---|
57 |
|
---|
58 | if (Iterations > 0) {
|
---|
59 | for (int i = 0; i < trees.Length; i++) {
|
---|
60 | avgQuality += LMConstantsOptimizer.OptimizeConstants(trees[i], problemData.Dataset, problemData.TargetVariable, rows, true, Iterations);
|
---|
61 | }
|
---|
62 | } else {
|
---|
63 | for (int i = 0; i < trees.Length; i++) {
|
---|
64 | avgQuality += SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, trees[i], double.MinValue, double.MaxValue, problemData, rows, true);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | return avgQuality / trees.Length;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|