Changeset 16691 for branches/2974_Constants_Optimization
- Timestamp:
- 03/16/19 13:13:39 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2974_Constants_Optimization/Benchmarks/Benchmarks/ConstantsOptimizationPerformance.cs
r16525 r16691 16 16 private static readonly int seed = 1234; 17 17 private static readonly int maxTreeSize = 50; 18 private static readonly int nTrees = 10 00;18 private static readonly int nTrees = 10; 19 19 20 private ISymbolicExpressionTree[] trees; 20 private List<ISymbolicExpressionTree> globalTrees = new List<ISymbolicExpressionTree>(); 21 private List<ISymbolicExpressionTree> iterationTrees = new List<ISymbolicExpressionTree>(); 21 22 private IRegressionProblemData problemData; 22 23 private TypeCoherentExpressionGrammar grammar; … … 34 35 grammar.ConfigureAsDefaultRegressionGrammar(); 35 36 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()); 37 // generate random trees and only keep trees which are ok 38 while (globalTrees.Count < nTrees) { 39 var t = Util.CreateRandomTrees(twister, problemData.Dataset, grammar, 1, 1, maxTreeSize, 0, 0).Single(); 40 Util.InitTree(t, twister, problemData.AllowedInputVariables.ToList()); 41 var q = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, t, double.MinValue, double.MaxValue, problemData, rows, applyLinearScaling: true); 42 if (q > 0) globalTrees.Add(t); 43 } 44 } 45 46 [IterationSetup] 47 public void IterationSetup() { 48 iterationTrees.Clear(); 49 for (int i = 0; i < globalTrees.Count; i++) { 50 var t = (ISymbolicExpressionTree)globalTrees[i].Clone(); // trees are changed in OptimizeConstants, so we need to clone the original trees for each iteration 51 iterationTrees.Add(t); 39 52 } 40 53 } … … 57 70 58 71 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);72 for (int i = 0; i < iterationTrees.Count; i++) { 73 avgQuality += LMConstantsOptimizer.OptimizeConstants(iterationTrees[i], problemData.Dataset, problemData.TargetVariable, rows, applyLinearScaling: true, maxIterations: Iterations); 61 74 } 62 75 } else { 63 for (int i = 0; i < trees.Length; i++) {64 avgQuality += SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, trees[i], double.MinValue, double.MaxValue, problemData, rows,true);76 for (int i = 0; i < iterationTrees.Count; i++) { 77 avgQuality += SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, iterationTrees[i], double.MinValue, double.MaxValue, problemData, rows, applyLinearScaling: true); 65 78 } 66 79 } 67 return avgQuality / trees.Length;80 return avgQuality / iterationTrees.Count; 68 81 } 69 82 }
Note: See TracChangeset
for help on using the changeset viewer.